I've been lurking around here looking for ideas on how to accomplish this little project but I've come up short. Basically I want to use my PIR sensor to keep an LED lit EXCEPT when there has been no detected movement for a defined period of time (probably around 2 minutes.) I need detected motion to light the LED, then start some sort of 2 minute timer that is re-started every time motion is detected again. The light would only go off after 2 minutes without detected motion. I've been trying to incorporate the sort of timer code I found here (http://popdevelop.com/2010/04/mastering-timer-interrupts-on-the-arduino/) with the example motion sensor alarm code that I cannot seem to find the source of. This however is not working Does anyone have any ideas how this can be accomplished?
I would accomplish this with a state machine of sorts. Write your loop without delays so that on each pass, it checks the sensor. If there is movement, it resets a variable, say lastMoved, to the current millis() . If the current mills() - lastMoved is greater than 120000 (2 min), it turns on the led.
For an illustration of this concept, see the blink without delay sketch
This is a typical problem called a "missing pulse detector", you don't even need an arduino if that is all you want to do.
Hardware:-
Arrange a pulse to discharge a charging capacitor using a transistor. When the charge reaches a certain level (using a voltage comparator) the output trips.
Software:-
Count up once a second. Each time you get a pulse reset the counter to zero. When counter reaches a certain value do your thing.
I would accomplish this with a state machine of sorts. Write your loop without delays so that on each pass, it checks the sensor. If there is movement, it resets a variable, say lastMoved, to the current millis() . If the current mills() - lastMoved is greater than 120000 (2 min), it turns on the led.
This is a good idea for sure. Just make sure that you don't use int as your datatype or you'll get some weird stuff going on. Sometimes when I write code quickly I'll do something dumb like that then when it doesn't work I'll scratch my head for a while and then eventually find the problem and feel like an idiot