Distance Measurement by Ultrasonic Sensor Using Arduino

About: I am an enthusiastic person who does not follow reality, instead who creates reality. I am sharing some projects with amazing people across the Globe (Of course you people) and I hope you will like them.

It is very simple and useful project which can be used in our daily life.

Things you will need to project is listed below......

  • Arduino Uno.
  • Ultrasonic sensor.
  • 4 Male to Female connecting wire.
  • connecting usb cable.

Step 1: Circuit Connection.......

connect

ultrasonic Vcc => 5V arduino.

ultrasonic GND => GND arduino

ultrasonic trig => 2pin arduino

ultrasonic echo => 3pin arduino

Step 2: Programming......

int trig=2;

int echo=3;

void setup() {

Serial.begin(9600); // initialize serial communication:

pinMode(trig,OUTPUT); //declear trig pin output:

pinMode(echo,INPUT); //declear echo pin input: }

void loop() {

// establish variables for duration of the ping,

// and the distance result in centimeters:

long duration, cm;

digitalWrite(trig, LOW);

delayMicroseconds(2);

digitalWrite(trig, HIGH);

delayMicroseconds(5);

digitalWrite(trig, LOW);

duration = pulseIn(echo, HIGH);

// convert the time into a distance

cm = microsecondsToCentimeters(duration);

Serial.print(cm);

Serial.print("cm");

Serial.println();

delay(100); }

long microsecondsToCentimeters(long microseconds) {

// The speed of sound is 340 m/s or 29 microseconds per centimeter.

// The ping travels out and back, so to find the distance of the

// object we take half of the distance travelled.

return microseconds / 29 / 2; }

Step 3: Testing.......

how burn programme to arduino and open serial monitor.you will see distance printed in serial monitor.

For any query comment pls.

Share

    Recommendations

    • Warm and Fuzzy Contest

      Warm and Fuzzy Contest
    • Cardboard Challenge

      Cardboard Challenge
    • Comfort Food Challenge

      Comfort Food Challenge

    Discussions

    0
    None
    Otitiori

    2 years ago

    The program did not compile to my audrino uno