const int pirPin = 14; // PIR sensor output
const int ldrPin = 34; // LDR analog output
const int ledPin = 2; // LED acts as bulb
int threshold = 500; // Adjust for darkness
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int motion = digitalRead(pirPin); // Read PIR sensor
int ldrValue = analogRead(ldrPin); // Read LDR value
Serial.print("LDR: ");
Serial.print(ldrValue);
Serial.print(" | Motion: ");
Serial.println(motion);
// Turn bulb ON only if dark AND motion is detected
if (ldrValue < threshold && motion == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.println("Bulb ON");
} else {
digitalWrite(ledPin, LOW);
Serial.println("Bulb OFF");
}
delay(200);
}