The ultrasonic range finder detects if anything is in its path by emitting a high frequency sound wave. The focus of this instructable will be how doors and ultrasonic range finders can work together,specifically how they can be used to detect when doors open and close. With this measuring device, we can see if it can detect the opening and closing of doors.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: MATERIALS!
For our plan, we need:
Arduino Uno microcontroller
USB cable (to connect the Arduino to the computer)
Wires (about 4-5)
Step 2: Connecting the Board!
There are different types and sizes of boards, for the long one, we recommend following the first picture above.
If you have the small one, we recommend using the second picture above.
Step 3: Programming Your Arduino!
This step is all about programming your Arduino, above you can see the code we used. With this code you will be able to get the monitor to read the value of the Sonar Rangefinder and record it on the screen.
Step 4: Calibrating Your Sonar Range
Now you need to set up an equation that the Arduino can use to correctly present the distance from the sonar to the door or any object your detecting. Place a ruler in front of the sonar and get any object such as a book. Place the front side of the object on the 10 inch line marked on the ruler, and record the value given by the sonar. Keep backing up the book by 5 inches , and record the values that pop up on the monitor.
Step 5: Making the Calibration Curve
Now that you have the data, we will use this to create the equation for reading distances! Using Logger Pro, set the x-axis the distance from the sonar and the y-axis as the sonar readings, filling in the charts. A set of points will appear on the right side showing a pattern. Click left from the left-most point on the graph, and highlight all the points towards the right until you get to the last one. When this is done, go the Graphs at the top of the screen, and press “Linear” to insert the graph of the best fit line.Hover over the graph and record the equation shown.
Step 6: Calibrating Your System
You will have to now go back to your code and change all the int values to float, allowing the code to read decimal values as well. Then create a new variable for your equation at the top, you can name it something like “temperature”, and set it equal to the equation you got from the previous step. Allow the new variable to also include decimals by adding a new line of code that is “ float temperature”. Finally, under those two lines, put in Serial.println(“variable name”) so that your new distance value will be recorded. It should look something like this=
*y represents the name you put for the variable*
float y ;
y = (a* x) + b ; Serial.println (y);
Also remember to remove the other Serial print as that isn’t the value we’re focusing on.
Step 7: Testing Out the Sonar Range Finder
Once you have your equation, you can use that equation and insert it into the code! Once insert it, you can connect your laptop to the board and transfer the code to test it out. You can see how the numbers change depending on the distance of the sonar range finder and a door, not only will the numbers change, the lights should turn on and off too.
Your Sonar range finder should be calibrated and results should be showing up on the screen. You are now done! :)