# Power circuit with a push button

In my current project, I try to connect a load rated at 5V/2A with a 5V power supply. To avoid plugging and unplugging the supply over and over again, I decided to add a push button. To turn the device on and off, it must be held down for 3 seconds. Constructing this circuit is harder than I thought it would be.

(This is just the beginning.)

When the button is pressed, C2 charges through R1. After some time, Q1 becomes saturated when C2's voltage drop gets higher than 0.7V. Load resistor R2 is powered at this time. However, this circuit is missing crucial aspects: The current through the load equals ~2A, there should be no voltage drop bigger than 0.01V across the transistor when saturated, C2 must discharge way faster to timeout a press shorter than 3 seconds, and most importantly, R2 must keep its voltage.

My suggestions would be:

• Instead of feeding the voltage across C2 directly through the base-emitter junction, I could compare the voltage with a comparator, then feed the output (HIGH / LOW) to a power MOSFET
• Use some kind of latching circuit or flip-flop to keep the voltage at R2 consistent
• Add a resistor parallel to C2 with an N-channel BJT to open a discharge path when SW1 is open (inverter?)

Will this approach work? Or is there an even simpler solution?

EDIT

To clarify why I can't use switches, here are some reasons:

1. The switch is exposed to the outside. If the user accidently hits it, it cuts the power, therefore losing all unsaved data without any warning. Even with a timer, most of the time the user wouldn't realize it fast enough.
2. The push button is used to give a smartphone-like interface. It can trigger different things after a certain time held down instead of a switch with only 2 states.
• If this is a one time application, I would use an NE555. Seems faster and simpler than doing with discrete parts. Commented Feb 18, 2018 at 20:17
• I heard it can only sink or source 200 mA at its output, so I'd need a MOSFET, right? Commented Feb 18, 2018 at 20:18
• Yes, you would still need an output stage. BJT would work also. I was thinking about the timing challenge. Commented Feb 18, 2018 at 20:20
• It sounds clear to me, but I want to ask in my own words to be sure. You want it to take 3 seconds of the push button being held down in order to turn the power on and also you want it to take a different 3 seconds of applying the push button the same way in order to turn the power off?
– jonk
Commented Feb 18, 2018 at 20:45
• My suggestion is to just use a simple mechanical toggle switch. Commented Feb 18, 2018 at 23:30

simulate this circuit – Schematic created using CircuitLab

Figure 1. A 4017 flip-flop.

How it works:

• On power-up C2 pulls the RST pin high as the voltage rises. R3 discharges it. Q0 is on and Q1 is off. CLK input is low.
• If SW1 is held for 3 s C1 will charge to the trigger level for the clock input. Q0 will turn off and Q1 turn on. Holding the button for longer will have no effect.
• On releasing the button C1 will rapidly discharge through D1 and R1.
• Pressing SW1 again for 3 s will advance the counter again, Q2 will turn on but since this is connected to the RST pin the chip will return to its initial state. D2 prevents Q2 interfering with the power-up reset pulse.

This sorts out the logic. I think you can figure out the power switching.

Power-down warning

With the addition of the signal line to your micro-controller you have a 3 s warning to trigger a "save data" routine before the power is cut. Some logic may be required in the controller to suppress this during power-up, etc.

• I was gonna answer something 95% like yours, but you were faster! Hahaha anyway, +1 for the good answer Commented Feb 18, 2018 at 23:49
• Perfect, exactly what I was looking for! Commented Feb 19, 2018 at 5:23
• 4017 pinout corrected. (It starts at Q0, not Q1.) Added a power-up reset circuit so that it powers up in a known state. Commented Feb 19, 2018 at 7:09

Let me show you the problems with your question. There are several unanswered questions that arrive from a simple state machine table. (The following assumes a debounced PB.)

