การใช้งานโมดูล HC-SR04 วัดระยะห่างด้วยคลื่นอัลตร้าโซนิค สามารถนำไปใช้ประยุกต์ใช้งาน เช่น การตรวจจับสิ่งกีดขวาง โดยเซนเซอร์ Ultrasonic วัดระยะทาง มีความแม่นยำที่ 2 - 400 cm ความละเอียด 0.3cmtechnical parameters1. Working Voltage: 5 V (DC)2. Static current: less than $ number ma.3. Output signal: Electric frequency signal, high level of 5 V, low level of 0 V.4. Sensor angle: Not more than 15 degrees.5. Detection distance: 2 cm-450 cm6. High precision: up to 0.3 cm7. Trigger Input: TTL pulse 10us8. Echo: TTL output signal PWL Connection mode1. VCC2. trig (T)3. echo (R)4. GND use Methodsupply module 5 V, the output will be 5 V while obstacle in range, or 0 V if not. The pinThis module is used as a switching output when anti-theft module, and without the feet whenvan modules. notethe module must be inserted in the circuit before power status, which prevents productionhigh level of misoperation, if not, then power again. Operating Principle module1. Adopt IO trigger through supplying at least 10us sequence of high level signal.2. The module automatically sends eight 40khz square wave and automatically detect whether receivethe pulse signal to return.3. If return signals through the output of high level and high-level timepermanent is the time that from the ultrasound transmission and reception. test distance =(High level time * sound velocity (340 M / S) / 2.Note: This module is not suitable for connecting with the power, if you need to connect thispower electronics module, and then let the GND terminal of this module that plugsfirst, otherwise it will affect the normal operation of the module.
ภาพแสดงหลักการทำงาน




โหลด library ที่นี่ตัวอย่างโค้ด
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LCD arduino library
Ultrasonic ultrasonic(9,8); // (Trig PIN,Echo PIN)
void setup() {
lcd.begin(16, 2);
}
void loop()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(ultrasonic.Ranging(CM)); // CM or INC
lcd.print("cm");
delay(100);
}