Pages: [1]   Go Down
Author Topic: Absence sensor  (Read 856 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello!

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 smiley-sad Does anyone have any ideas how this can be accomplished?
Logged

0
Offline Offline
Sr. Member
****
Karma: 2
Posts: 360
I'm 15. I like making things. I like breaking things better.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Alice asked the Chesire Cat, who was sitting in a tree, "What road do I take?"
The cat asked, "Where do you want to go?"
"I don't know," Ali

Seattle, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This recent thread covered exactly what you want  http://arduino.cc/forum/index.php/topic,68406.0.html
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34159
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, this is great stuff, I'll be able to get this up and running this weekend for sure. Thanks so much!
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 193
The people the people they see me and they know
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Logged

Pages: [1]   Go Up
Jump to: