Hi all, I am a newbie to C++ and Arduino so have a small project but am not sure how best to tackle it. Basically I have a Mega board and will put 2x PIR sensors on it and then output to a 2x Relay board. These will be installed in my shed and 2 sets of lights on the relays. All nice and simple so far. The idea is that you walk in the shed and it will switch on the 1st set of lights and the same with sensor #2. The issue is that I do not want to use the timer on the PIR, but want to tell the program that if it detects movement (PIN 53 goes high) then to turn on Relay No. 22 for 5 minutes (pin 22 to go High). Then if it detects movement within that 5 minutes, to reset teh 5 mins countdown. I tried to use the 'pause' command, but this paused the program, so PIR 2 would not work independently. Is there any way I can tell it code wise to hold for 5 mins (or so) but still allow the program to run so PIR#2 can still independently work? Or do I need to buy a real time clock and some how interface that into my code for counting? Anybody got any idea, such a simple project, but am scratching my head. My code so far is this:
In advance, thank you all for any assistance you can give me.
const int pirshed = 53; // the number of the pushbutton pin
const int lightsshed = 22; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
pinMode(lightsshed, OUTPUT);
pinMode(pirshed, INPUT);
}
void loop(){
// This is the PIR Sensor for the main shed area
buttonState = digitalRead(pirshed);
if (buttonState == LOW) {
LightShedOn();
}
else {
LightShedOff();
}
}
void LightShedOn(){
digitalWrite(lightsshed, HIGH);
}
void LightShedOff(){
digitalWrite(lightsshed, LOW);
}