// Pin definitions
int pirPin = 5;
int ldrPin = 34;
int led1 = 18;
int led2 = 19;
int led3 = 21;
int motion = 0;
int lightValue = 0;
unsigned long lastMotionTime = 0;
int delayTime = 5000;
void setup() {
pinMode(pirPin, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
Serial.begin(115200);
}
void loop() {
motion = digitalRead(pirPin);
lightValue = analogRead(ldrPin);
Serial.print("Light: ");
Serial.print(lightValue);
Serial.print(" | Motion: ");
Serial.println(motion);
// 🌙 DARK
if (lightValue > 2000) {
if (motion == HIGH) {
lastMotionTime = millis();
// 🚶 FULL brightness (clear difference)
analogWrite(led1, 255);
analogWrite(led2, 255);
analogWrite(led3, 255);
}
else if (millis() - lastMotionTime < delayTime) {
// stay ON
analogWrite(led1, 255);
analogWrite(led2, 255);
analogWrite(led3, 255);
}
else {
// 🌃 VERY DIM (visible difference)
analogWrite(led1, 5);
analogWrite(led2, 5);
analogWrite(led3, 5);
}
}
else {
// ☀️ DAY → FORCE OFF
analogWrite(led1, 0);
analogWrite(led2, 0);
analogWrite(led3, 0);
}
delay(100);
}