Sonar Range Finder

Our goal is to figure out if a laptop screen is open. This test plan will give you instructions on how to build a simple digital "ruler", calibrate it, program it, and then finally use it to see if you can detect if a laptop screen is open.

Supplies:

-Arduino

-Ultrasonic range finder

-Four Arduino jumper wires

-USB 2.0 Cable Type A/B

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Build Circuit

1.Connect one wire from the VCC port on the sonar to the 5V

2.Connect one wire from the Trig port on the sonar to the 9 pin

3.Connect one wire from the Echo port on the sonar to the 10 pin

4.Connect one wire from the GND port on the sonar to the GND

Step 2: Type the Code

int trig=9;

int echo=10;

void setup() {
pinMode(trigpin,OUTPUT);

pinMode(echopin,INPUT);

}

void loop() {

digitalWrite(trig,LOW);

delayMicroseconds(5);

digitalWrite(trig,HIGH);

delayMicroseconds(10);

duration = pulseIn(echoPin, HIGH);

Serial.println(duration);

delay(250);

}

Save file and verify code. If any errors arise troubleshoot it. Then connect the USB cable from the Arduino to the computer and upload the "Sonar_Range" code. After the lights flash on the Arduino board, the sonar code should start executing open the Serial Monitor by pressing the magnifying glass icon at the top right corner of the Arduino IDE window. A list of numbers start to form. Move your hand (back and forth) slowly from the sonar and observe how the numbers change.

Step 3: Collecting Data

We need to calibrate the system in order to produce centimeter values rather than voltage values.So first we need to take a series of voltage measurements with the Arduino at various distances, while recording the distances at each voltage measurement.This way, we can create a chart that use voltage values as 'X' values and distances as 'Y' values. From this chart we will be able to come up with an equation that will allow us to automatically convert between volts and centimeters.

First take a ruler and measure 3 centimeters away from the sonar and place your hand. Next to it, write down the voltage reading that your Arduino is putting on the serial monitor. Repeat this process every 3 centimeters and stop when you reach 15. You should now have a series of voltage values, with each corresponding to a specific temperature. Enter these into a spreadsheet.

Step 4: Plot Calibration Curve

Take the values you collected and plot them on a graph. Your 'X' values are the voltage values, so name the x-axis 'Voltage Values'. Your 'Y' values are the centimeter values, so name the y-axis 'Centimeters'. Then get the linear line of best fit, providing you with a calibrated equation. The calibrated equation converts the voltage values automatically to centimeter values.

Step 5: Calibrating System

Now we must update the code in order for the system to automatically produce centimeters not the voltage values. In order to do this after the line "duration = pulseIn(echoPin, HIGH);" write the line distance= *mduration+*b, *m and *b being the values from the calibration equation. Next, delete "Serial.println(duration)" and write the following: if (distance > 15) { Serial.println(" Laptop Screen open") } .Save your code and upload it to the Arduino.

Step 6: Testing Device

We have essentially made a digital ruler that tells us if a laptop screen is open. Now we must test the device. Place the ruler near the hinge of the laptop and open the laptop past 15 cm. Upload the code and start the sonar and if the serial monitor displays "Laptop Screen open" you are done!

Be the First to Share

    Recommendations

    • Instrument Contest

      Instrument Contest
    • Make it Glow Contest

      Make it Glow Contest
    • STEM Contest

      STEM Contest

    Discussions

    0
    None
    audreyobscura

    22 days ago

    You should consider updating your main image to something that reflects your project so folks are more likely to click on it from search. Thanks for the share!