Arduino button pin that also turns on/off power?

This has probably been covered, but I don't seem to be able to come up with the right search terms to find it.

I want to use a momentary switch to turn on power to the entire device and once the Arduino becomes "Live" let it control whether power stays on or off. I also want to use that same button as a regular input input button for the Arduino.

I kind of see some kind of circuit that is started by pressing the button pin, but "kept alive" by a High or Low signal on a digital pin once the Arduino "Wakes up" and is able to take control. It would have to do that while still being functional as a regular input button.

Once the correct conditions are met (In this case, button has been held down for > 5 seconds) it changes the state of the digital control pin and lets the circuit close.

The whole idea is to have a way to shut the whole thing off for charging WITHOUT having an extra switch and/or button visible. I also want to not have a visible charging port either, I will be using a couple of screw heads or something to carry the charge current.

Has anyone seen/heard of/can direct me to information about that? Is there a name for that kind of circuit or some search term that may help me find it?

try this code:
http://www.arduino.cc/playground/Learning/ArduinoSleepCode

David

I'm not sure it would be safe to charge if it's only asleep? Would the charger (Li Ion, by the way) be affected and maybe not charge/shut off charge if the whole circuit was left connected?

Plus, I'd like to shut off the whole device, not just the Arduino. There will be accent LEDs and some other electronics in the whole system... none of which would overly affected by the charge current I don't think, but they would draw power and at best make it have to charge longer.

Is this what you're looking for...

That's a heck of a good start! I actually ran in to that the other day..... and just couldn't wrap my head around how to make it work.

Right now I am using click, double click and hold to run the functions of the lightsaber. I can also do a "Long hold" and hopefully cut all the power with it. I'd love to do it with just one button.... maybe I'll just have to give up and go ahead and use two buttons on the project.

I just can't think of a way to use a single button as both a regular input AND have it pulse (only the once) to turn on that power switch. Maybe I could add in a relay and use the NC posts to allow the signal to start, and once the power starts flowing have it hold the relay open? Maybe the same idea with a transistor instead?

I'll keep my brain grinding on it... it's definilty a "Learning opportunity" as it's just a little over my head, LOL.

I think you can accomplish what you want with a DPST (double pole single throw) pushbutton. One pole would be connected to the Pololu switch. The other pole would be connected as a pushbutton an Arduino pin.

For the "hold to off", you would have to mimic being off (e.g. turn off the LEDs), wait for the human to release the pushbutton, then trigger the Pololu switch to turn off the power.

But wouldn't pushing the button also turn the Pololu switch off too? (IE... you "power on" and you now have the Arduino running. You click the DPST switch, which would be fine if only the Arduino saw it, but the Pololu switch also sees it and would then turn off.)

What about an And gate? IE.. start the Pololu, Arduino boots. It writes a pin LOW that's hooked to an AND gate, Now, no matter what the other pin (The input button) on the AND gate is, it won't pass along the HIGH out until the Arduino writes that first pin to a HIGH.....

Maybe?

But wouldn't pushing the button also turn the Pololu switch off too?

No. The device essential has two digital inputs: one turns the power on; the other turns the power off.

For your application, the ON is wired to the button. When the button is pressed, the power is turned on. If the button is pressed and the power is already on, the power remains on.

The OFF can be wired to an Arduino pin so it can turn itself off.

What about an And gate? IE.. start the Pololu, Arduino boots. It writes a pin LOW that's hooked to an AND gate, Now, no matter what the other pin (The input button) on the AND gate is, it won't pass along the HIGH out until the Arduino writes that first pin to a HIGH.....

It isn't necessary. I believe the Pololu device will work as-is for your application.

The Pololu module is similar to what you need, but doesn't quite do what you asked for.

First, you need to find out what the initialization time for your Arduino is. This varies depending on clock speed and which bootloader you have.

Next, you need a CMOS 555 and a CMOS 2-input OR gate. I think you can get a single OR gate in a surface-mount package, but I've never seen small-pin-count logic DIPs :frowning:

You'll also need a P-channel FET similar to the one in the Pololu module, with a low RDS(ON) and a low threshold voltage.

Your pushbutton needs to be a switch to ground, with a pullup to Vcc, for this to work. The switch will feed the trigger input of the 555, one of the OR gate inputs, and a digital input pin on the Arduino.

Wire up the 555 as a one-shot, with a period of about 5 seconds minus the Arduino initialization time. Wire its output to the second input of the OR gate.

The 555 and the OR gate need to be wired so they're always powered.

