Getting Started With Ultrasonic Sensor in 3 Simple Steps

1,184

28

1

Hey everybody,

Before starting this instructable let us know what an ultrasonic sensor is.

Ultrasonic Sensors are self-contained solid-state devices designed for non-contact sensing of solid and liquid object.

So there ends the technical definition,I don't know how many of you understood.In simple words, its a sensor which helps us in knowing the proximity of the obstacles or objects.We here in ECE see every object as an obstacle

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: Components Needed

1. Ultrasonic Sensor

2. Jumper wires

3. Arduino Uno

4.Breadboard

5.LED(Add-on)

Step 2: Step 2: Make the Connections

  • Vcc to 5V
  • Gnd to Gnd
  • Trig(Trigger) to digital pin 9(any of your choice)
  • Echo to digital pin 10( again,any of your choice)
  • LED to digital 12(You can use built-in LED if you want)
  • And yes, don't forget to connect Arduino to your laptop(happens to me quite often ;) )

Step 3: Step 3: Run the Code Printed Below and You Are Good to Go

int trig=9;

int echo=10;

int a=12;

void setup()

{

pinMode(a,OUTPUT);

Serial.begin(9600);

}

void loop() {

long duration,cms,in;

pinMode(trig,OUTPUT);

digitalWrite(trig,HIGH);

delayMicroseconds(10);

digitalWrite(trig,LOW);

pinMode(echo,INPUT);

duration=pulseIn(echo,HIGH);

cms=mtoc(duration);

in=mtoi(duration);

if(cms<=10)

digitalWrite(a,HIGH);

else

digitalWrite(a,LOW);

Serial.print(cms);

Serial.print("cm");

Serial.println();

}

long mtoc(long m)

{

return m/29/2;

}

Points to note:

  1. LED will light up once the distance is less than 10 cm. This can used as a warning to the user in practical applications.
  2. Serial monitor can be used to see the distance.
  3. The video has been uploaded for your convenience

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    Discussions

    0
    None
    PushpendraC2

    1 year ago

    The code is showing error