Introduction: Getting Started With Ultrasonic Sensor in 3 Simple Steps

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

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

Comments