When you press the button, it will trigger the 555. The 555's output will go high for a few seconds, then go low. If you're still holding the pushbutton when the 555 goes low, the output of the OR gate will also go low (there will also be a glitch of a few microseconds when the button is pressed, but that's not a problem). The output of the OR gate is connected, through a diode, to the gate of the FET: when it goes low, the FET turns on.

In the setup() function of the Arduino, you set a digital output pin low. This pin is also connected to the FET through a diode. Once that pin goes low, you can release the button: the power will stay on. You can also use that button as an input to the Arduino without affecting the power.

To shut the power off, you just set the output pin high, and power will go off when the pushbutton is released.

The trick with the diodes is called a "wire AND". It's commonly used to allow several peripheral chips (with open-collector/open-drain outputs) to share one active-low interrupt input (The diodes make the "normal" outputs on the ATMega and the OR gate look kinda like open-drain ones). It requires a pullup on the gate of the FET, so it will be turned off when neither chip is driving it.

I wenta head and ordered a Pololu module, even if I don't use it for this particular project I'm sure I can do something with it, LOL.

I get what you are saying... I have seen SM logic gates that wouldn't be that painfull to solder.

Mostly, it's a space issue... even the Pololu module was going to be cutting it close, space wise. I doubt I could perf-board up a smaller soloution with the circuit you describe anyway, and there's still the issue of having a couple of circuits "swinging in the breeze" while charging.

I may just have to go with either a switched charging port, or a secondary switch. The only issue with the charging port would be whether or not the switch pin can handle the 1.5-3A current draw. It also may be more visible than say a latching switch that's accessable via a pin hole or something.

It would be nice... and will be kept in mind for future development for later versions.

The Pololu module is similar to what you need, but doesn't quite do what you asked for.

What did I miss?

I wenta head and ordered a Pololu module, even if I don't use it for this particular project I'm sure I can do something with it, LOL.

I apologize. I honestly thought it would work. I hope I haven't caused you too much trouble.

What did I miss?

The time delay, mostly: the Pololu is "instant on" and "instant off".

There's no need to apologize: it was a good start for this particular problem, and will probably directly help someone else who comes here looking for a solution where they actually want the "instant" action.

Plus, I was hesitating about offering my idea because I wasn't familiar with any readily-available low-threshold P-channel power FETs. Once I was sure there were some out there, I went ahead and fleshed out what I'd been thinking of.

So you actually got things moving. And Troy might well decide to use some variant of my idea to trigger the Pololu module. Or someone else might.

If some one person had exactly the right answer to every question posted here, the threads would be very short, very boring, and not very useful to anyone with similar, but not identical, problems.

Tossing out "close, but no cigar" ideas the way you did is how readers learn new stuff that may help them out in similar situations, and how the cigar-winning ideas often get inspired. It's what makes the open discussion and collaboration process work.

If you power this from a single Lithium cell (3.7V) you should be able to get away with a single n-channel FET to control power on/off. You could also leave it powered while charging as voltage woud stay well below 5V (assuming you're powering your circuit/mcu directly from the cell - no regulator).

Also I can't really see a need for the external timer. Once the AtMega start you can simply use the millis() timer (in your setup function) to wait until 5s has passed before you set a high level on the FET gate using one of your digital outputs. This will then leave the FET triggered also after the "power button" is released.

The button should be wired so it pulls the FET gate high when pushed and you need a pull low resistor on the FET gate to keep it swicthed off when not powered. To switch off you simply set the digital out connected to the FET gate to low.

Coding Badly... not at all... I ordered it knowing full well it was a "shot in the darK' for this particular application.... and also knowing I have about a dozen other things it would work just great for, LOL.

As a matter of fact, an issue several lightsaber builders have run in to are sound cards that run from a momentary switch. Not a problem in itself, but you need a latching switch of some kind to turn on the LED drivers and have them stay on. No one wants two buttons on thier saber when one will do. Guess what the best $7 answer to that problem is? LOL.... they have probably sold a couple dozen to folks from the lightsaber board after I posted it.

So, it goes in the "Toolkit" and will absolutely get used at some point! LOL.

I think this design discussion is perfect. I've been looking for the same thing everywhere and have tooled around with logic gates for a while to no avail. If nobody has time to make a diagram I would be very grateful, otherwise I will try if I ever understand the whole thing.

Also, question for Ran or anyone who can answer: Is this system totally power free in off state? The problem I've been running into with the 555s and the latch circuits is that they require a basal amount of power just to be able to respond to stimuli which I think is excellently explained here:

Does your design circumvent the problem and allow for a true LOW state in "off" to preserve batt power? Would the Pololu as well?

Thanks,
www.amrk.net

Would the Pololu as well?

They document the power consumption in the off state. I believe it's 0.1 microamps.

One choice not mentioned in this thread is a "latching relay". (My thanks to Retrolefty for this suggestion)