#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int motionSensor = 2;
const int trigPin = 9;
const int echoPin = 10;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup(){
Serial.begin(9600);
pinMode(motionSensor, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.begin(16, 2);
lcd.backlight();
lcd.print("harakat va ultrasonik");
lcd.setCursor(0,1);
lcd.print("Sensorlar");
delay(2000);
lcd.clear();
}
void loop() {
int motionValue = digitalRead(motionSensor);
if (motionValue == HIGH) {
lcd.clear();
lcd.print("Harakat bor");
delay(1000);
long duration, distance;
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.0343) / 2;
lcd.setCursor(0, 1);
lcd.print("Masofa:");
lcd.print(distance);
lcd.print("sm:");
} else {
lcd.clear();
lcd.print("Harakat yo'q");
lcd.setCursor(0,1);
lcd.print("Masofa: -");
}
delay(500);}