SHARE

When we want to measure distances, generally we use a ruler or measuring tape. But how if we want to get a digital distance in real time?

One answer: use ultrasound technology to achieve a range finder.

The ultrasonic sound waves being propagated in the form of a cone, they make great obstacle detectors.

So we will get into the construction of a small ultrasonic rangefinder using an Arduino nano.

Here are the prerequisites for this tutorial:

  • Arduino Nano with USB Cable.
  • HC-SR04 Ultrasonic sensor.
  • Buzzer.
  • 2 LEDs.
  • Wires.

The HC-SR04 Ultrasonic rangefinder.

HC-SR04 is what is commonly called an “ultrasonic rangefinder”. The HC-SR04 Ultrasonic rangefinder easily findable on many electronic component suppliers sites. In general the sites delivering from China offer prices lower than 4 dollars.

HC-SR04 Ultrasonic rangefinder

This component has several small things. First, on the front face of the HC-SR04 Ultrasonic rangefinder can be seen the US transmitter and its receiver. These are small piezoelectric cells that will either vibrate when voltage is applied (transmitter) or on the contrary produce a voltage when a vibration is received (receiver).

On the back side there are several small circuits for signal generation and processing. Thus, a component will generate a wave of 40 kHz at a “starting signal” and the remaining part will handle the receipt of the forming (amplification and filtering) and format it properly on an output pin.

The HC-SR04 has 4 pins. The first are as always VCC and GND that will accommodate the power supply (5V and ground respectively). then there is the Pin “echo” which will be present on the output signal. Finally, a pin named “Trig”. This means “Trigger”. Setting this pin high for 10 S you will trigger the ping for measurement. A “ping” is launching an ultrasonic wave.

The output signal is quite simple to operate. It is initially at 0 and goes to 1 when the ping is sent. Then it returns to 0 when the echo returned to the receiver OR if there is no return during the 30ms after sending (the wave is then considered lost).

Connection

The connections of the HC-SR04 sensor are quite simple. Just connect 5V and GND to their respective pins on Arduino then “Trig” and “Echo” on the digital I / O. In our case.

  • Echo Pin to digital Pin 2 of  Arduino.
  • Trig Pin to the digital Pin 3 of Arduino.
  • LED 1 to digital pin 4 of Arduino.
  • LED 2 to digital pin 5 of Arduino.
  • Buzzer to the digital pin 6 of Arduino.

HC-SR04 Ultrasonic rangefinder

Operate the HC-SR04 rangefinder with Arduino.

Moving on to practice with Arduino. The goal here will be to be able to make a distance measurement then display the distance  in cm in the serial monitor and light LED1 if distance  D <= 5 CM or LED2 if  D >= 40 CM.

Watch the video Below to  to see how this system work.

Click here to download The Arduino program of this HC-SR04 Ultrasonic rangefinder.

Leave a Reply