How to Make Distance Meter
Code :-
/*
Code Started
Distance metre using by ultrasonic sensor
Crated By Technical idEas YouTube
Channel Link :- https://youtube.com/channel/UCCJyR_wnt3SxhErsSUP9Wrw
*/
#include <LiquidCrystal.h>
#define trigger 5
#define echo 6
const int rs = 7, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
float time=0,distance=0;
void setup()
{
lcd.begin(16,2);
pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
lcd.print(" Ultra sonic");
lcd.setCursor(0,1);
lcd.print("Distance Meter");
delay(2000);
lcd.clear();
lcd.print(" Technical idEas");
delay(2000);
}
void loop()
{
lcd.clear();
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH);
distance=time*340/20000;
lcd.clear();
lcd.print("Distance:");
lcd.print(distance);
lcd.print("cm");
lcd.setCursor(0,1);
lcd.print("Distance:");
lcd.print(distance/100);
lcd.print("m");
delay(1000);
}
Ultrasonic Sensor Pin
VCC =5v
Trigger = 5
Eco = 6
GND =GND
Comments
Post a Comment