Digital Distance Measuring Circuit

by Jamari in Circuits > Arduino

481 Views, 1 Favorites, 0 Comments

Digital Distance Measuring Circuit

PhotoGrid_1646712544557.jpg

In this instructables project, I will show you how to create your own Digital Distance Measuring Device using an Arduino. The goal of this project is to be able to estimate the distance of a flat surface from where the user points the device. This would allow the user the to quickly get measurements without the use of a measuring tape. This circuit uses an ultra sonic sensor to calculate the distance of an object that is perpendicular to the device at a maximum recommended distance of 5 meters. A laser module is included to show the user approximately where the device is pointed. These values will then be displayed on a 64 bit OLED display.

Note: This build does not involve soldering, so parts can be easily removed for other purposes.

Caution: Do not point the laser at anybody's eyes

Supplies

These are the list of supplies needed for the project:

1. Arduino Uno (Nano can also be used)

2. HC-SRQ4 ultra sonic sensor

3. IIC OLED 1306 Display

4. Laser Diode module

5. 10 male to female jumper wires ( Not all will be used, just in case there are any breaks)

6. 10 male to male jumper wires ( Not all will be used, just in case there are any breaks)

7. 9 volt battery

8. 9 volt battery connector for Arduino

9. 4 small screws of your choice

10. small switch

11. mini breadboard

Connect the Ultrasonic Distance Sensor to the Arduino

HC-SRQ4.PNG

This step will show you how to connect the wires from the ultrasonic sensor to the Arduino. A bread board is used because there are going to be multiple 5 volt connections which the Arduino cannot supply. Male to female jumper wires will be used for this portion. First, connect the ground pin of the Arduino to the ground pin of the Ultra sonic sensor marked GND. Next, connect the echo pin of the sensor to pin 4 and the trig pin to pin 3. Finally connect the 5v from the Arduino to the breadboard and from the bread board, connect the 5v to the sensor.

Connecting the 1306 OLED Display to the Arduino

20220308_192904.jpg

Connect the ground pin of the display to the ground pin of the Arduino. Next, connect the SDA pin of the display to pin A4 on the Arduino. Then connect the SCL pin to A5 and finally connect the VCC pin to 5v on the breadboard.

Connecting the Laser Module to the Arduino

20220308_192934.jpg

Connect pin S to ground(GND) and connect - to the 5v on the breadboard. Note that the laser module may have the labels reversed. If it does not turn on when the Arduino is on, switch the connections on the module.

Writing and Uploading the Program to the Arduino

code 1.PNG
code 2.PNG

This program was written using the Arduino IDE and this is what allows the components to work. The distance is given in SI units which can be changed by altering the variable "distancemeter." The code used in this project will be provided at the end. However, if you want to make modifications to the code, you will need to download a few libraries. In the IDE, click sketch, a drop down will appear and then click include libraries. After this is done, click manage libraries and search for Adafruit GFX library and SSD1306 then download. Be sure to include these libraries if you are making your own code.

Running the Code and Checking the Components

20220308_192743.jpg
20220308_195007.jpg

After all of the pins have been put in the correct places and the code has been sent to the Arduino, the project should be fully functional. The laser module should be on and the display should be show numbers that are changing relatively often. At this point add a switch between the 5v output from the Arduino and the vcc pins of the modules. This allows you to turn off the circuit.

Note: The switch only turns off the functions to the modules. The Arduino will still be on, so the battery will drain if not disconnected. Also, once the display has been switched off, it cannot be turned on until the Arduino is reset button is pressed or the 5v pin is disconnected and reconnected to it.

(Optional Step) Access to a 3d Printer Required- Build Assembly

20220308_200433.jpg
20220308_200347.jpg

The files for 3D printing these pieces are provided below. Once printing is finished, make a small 6mm hole in the front of the case right above the distance sensor holes. This is where the laser module will be. Next, put the 3d printed pieces together and make a hole on both sides of the long face where the protrusions are. This will be for the screws to keep the cover on the case. Finally, align the display with the rectangular cutout on the back and make 2 diagonal screw holes for the display to attach to the cover.

Assembly

20220304_003539.jpg

Put the ultra sonic sensor into the two large holes. Then fit the laser into the smaller hole that you made above the two larger holes. Put the Arduino in the case along with the battery and battery connector. Then, screw the display into its place on the cover. All that is left to do is, screw the cover onto the front case and the build is completed.

Project Complete

final.PNG
final 2.PNG

The digital distance measuring device is now complete. Point it at a nearby wall and see what the measurements are displayed.