Arduino Range Finder

by kleewhitfield in Circuits > Arduino

763 Views, 4 Favorites, 0 Comments

Arduino Range Finder

Jay.jpg

This range finder was created to monitor whether or not a door is open. Measuring the distance of a door will allow us to identify whether a door is open or closed.

Gather Your Materials

sonar 2.png

To complete this project one must acquire:

Arduino Uno microcontroller

USB cable (to connect the Arduino to the computer)

Laptop computer

Resistors (10,000 Ohm)

Breadboard

Sonar

Connecting Your Circuit

sonar.png

Follow the above diagram to connect your circuit. You will notice that the vcc is connected to the 5v pin, the trig is connected to the 9 pin, the echo is connected to the 10 pin, and gnd is connected to ground.

Programming Your Arduino

Screen Shot 2018-01-29 at 1.57.29 PM.png

Copy and paste this code into your editor then upload it to your Arduino. This will produce distance values from your Arduino that we will then need to calibrate

Recording Your Calibration Data

Screen Shot 2018-01-29 at 2.00.25 PM.png
sonar 2.png

Currently your Arduino is not producing distance values, it is producing duration values. We need to create a calibration curve to find the equation of the line. To do this take a ruler and set up your Arduino at the base of it, every 5 inches record the duration that the Arduino produces. We will then take this data and input it into an excel spread sheet.

Creating Your Calibration Curve

Screen Shot 2018-01-29 at 2.13.33 PM.png

In excel make sure that in column 1 you put your distance and in column 2 you put your distance. Then highlight the columns and then select insert scatter plot. Right click on one of the data points and click format trendline, then select linear. Finally select display equation on chart. Finally record the equation given to you.

Calibrating Your System

Screen Shot 2018-01-29 at 1.43.29 PM.png

Now that you have found your equation you will convert duration into distance.Take your equation and input it into your code underneath where we left off originally. For example my equation was y=0.007x-0.589 so I would input:

duration = pulseIn(echoPin, HIGH);

delay (1000);

distance=0.007*duration-0.589;

Serial.println(distance);

delay(500);

Save this code and upload it into your Arduino