const int PIR_PIN = 4;
const int LDR_PIN = A0;
const int LED_PIN = 6;
int pirState = LOW;
int ldrValue = 0;
int threshold = 500;
void setup() {
pinMode(PIR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Read PIR sensor state
pirState = digitalRead(PIR_PIN);
// Read LDR sensor value
ldrValue = analogRead(LDR_PIN);
// Check if motion is detected and ambient light level is below threshold
if (pirState == HIGH && ldrValue < threshold) {
// Turn on the LED
digitalWrite(LED_PIN, HIGH);
Serial.println("Motion detected and ambient light level is low. Turning on LED.");
} else {
// Turn off the LED
digitalWrite(LED_PIN, LOW);
Serial.println("No motion detected or ambient light level is high. Turning off LED.");
}
delay(100);
}