I'm working on a self-contained project that will be battery powered. I want it to come "on" when the user presses a pushbutton, but then turn "off" again after, say, 10 minutes of inactivity.
This device must be very power conservative, because it won't be very feasible to swap out the 9V battery. So what I really want is for the Arduino inside to physically turn itself OFF (and not just enter a quiescent state which appears "off" to the external world).
Being a software guy, I'm having some difficulty envisioning what kind of circuit would allow me to
(a) switch "on" the Arduino at the push of a (momentary contact) pushbutton
(b) switch it back "off" in response to a digitalWrite to one of the pins (after the 10 minute timer lapses) (I don't need any advice on how to write the software.)
Any suggestions to get me started?
[As an addendum, I read somewhere in a recent post that you can put the Arduino into a sleep state. Does anyone know how to calculate how long you'd expect a 9V battery to provide adequate power for an asleep Arduino? If the answer to this question is favorable, I would probably opt to solve the on/off problem by simply putting the device to sleep rather than turn it completely off, since this wouldn't involve any fancy (by my standards) circuitry.]
I think I get the relay, but what does the switch connect to? The same relay? Is the relay controlled (somehow) by both this "power" switch and an Arduino digital pin? Pardon my density, please.
Thanks a bunch for working this through with me, Stephen.
This is the part I'm anxious about. Assuming my user presses the button to turn the system on, isn't there some delay time on the order of SECONDS before my sketch gets control and can force the relay control pin HIGH? I'm worried about this interval. What keeps the power on during that time? Would a pullup resistor be appropriate here?
There is a simple way to wire a relay that once it is energized, it switches power to itself (through it's own contacts) to keep it energized.
But relays use a fair amount of power, and it sounds like that is the issue for you.
Not that I have a solution for you :), but I'm surprised you didn't get one by now.
One thing I do is to use tilt switches (actually the politically incorrect mercury switch) for battery projects. Turn the box one way, it's on. The other, it's off. However, it doesn't help with your auto shutoff issue. I'll get back if I think of something. (PM someone?)
You could use a flip-flop so one high turns it on and the next turns it off, less power. Also try to design for AA batteries rather than a 9volt they will last longer.
This is a proprietary solution, but it looks like it would do more or less what you're looking for: the small button could switch the Arduino on and then after some task, the Arduino could digitalWrite to the "Off" pin to turn the power off. The switching circuit itself draws 10uA in the off-state, but that's very little and should stretch your battery life.
The Arduino is based on hardware with very good sleep ability. If you bypassed the regulator, removed the power LED and the FTDI chip, you could get a power efficient solution by reading the atmega datasheet regarding sleep modes. You'd want to run from three AAA cells or similar instead of 9V, so you could run the Arduino from 4.5 to 3.0 volts directly.
How would that work with the arduino variants that don't have the FTDI on-board?
You just desolder the power LED, power thru the regulated power input pin and... hack some custom code to access power saving modes? Those modes aren't supported by the standard IDE, right?
How about a 555 timer fired by the power button? The output of the timer would stay high for 10 seconds keeping the power on until the Arduino is up and stable. Takes care of switch bounce too.
Wow! I'm much obliged for the plethora of great responses. It's a good lesson: phrase your request succinctly and you'll get a better response. Thanks.
So to summarize helpful ideas I got:
Connect a relay on the power line.
Use AA or AA batteries.
Use a flip-flop
Latching relay to sustain power until Arduino comes up
The pololu proprietary solution
Remove all power draining stuff and just put the Arduino in a sleep state
555 timer to sustain power
but my favorite, and the one I think I'll try first (I'm extrapolating here)
wire up an off-center motor that, when activated, knocks my little box onto its side, turning off BroHogan's mercury tilt switch. Seriously, though, thanks Bro, and thanks for the latching circuit diagram. As a SW guy it will probably take me a day to understand how that works, but I am determined to figure it out.