norr@manorshi.com        +86-519-89185720
News Center

How to use ultrasonic sensor with Arduino?

Views: 135     Author: Grace     Publish Time: 2021-07-26      Origin: Site

Introduction of HC-SR04


HC-SR04 is a very popular sensor for measuring distance. It emits ultrasonic waves at a frequency of 40KHz. The ultrasonic waves travel through the air. If there are objects or obstacles in the path, it will bounce back to the module. Taking into account the propagation time and the speed of sound, you can calculate the distance.

1

1. Main technical parameters:

●Typical working voltage: 5V 

●Ultra-small static working current: less than 5mA 

●The sensing angle (R3 resistance is higher, the higher the gain, the larger the detection angle): 

R3 resistance is 392, no more than 15 degrees 

R3 resistance is 472, no more than 30 degrees 

●Detection distance (R3 resistance can adjust the gain, that is, adjust the detection distance): 

R3 resistance is 392 2cm-450cm 

R3 resistance is 472 2cm-700cm 

●High precision: up to 0.3cm 

●Blind zone (2cm) super close



2. Pin Description:

VCC - +5 V supply

TRIG – Trigger input of sensor. Microcontroller applies 10 us trigger pulse to the HC-SR04 ultrasonic module.

ECHO–Echo output of sensor. Microcontroller reads/monitors this pin to detect the obstacle or to find the distance.

GND – Ground


hc-sr04


3. Working principle


Use IO to trigger ranging, giving a high level signal of at least 10us;

●The module automatically sends 8 40khz square waves to automatically detect whether there is a signal return.

●There is a signal return, through the IO output a high level, the high level duration is (4) the time from the transmission to the return of the ultrasonic wave. Test distance = (high time * sound speed (340M / S)) / 2


hc-sr04 ultrasonic module


HC-SR04 Ultrasonic Module Timing Diagram

Arduino

1. Basic knowledge of Arduino programming:

pulseIn(): Used to detect the pulse width of the high and low levels output by the pin.

pulseIn(pin, value);

pulseIn(pin, value, timeout);//time

Pin---The pin that needs to read the pulse

Value---The pulse type to be read, HIGH or LOW

Timeout---timeout time, in microseconds, the data type is unsigned long integer

arduino


The connections are pretty easy, you can refer to the below image with the breadboard circuit schematic.


uno

2. Ultrasonic sensor ranging program (typical):

If you see here, I believe you have understood the operation method of  use ultrasonic sensor with Arduino. Let’s take action and try it yourself!


Ultrasonic sensor ranging program





Leave A Message

Contact Us

Tel: +86-519-89185720
E-mail:  norr@manorshi.com
Address: Building 5, No. 8 Chuangye Road, Shezhu Town, Liyang City, Changzhou, Jiangsu, China