How To Make An Ultrasonic Rangefinder On HC-SR04 And Arduino

Table of contents:

How To Make An Ultrasonic Rangefinder On HC-SR04 And Arduino
How To Make An Ultrasonic Rangefinder On HC-SR04 And Arduino

Video: How To Make An Ultrasonic Rangefinder On HC-SR04 And Arduino

Video: How To Make An Ultrasonic Rangefinder On HC-SR04 And Arduino
Video: Ultrasonic Sensor HC-SR04 and Arduino Tutorial 2024, November
Anonim

I propose a rangefinder project based on the HC-SR04 ultrasonic sensor and the Arduino board. The sensor readings are displayed on the liquid crystal display, and power is supplied from a 9 volt battery.

Rangefinder project layout
Rangefinder project layout

It is necessary

  • - Arduino Nano;
  • - ultrasonic rangefinder HC-SR04;
  • - LCD display;
  • - body;
  • - battery "Krona";
  • - 10 kOhm potentiometer;
  • - bread board;
  • - connecting wires.

Instructions

Step 1

To begin with, you need to choose the right size for the case. The size depends on which Arduino board you are going to use (UNO, Mini, Nano, or another), as well as what size your LCD is. It is possible to use a miniature 3-character LED indicator instead of the LCD. This will be enough to display the distance in centimeters, because the ultrasonic sensor used has a measuring range of 3 to 400 cm.

Choosing a case for a rangefinder
Choosing a case for a rangefinder

Step 2

Let's estimate how the parts will be arranged inside the body. Cut out the holes for the ultrasonic sensor, for the display and for the on-off switch.

Step 3

Now let's look at the circuit of our device. Power supply - from battery "Krona" 9 V. Toggle switch S1 - to turn the device on and off. The liquid crystal display (LCD) is connected in a standard way with a 10 kΩ potentiometer to adjust the contrast. LCD and ultrasonic sensor are powered from 5 V.

Ultrasonic rangefinder circuit
Ultrasonic rangefinder circuit

Step 4

Let's write a sketch for our rangefinder. Everything is simple here. First, we initialize the LCD on pins 12, 11, 10, 9, 8 and 7 using the LiquidCrystal library from the Arduino IDE.

Next, we connect the trigger and echo pins of the rangefinder to pins 6 and 5 of the Arduino board.

Every 50 ms we will request the distance from the detector using the getDistance () function and display it on the LCD.

Rangefinder sketch
Rangefinder sketch

Step 5

After we have written the sketch to the Arduino memory, we can assemble the device. The layout of the internals that I suggest is shown in the figure. I fixed the display and sensor with hot melt glue. It holds quite firmly, but at the same time makes it possible to remove the connected parts, if necessary. It is advisable to place everything so that you can connect to the USB port of the Arduino and fix the "firmware" if necessary. For example, change the displayed text or correct the coefficients for calculating the distance. It may be necessary to change the contrast of the LCD, so it is also advisable to have a potentiometer adjuster available.

The layout of the insides of the ultrasonic rangefinder
The layout of the insides of the ultrasonic rangefinder

Step 6

A version of the finished device is shown in the photo. It is quite compact and easy to use. Of course, such a device has its own characteristics. Several important usage tips are provided at the end in the helpful tips section.

Recommended: