Sonar Range Finder (Angella, Kwadwo and Julie)

This Sonar Range Finder Project is to use an Arduino and an Ultrasonic Range in order to be able to determine distance from the Sonar Range to an object. Something important to consider for this project is how distance is calculated. Distance = (Speed * Time) / 2

Supplies:

First, gather all the supplies.

  • One Arduino Uno
  • One Ultrasonic Range
  • Wires
  • One 220 ohm Resistor
  • One LED (You can choose what color you want)
  • One Breadboard

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: Set Up the Sonar

Here is a fritzing Image to help visualize the Setup:

VCC --> 5V

Trig --> Pin 9 (OUTPUT PIN)

Echo --> Pin 10 (INPUT PIN)

GND --> Ground

LED --> Pin 11

*** It is important to understand that you can change the pins you use for Trig and Echo, we just used pins 9,10 and 11.

Step 2: Code for the Sensor

This is the code we used:

int trigP = 9;

int echoP = 10;

int led = 11;

void setup(){

Serial.begin (9600);

pinMode(trigP, OUTPUT);

pinMode(echoP, INPUT);

pinMode(led, OUTPUT);

}

void loop(){

long duration, distance;

digitalWrite(trigP, LOW);

delayMicroseconds(2);

digitalWrite(trigP, HIGH);

delayMicroseconds(10);

digitalWrite(trigP, LOW);

duration = pulseIn(echoP, HIGH);

distance = (duration/2) / 74;

if (distance < 7)

{ digitalWrite(led,HIGH);

}

else {

digitalWrite(led,LOW);

}

Serial.print(distance);

Serial.println(" in");

delay(500);

}

Step 3: Calibrate the Sonar Range Finder

To calibrate for the Sonar range we used a ruler and a folder, when we placed the folder an inch away and then in an excel sheet wrote what the distance sensor calculated. In order to see the sensor value we had to look at the serial monitor and looked at the values it gave us. In our data we found that there was a linear relationship between the data points. In order to convert the value from the Sensor into inches, we used the distance = speed *time / 2 equation.

This part of the code shows the conversion.

duration = pulseIn(echoP, HIGH);
distance = (duration/2) / 74;

*** If you wanted cm instead of inches all you would have to do is change the distance part of the code into

distance = (duration/2) / 21;

Step 4: Challenge:

The challenge that we came up with on our own was to detect whether someone was walking past the sensor. So we set up the code to make the LED light up if the foot is less than 7 inches away from the sensor. Here is a video of testing our challenge.

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

    20 days ago

    Thanks for sharing your code and circuit diagram.