Wake Arduino Once a Day

I have a battery powered Arduino project that need to be very low power and wake up and run once a day once it’s getting dark or is dark outside. My thought was to use a resistor divider with a photocell to pull a pin up down which would interrupt wake the Arduino and have it run its routine. However, once it's dark and the Arduino wakes up to run its routine, I want it to go back to sleep until it’s dark again the next night. Is it possible to set the interrupt change from waking when it goes low to waking when it goes high once the program is running?

If so, then I could write a program that wakes the Aruindo when it’s dark out, runs it's routine, then changes the interrupt to look for when it’s light out and put it to sleep. When it wakes up when it’s light out I can tell it to change the interrupt again to look for when it’s dark out again and that will get me to keep the arduino sleeping but wake and run my routing the next night. Am I overthinking this and should I just use a timer to get the Arduino to sleep at low power for 12 hours until it's light again and then look for a darkness interrupt after the 12 hours is up or is there a better way to do this?

Take a look into Arduino reference and search for "Interrupt". It's well explained there.

Another option is based around the built-in watchdog timer. This would allow your micro to sleep for up to 8 seconds at a time. Your micro could wake every 8 seconds, sample the photocell, decide what to do and then go back to sleep again.

I use the watchdog timer like this to sleep for an hour, then transmit a radio message, and go back to sleep again. It's been running on a couple of AA batteries for over 3 months now with minimal reduction in battery voltage.

This is another henhouse door controller, isn't it?

Paul__B: This is another henhouse door controller, isn't it?

You've polished Your Chrystal ball? Let's see.....

Paul__B: This is another henhouse door controller, isn't it?

haha not this project, it's to sprinkle food on the ground for rodents to feed at night under my bird feeder

Sone RTCs have alarms you can use

You will need some kind of RTC. Especially around dusk and dawn there is a good chance of triggering multiple times due to changes in light level just around the trigger point. A good hysteresis will help here but then there's no chance to use the light level (and the LDR itself) to trigger an interrupt.

A possible use for the RTC: set an alarm to wake up, check light level, if still day set it to say 10 mins later and go back to sleep. Then when it does get dark, you can set the alarm for the next day half an hour before now (to account for seasonal changes), do what needs to be done, and go back to sleep until the alarm goes off again. That should ensure minimum power use, and no risk of it thinking night is over when it was just a brief change in light levels.

Note: an LDR and resistor as voltage divider wastes current all day long (less at night when the LDR is muhc higher resistance). Not good for battery use. Connect the pull-up resistor to an output pin, which you set to INPUT or LOW before going to sleep, and OUTPUT, HIGH when measuring.

wvmarle: Connect the pull-up resistor to an output pin, which you set to INPUT or LOW before going to sleep, and OUTPUT, HIGH when measuring.

If you use the effective 47k internal pullup, you can do this without using an extra pin. :sunglasses:

Not if you want to do a measurement with analogRead()... which is what I would assume for flexibility in actual light level for dark/light.

If you use an RTC, you should be able to calculate the time for sunset and set the alarm appropriately, unless you want to account for other factors such as cloudy weather.

I agree that an RTC is the way to go. Otherwise your circuit can be confused by passing clouds, lightning strikes, etc. You could put your Arduino into deep sleep, and have the RTC alarm trigger a wakeup interrupt at the time you've set. Or if you have other parts of your circuit that draw current but can't be put to sleep, the RTC alarm could control a power mosfet that would keep the entire circuit powered down until the alarm triggers. Something like the DS3231 would work well for this, and it would run on its own coin cell battery for a long time, so your main battery would be preserved.

wvmarle: Not if you want to do a measurement with analogRead()... which is what I would assume for flexibility in actual light level for dark/light.

Why not? INPUT_PULLUP works perfectly well for analogRead() except on A6 and A7.

markd833: Another option is based around the built-in watchdog timer. This would allow your micro to sleep for up to 8 seconds at a time. Your micro could wake every 8 seconds, sample the photocell, decide what to do and then go back to sleep again.

I use the watchdog timer like this to sleep for an hour, then transmit a radio message, and go back to sleep again. It's been running on a couple of AA batteries for over 3 months now with minimal reduction in battery voltage.

Mark that's really impressive. Is there a low power library you're using as well? I assume you cut out the voltage regulator too.

This is a project I'm interested in following.

I think using some of the ideas done by Arduino cat feeder projects, internet search words "arduino cat feeder", that one of those ideas could be adapted.

I tried using LDR's for solar tracking but their hysteresis made the system unreliable. I switched to Photodiodes and my solar tracking issues went away.

Anyways when I mentioned this idea to my wife, getting up at 0400 when its 21F outside to feed the critters, she made sure that I added web site control. She wants to be able to click on her phone and feed the critters, as well as have automated feeding

Paul__B:
Why not? INPUT_PULLUP works perfectly well for analogRead() except on A6 and A7.

I expect analogRead() to switch off the pull-up… in most cases it will mess with a reading if set to that mode.

@freebird4446:

Mark that's really impressive. Is there a low power library you're using as well? I assume you cut out the voltage regulator too.

Have a look at LowPowerLab on github. You will find their LowPower library there.

I have a couple of boards that run straight off 2x AA batteries without any regulator. The RFM69 module has a min voltage of 3v (if I recall) but is still working at 2.7v.

I also have 2 boards running off 3x AA batteries and a 3.3v regulator. I think the regulator was an MCP1700 3.3v series device. I'll check and correct this post if it's different.

A lot depends on the other devices you want to use - EEPROM, Flash, temp sensor etc. If they operate down to, say, 1.6v you could run without a regulator. If they bottom out at 3v, then go for the 3 battery + regulator solution.

Another option, and a power supply guru may jump in here, is to use a boost converter to suck the last bit of power out of the batteries whilst trying to maintain 3.3v. But I don't know if this is more of less efficient than the other solutions.

Devices also have a high voltage limit - if that's 5V or more (3xAA delivers almost 5V when fresh) no need to bother with regulator... EEPROM will be fine. Flash not so much. The RFM69 is rated to operate at 1.8-3.6V which is perfect for powering by 2xAA batteries. No regulator needed.

Using a boost converter may work but the quiescent current of those things is often quite high, likely resulting in a net loss.

wvmarle: I expect analogRead() to switch off the pull-up... in most cases it will mess with a reading if set to that mode.

Why would it do that?

What do you mean by "mess with a reading"?

Adding a pull-up to an analog signal may change what you're reading - if it's from a voltage divider, for example.