1. OFF STATE: On entry to this state, turn off the power to the MCU. If the PB is unpressed, continue in this state. If the PB is pressed, then start a 3-second timer and go to step 2. (Regardless of its prior state, it must be reset so that 3 seconds will elapse -- so this means that if there is a hardware timer and if for some reason that hardware timer is still timing away, you MUST be able to reset it the moment the PB is pressed.)
2. TIMER PENDING: If the timer is still busy and the PB is still pressed, then continue in this state. If the PB is released, go to step 1. If the PB is still held, but the timer expires, then go to step 3.
3. PB PENDING: If the PB is still held but the timer is on for some reason, there is an error in the timer -- go to step 2 and re-await the timer (or else choose some other behavior.) If the PB is not held but the timer is on, then there is an error in the timer -- go to step 1 and re-await the PB to restart the process (or else choose some other behavior.) Otherwise if the PB is still held, continue in this state. And if the PB is released, then go to step 4.
4. ON STATE: On entry to this state, turn on the power to the MCU. If the PB is unpressed, continue in this state. If the PB is pressed, then start a 3-second timer and go to step 5. (Regardless of its prior state, it must be reset so that 3 seconds will elapse -- so this means that if there is a hardware timer and if for some reason that hardware timer is still timing away, you MUST be able to reset it the moment the PB is pressed.)
5. TIMER PENDING: If the timer is still busy and the PB is still pressed, then continue in this state. If the PB is released, go to step 4. If the PB is still held, but the timer expires, then go to step 6.
6. PB PENDING: If the PB is still held but the timer is on for some reason, there is an error in the timer -- go to step 5 and re-await the timer (or else choose some other behavior.) If the PB is not held but the timer is on, then there is an error in the timer -- go to step 4 and re-await the PB to restart the process (or else choose some other behavior.) Otherwise if the PB is still held, continue in this state. And if the PB is released, then go to step 1.

This is not so complicated for a PIC10F200. In fact, it's relatively trivial to perform. (It still will require an external driver circuit to handle the required current, obviously.)

However, this is quite a bit more complex to do in analog hardware. There exist components such as the 74121 that can be used to represent your 3-second timing component(s). You will also need something to keep track of the power-on state (some form of FF.) And also something to keep track of the current state and some added logic to make the state transitions.

That said, you might make some "don't care" decisions to help simplify the hardware logic involved. But you haven't specified what to do in the error conditions mentioned above (and you must decide what you can accept in those cases, because they might occur.)

An MCU requires a toolchain, learning curve, and some coding. That's a process by itself and I don't want to tell you that this is the better way. That's something you have to decide.

But I can say that the hardware logic won't be trivial, either. I see analog debouncing, a short term reliable delay as well as a 3-second delay timer (or two), one or more FF, and a variety of logic gates. And you would need to carefully specify all of the details. Look over the above logic and tell me exactly how you'd want to carefully describe the exact behaviors of this circuit.

I'd go with the SOT-23-6 MCU.

• Good points you mentioned, I didn't think of those situations. Commented Feb 18, 2018 at 21:52
• Power on: MCU is off, PB gets pressed: 3s timet starts. When PB gets released before timer expires, the timer gets reset. If it's held for longer than 3 seconds, it will still turn on. When the PB gets finally released, functionality switches: The next time the PB is pressed and the timer expired, the MCU will shut down even if the PB is longer held. Functionality switches back to its original state. Commented Feb 18, 2018 at 21:59
• I think the MCU option offers the advantage of low current draw vs. flexibility. The circuit I just finished to 70% needs many logic gates and FFs (like you've already said). And these ICs have a current consumption of nearly 1mA when in idle mode. In comparison to a watchdog MCU with 1uA I see great potential in going with your solution. Commented Feb 20, 2018 at 19:02
• @Overblade You need to consider what toolchains you are already familiar with, then. I am fully set up for Microchip and TI and Atmel and ARM. But you may be set up for less. Of those, only Microchip (so far as I'm aware) offers a SOT-23-6 MCU -- the PIC10F2xx line. I'd probably go that way because they are small and cheap and once you've got these programmed up, you have a universally useful device that you may use elsewhere. And perhaps even sell to others.
– jonk
Commented Feb 20, 2018 at 21:43

Will this approach work? Or is there an even simpler solution?

Use a toggle switch rated for 2A and at least 5VDC.

There doesn't seem to be any compelling reason to make this electronic.

• I would do that, but the load's memory may get corrupted when the toggle switch is actuated. A push button with a timer is safer to prevent such accidents. Commented Feb 19, 2018 at 5:18
• I don't think the load will be able to tell the difference. Commented Feb 19, 2018 at 7:36
• It won't, but the user will if data gets corrupted. Commented Feb 19, 2018 at 12:15
• Why would switching the power using a toggle switch be more likely to cause data corruption than switching the power using a transistor? In both cases the power is cut suddenly with no warning to the load. Commented Feb 19, 2018 at 16:36

there should be no voltage drop bigger than 0.01V

This is a problem for any solid state switch. The only approach that would satisfy this requirement would be a relay - reed or otherwise.

The relay itself could be activated from a T (or D) flip-flop circuit. That way the pushbutton would be sufficient to turn on or off the current through the load.

simulate this circuit – Schematic created using CircuitLab

• If you look, I think you can get a 5mOhm PMOS. Commented Feb 18, 2018 at 23:29