const int ledPin = 13; // LED connected to digital pin 13
const int ldrPin = A0; // LDR connected to analog pin A0
const int pirPin = 2; // PIR sensor connected to digital pin 2
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
pinMode(pirPin, INPUT); // Set the PIR sensor pin as an input
}
void loop() {
// Read the state of the LDR (A0) and PIR sensor (2)
int ldrValue = analogRead(ldrPin);
int pirValue = digitalRead(pirPin);
// Check if A0 is low (below a threshold) and pin 2 is high
if (ldrValue < 500 && pirValue == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
}