/**
ESP32 + DHT22 Example for Wokwi
https://wokwi.com/arduino/projects/322410731508073042
*/
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int pirInput = 13;
int pirState = LOW;
int ledPin = 12;
int buzzPin = 14;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buzzPin, OUTPUT);
pinMode(pirInput, INPUT);
lcd.init();
Serial.begin(115200);
}
void loop() {
int val = digitalRead(pirInput);
if (val == HIGH){
digitalWrite(ledPin, HIGH);
tone(buzzPin, 1000);
lcd.setCursor(0,0);
lcd.print("Motion Detected!");
if(pirInput == LOW){
pirInput = HIGH;
}
delay(1000);
lcd.clear();
}
else{
digitalWrite(ledPin, LOW);
noTone(buzzPin);
lcd.setCursor(1,1);
lcd.print("Motion ended!");
if(pirInput == HIGH){
pirInput = LOW;
}
delay(1000);
lcd.clear();
}
}