Smit Babariya
Published

Distance Measurement Using Ultrasonic Sensor

Distance measurement using an ultrasonic sensor.

IntermediateProtip12,849
Distance Measurement Using Ultrasonic Sensor

Things used in this project

Story

Read more

Schematics

simulation file proteous

Code

arduino code

Arduino
#include<LiquidCrystal.h>
const int rs=12, en=3, d4=4, d5=5, d6=6, d7=7 ;
const int trig=2,echo=9;
int distanc;
long d;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);

void setup() {
  
lcd.begin(16,2);
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
Serial.begin(9600);
}

void loop() {

digitalWrite(trig,LOW);
delay(2);
digitalWrite(trig,HIGH);
delay(10);
digitalWrite(trig,LOW);
d=pulseIn(echo,HIGH);
distanc= d*0.034/2;
lcd.setCursor(0,0);
lcd.print("distance");
lcd.setCursor(0,1);
lcd.print(distanc);

}

Credits

Smit Babariya

Smit Babariya

12 projects • 39 followers
Embedded Eng. with demonstrated history of working in diff. Projects like ESP32,8266 & Arduino.Strong engineering professional in E&C eng.

Comments