My circuit consists of a pir sensor, buzzer, lcd, and other sensors but they dont really matter right now, and whenever motion is detected, the lcd shows a "Motion Detected!" message but when there is no motion the lcd is supposed to just stay on the message "Safe". The problem is whenever motion is detected, it shows the appropriate message but after the motion stops it overlaps with the message "Safe". Can someone pls help me.
Full Code:
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define Type DHT11
int sensePin=2;
DHT HT(sensePin,Type);
float humidity;
float tempC;
float tempF;
int setTime=500;
int delT=500;
int pir=4;
int motion;
int buzzPin=6;
void setup() {
// put your setup code here, to run once:
HT.begin();
lcd.init();
pinMode(pir,INPUT);
pinMode(buzzPin,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
lcd.backlight();
humidity=HT.readHumidity();
tempC=HT.readTemperature();
tempF=HT.readTemperature(true);
motion=digitalRead(pir);
if (motion) {
digitalWrite(buzzPin,HIGH);
lcd.setCursor(0,1);
lcd.print("Motion Detected!");
}
else {
digitalWrite(buzzPin,LOW);
lcd.setCursor(0,1);
lcd.print("Safe");
}
lcd.setCursor(0,0);
lcd.print("H=");
lcd.setCursor(2,0);
lcd.print(humidity);
lcd.setCursor(8,0);
lcd.print("C=");
lcd.setCursor(10,0);
lcd.print(tempC);
}
Specific Part:
if (motion) {
digitalWrite(buzzPin,HIGH);
lcd.setCursor(0,1);
lcd.print("Motion Detected!");
}
else {
digitalWrite(buzzPin,LOW);
lcd.setCursor(0,1);
lcd.print("Safe");
}