all about Ultrasonic sensor
Hi friends. here is the diagram :- here is code :- ---------------------------------------------------- /* * Distance measurement using HC SR04 ultrasonic sensor and i2c 16x2 lcd * ER BROS LAB */ #include <Wire.h> #include <LiquidCrystal_I2C.h> #define trigger 12 #define echo 13 LiquidCrystal_I2C lcd(0x27, 16, 2); float t = 0, distance = 0; void setup() { lcd.begin(); lcd.backlight(); delay(100); pinMode(trigger, OUTPUT); pinMode(echo, INPUT); lcd.print("Ultra sonic"); lcd.setCursor(0, 1); lcd.print("Distance Meter"); delay(2000); lcd.clear(); lcd.print("ER BROS LAB"); delay(2000); } void loop() { lcd.clear(); digitalWrite(trigger, LOW); delayMicroseconds(2); digitalWrite(trigger, HIGH); delayMicroseconds(10); digitalWrite(trigger, LOW); delayMicroseconds(2); t = pulseIn(echo, HIGH); distance = t * 340 / 20000; lcd.clear(); lcd.print("Distance:"); lcd.print(distance); lcd.print(