In this Instructable, a test plan was created to see if a sonar range finder is able to detect is a laptop is open or not. There will be instructions on how to create the sonar range finder, how to program, calibrate, and then test it.
Step 1: Gather Your Materials
In this test plan, you will need a couple items. The full Arduino is displayed above, but only a few things will be needed:
- Arduino Uno Microcontroller
- 4 1-stranded jumper wires
- Sonar Range Finder
- USB cable to connect the Arduino to the computer
Step 2: Putting the Pieces Together
Follow the images above to correctly connect the jumper wires to the correct pins:
- On the sonar range finder itself, there are four prongs to place the wires. As seen in the first diagram, each prong and wire should correlate with a specific placement on the Arduino Uno Microcontroller.
- The second picture shows the wires in their respective places (Due to an error, extra wires are also connected to the Microcontroller, but only focus on the ones that are part of the first diagram).
Step 3: Programming
Follow the code above to properly program the Arduino. The input and output variables correlate to the pins and these are where the data is taken. Values taken from this data can be accessed using the viewfinder on the Arduino Editor, but they will look like random values since the voltage values have not been calibrated with inches yet.
Step 4: Calibrating the Values
In order to turn the random range of variables into workable data, they need to be calibrated. To do this, the ruler and a notebook will be used. The chart above shows a range of sensor values at different inch values (at increments of 2 inches).
To do this, place the sonar range finder at 0 inches on the ruler. Place the notebook on top of 2 inches as if it is a wall. Record the voltage values given. Move the notebook to 4 inches in the same position. Record the value again. Continue doing this until you have reached 12 inches. When you are done, put all of the values into a chart like the one seen above.
Step 5: Creating the Calibration Line
When making this graph, I averaged the range of values for each x-value (distance). The line of best fit can be seen on the graph. By inputting the table values into Excel, you are able to create a graph from the values. To do so, highlight the values you want to use and then select the line graph image to create a graph from these values. Then, place the line of best fit in by selecting a data point and selecting "linear" as an option to display on the graph.
Step 6: Testing It!
By using the chart and graph, you are able to determine if the laptop is open or closed and how far it is as well! As could be seen in the first video, when the computer is closed, the sensor values are completely random and going into the high thousand values. They are flying randomly and do not correlate to any specific range of values.
The second video shows the values when the laptop screen is open. When the sensor values are viewed, they are within a specific range and the distance to the sonar range finder could be seen as between 4 and 6 inches away.