Hello everyone.
I looking for the solution about my small project.
So I decided to make motion and light sensor using PIR sensor and LDR.
I have the code which work perfectly. Here is it
#define LDR 0
#define PIR 2
#define LED 3
int pirState;
int ldrValue;
void setup() {
//Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(PIR, INPUT);
digitalWrite(LED, LOW);
}
void loop(){
ldrValue = analogRead(LDR);
//Serial.print("Analog reading = ");
//Serial.println(ldrValue);
if (ldrValue <= 512) { // dark
digitalWrite(LED, HIGH);
}
else { // ldrValue > 512
pirState = digitalRead(PIR);
if (pirState == HIGH) {
digitalWrite(LED, HIGH);
delay(5000);
digitalWrite(LED, LOW);
delay(1000);
}
else { // pirState == LOW
digitalWrite(LED, LOW);
}
}
delay(1000);
}
my question is, how to make :
LED OFF when time is (example) 10pm - 3am but ON when there is a motion