Hello everyone;
I need some help with this code please. It does nothing right now.
What I'm trying to do is:
- If it's not dark, keep checking until that changes.
- If the PIR is not activated, keep checking until it is.
- If both are true, sound the alarm and blink the LEDs for three seconds.
Any hints or help would be helpful. Thanks.
int ldrPin = 0;
int pirPin = 8;
int LED1 = 5;
int LED2 = 6;
int relayPin = 10;
byte pirState = LOW;
byte ldrState = LOW;
unsigned long interval = 3000;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
void setup() {
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(8, INPUT);
pinMode(0, INPUT);
pinMode(10, OUTPUT);
}
void loop () {
Start:
unsigned long currentMillis = millis(); //Get current time
analogRead(ldrPin); //Is it dark?
if (ldrState >= 100) {
goto Start;
} //If it's not dark, check again
else { //If it is dark go on
}
delay(10);
digitalRead(pirPin); //Is the PIR activated?
if (pirState == LOW) {
goto Start; //If it is not activated, go to start
}
else {
delay(10);
}
}
void alarm () {
digitalWrite(relayPin, HIGH); //If the pin is actuated and it is dark, sound the alarm
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
delay(100);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
delay(100);
if ((unsigned long)(currentMillis - previousMillis) >= interval) { //let it sound for 3 seconds
previousMillis = millis();
}
}