Arduino Bathroom Occupancy Detector with PIR Motion Sensor & 16x2 I2C LCD Display | English Subtitle
ฝัง
- เผยแพร่เมื่อ 31 มี.ค. 2024
- If you need any custom code for your projects, please contact me on Skype- G B RANJITKAR (message only/no calls) Not free, there will be a fee.
Arduino Bathroom Occupancy Detector with PIR Motion Sensor & 16x2 I2C LCD Display | English Subtitle
Code : code is on the comment below.
Facebook : / doit20-104218935882053
Please Subscribe my Channel. ThankYou!
#include
#include
// Initialize the LCD using the address 0x27 (you might need to adjust this according to your LCD module)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// PIR motion sensor pin
int pirPin = 2; // You can connect the signal pin of PIR sensor to any digital pin
int ledPin = 12; // LED pin
bool motionDetected = false;
void setup() {
// Initialize LCD
lcd.begin();
// Initialize PIR motion sensor pin
pinMode(pirPin, INPUT);
// Initialize LED pin
pinMode(ledPin, OUTPUT);
// Print initial message on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Toilet sign ");
}
void loop() {
// Read the PIR sensor output
motionDetected = digitalRead(pirPin);
if (motionDetected == HIGH) {
// Display message on LCD when motion is detected
lcd.setCursor(0, 1);
lcd.print(" OCCUPIED ");
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(1000); // Delay to avoid multiple detections
} else {
// Display "VACANT" on LCD when no motion is detected
lcd.setCursor(0, 1);
lcd.print(" VACANT ");
digitalWrite(ledPin, LOW); // Turn off the LED
}
}