038_Kashish Khera
Published

Interfacing of ultrasonic Sensor

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

BeginnerProtip1 hour170
Interfacing of ultrasonic Sensor

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04
SparkFun Ultrasonic Sensor - HC-SR04
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Breadboard (generic)
Breadboard (generic)
×1
Arduino UNO
Arduino UNO
×1
Buzzer
Buzzer
×1

Software apps and online services

Arduino IDE
Arduino IDE

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

038_Kashish Khera

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

Comments

Add projectSign up / Login