#define LDR 2
#define PIR 22
#define LED 33
int pirState;
int ldrValue;
void setup() {
//Serial.begin(9600); // Initialize serial communications with the PC
pinMode(LED, OUTPUT); // If LED is activated wil turn on as an ouput
pinMode(PIR, INPUT); // PIR sensor detects if there is motion
digitalWrite(LED, LOW); // LED turns off if there is light and or no motion
}
void loop(){
ldrValue = analogRead(LDR); // initialize Photoresistor output
if (ldrValue <= 512) { // if photoresitor detects ldr value less than or equal to 512,
digitalWrite(LED, HIGH); // then the LED light will turn on.
}
else {
pirState = digitalRead(PIR); //
if (pirState == HIGH) {
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
}
else {
digitalWrite(LED, LOW);
}
}
delay(1000);
}