Hi, I am newer with Arduino and I have a few questions.
First off, I am ventilating my basement because we have 3 cats. I am using a motion detector so that when the cats go down there, the fan turns on for approx. 10 minutes. I still want the fan to run for lets say 30 mins/hour.
I am looking for the most simple way of achieving this.
I am using the count in the interrupt section because when the relay turns off, the arduino sees the sensorPin as RISING(I don’t know why-perhaps it is not opto-isolated?), this is my work-around.
I also realize that I probably should not be using delay(), but for now, it is just ok.
I really thought that I could simply use an interrupt and then goto the top of the void loop() section.
Eventually I would like to add humidity criteria, but this will be nice for the time being.
I'd suggest that you drop the delays now and use millis - it'll make it easier to add your humidity control later.
As to your relay causing a spurious interrupt, do you have a snubber diode across the relay? If not, take a look at the solenoid example in the playground to see how to wire one up.
If you do adapt to millis, you'll need to figure out the requirements - what should happen when the PIR detects movement and the fan is already on during its 30 minute cycle? What if it's 29 minutes through the cycle? Does additional movement reset the clock on the ten minute interval - I assume not.
How long does the PIR input stay high? Without delays, you may find that you can poll it and forget the interrupts.
Hi,
I got a similar system to turn on the light in my hallway. It is easily adjustable for your situation. When it detects movement the lights turn on bright between 07.00 and 23.00 and the lights turn on dimmed between 23.00 and 0700 , but only when it isn't light enough from daylight. I added a ethernet shield and wired it to my router so all timings can be set on an networked pc (internet). The light sensor i use can be replaced with a humidity (and temperature) sensor and the relays i use for the lights can of course switch on your fan. Let me know if you are interested in the code.
marque - I'm certainly interested in looking at your code if you can send it / post it? I'm building basically exactly the same thing at the moment! Thanks!
HarmlessSaucer:
marque - I’m certainly interested in looking at your code if you can send it / post it? I’m building basically exactly the same thing at the moment! Thanks!
I will post the complete code this week. I need to clean up the code first (remove cosm stats, alarm notifications, webcam control etc.), but below is the main part.