Distance measuring through Ultrasonic sensor Using Arduino UNO

Source code 

//Ultrasonic sensor Using Arduino UNO 

//BY MUHAMMD IBRAR

#include <LiquidCrystal.h>

LiquidCrystal lcd(7 ,6 ,5 ,4 ,3 ,2);

#define trigPin 10

#define echoPin 9

long Duration, Distance;

void setup(){

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

lcd.begin(16, 2);

}

void loop() {

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

Duration = pulseIn(echoPin, HIGH);

Distance = (Duration/2)/29.1;

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Distance=");

lcd.setCursor(9,0);

lcd.print(Distance);

delay(500);

Serial.println(Distance);

}


Result




Post a Comment

0 Comments