038_Kashish Khera
Published

Interfacing of ultrasonic Sensor

This is basic interfacing of ultrasonic sensor and output is displayed on LCD screen

BeginnerProtip1 hour210
Interfacing of ultrasonic Sensor

Things used in this project

Story

Read more

Schematics

Circuit Diagrame

Code

Source Code

Arduino
SCA -> A5
SDA -> A4
#include<LiquidCrystal_I2C.h>

#define echoPin 2
#define trigPin 3
#define buzz 13
#define buzzer 12
long distance;
int duration;
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
  // put your setup code here, to run once:
 
Serial.begin(9600);
pinMode(echoPin,INPUT);
pinMode(trigPin,OUTPUT);
pinMode(buzz,OUTPUT);
lcd.begin();
lcd.backlight();
//lcd.print("done");
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);        //use to send the waves
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration = pulseIn(echoPin,HIGH);
distance = duration*(0.034/2);
if(distance > 100){
  digitalWrite(buzzer,HIGH);
  tone(buzzer,1500);
}
else{
  digitalWrite(buzzer,LOW);
}
digitalWrite(buzz,HIGH);

Serial.print("THE DISTANCE IS ");
Serial.println(distance);
Serial.print("CM");
lcd.print("Distance is =");
lcd.setCursor(0,1);
lcd.print(distance);
//lcd.clear();
delay(1000);
lcd.clear();
}

Credits

038_Kashish Khera
2 projects • 2 followers
IoT developer and intersted in web development and ui/ux design too
Contact

Comments

Please log in or sign up to comment.