Author Topic: Push button power circuit for Arduino... trying to modify it for 12V input  (Read 15567 times)

0 Members and 1 Guest are viewing this topic.

Offline doublec4Topic starter

  • Regular Contributor
  • *
  • Posts: 119
  • Country: ca
Thanks to both.

Zero999 I moved the cap as per your suggestion and success, that works  :)

Peabody, I basically did the same thing, I took the 2.2uF cap and moved it in parallel with the 1M resistor and it works flawlessly now as well.

 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19518
  • Country: gb
  • 0999
Yes, I should have set the simulator to start with the supply voltages at 0V, which would have shown this issue.
 
The following users thanked this post: doublec4

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2005
  • Country: us
I see that doublec4 (Chris) has put all these designs into a video, and posted a link to that in the Tutorials section of the Arduino Forum. Nice work, Chris.  Here's the video link:



He likes Ian.M's circuit best, and I do too.

I guess the next step is to integrate a battery charging circuit into this.  :-)

 

Offline doublec4Topic starter

  • Regular Contributor
  • *
  • Posts: 119
  • Country: ca
 :-+

Thanks! Couldn't have done it without you guys!
 

Offline chris.munc

  • Newbie
  • Posts: 1
  • Country: za
Oops I am trying to design for a 9 volt battery, as i said I'm a newbie. Will start looking for that on the forum.

Hi all, I’m a bit of a newbie here, dabbled a bit, but have always been keen to try microcontrollers.  Just bought myself an Arduino beginners kit, with the intention of building a simple ultrasonic distance comparator.  In my wanderings of the internet I came across the above video (many thanks doublec4), and also found that I liked, Ian.M's circuit, so much so that I have reproduced it in tinkercad.  I’m not sure if this hyperlink will work for you but here it is https://www.tinkercad.com/things/k5xWaD0dLv1-attiny-soft-latching-power-supply-, otherwise just search for “ATTiny Soft Latching”, in the circuits section.

Now for the real purpose of my visit, please could you chaps help me with alternative components.  Would an IRF9530 work for the p mosfet, a 2N7000 work for the n mosfet, and two 1N5818’s for the Schottky diodes (again apologies, I would like to do this project with a 9v battery not 12v).

Many thanks.

PS here is a screen shot of the tinkercad project

« Last Edit: July 24, 2019, 03:59:44 pm by chris.munc »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
As long as the Arduino (or other MCU) is running at 5V, your choice of MOSFETs will be O.K.   If you need to run at 3.3V, you'd need something with a lower max. gate threshold voltage than a 2N7000.

Small signal Silicon diodes (e.g. 1N4148) would be better than 1A Schottky diodes - the leakage current and junction capacitance of 1N5818 may be excessive.
« Last Edit: July 24, 2019, 07:33:14 pm by Ian.M »
 
The following users thanked this post: chris.munc

Offline MrFollies

  • Contributor
  • Posts: 10
  • Country: au
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #31 on: October 28, 2021, 01:47:54 am »
As long as the Arduino (or other MCU) is running at 5V, your choice of MOSFETs will be O.K.   If you need to run at 3.3V, you'd need something with a lower max. gate threshold voltage than a 2N7000.

Small signal Silicon diodes (e.g. 1N4148) would be better than 1A Schottky diodes - the leakage current and junction capacitance of 1N5818 may be excessive.

Hello Ian..

In your design (and the 9v idea above), what voltage is the GPIO seeing?
I'm keen to use this circuit for both rPi and esp32 MCUs both of which are happily powered by 5V but don't want anything higher than 3.3V on the inputs.
I can use a logic shifter I guess, but that might break the output design.

I'd like to understand how to convert your design to work with a 5V power supply but with 3.3V tolerant GPIO pins.
Is it possible?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #32 on: October 28, 2021, 03:08:39 am »
Due to the diodes, the GPIO pin can only be pulled low by the circuit, so it never 'sees' more than its normal logic '1' voltage no matter what the supply voltage is.  With appropriate choice of MOSFETs you can use the same circuit for any supply voltage from 3.3V up to about 15V.  Above 15V you'll almost certainly need a modified circuit to limit M1's Vgs to keep it well within its abs. max limits, just due to the limitations of having to find a P-MOSFET rated for >20V Vgs.   

The key parameter for low voltage operation is the MOSFETs threshold voltage - M1's needs to be well under  Vbatt/2 so it can deliver enough current when the gate is grounded  (i.e. when Vgs=-Vbatt, see datasheet curves to check it wont be edging into saturation), and M2's needs to be under half the logic '1' voltage.
« Last Edit: October 28, 2021, 03:13:59 am by Ian.M »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5903
  • Country: es
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #33 on: October 28, 2021, 08:26:45 am »
Just replace the 2n7002 with a small signal bjt and a 10K resistor to its base. 2n2222, bc547, c945... will work down to ~1V
« Last Edit: October 28, 2021, 08:29:53 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #34 on: October 28, 2021, 10:55:32 am »
Just replace the 2n7002 with a small signal bjt and a 10K resistor to its base. 2n2222, bc547, c945... will work down to ~1V

While true for most of the general power circuits with seperae GPIO pins for power control and button sensing, a BJT will specifically *NOT* work in my single GPIO pin circuit.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5903
  • Country: es
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #35 on: October 28, 2021, 01:59:24 pm »
No idea what you're talking about...
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #36 on: October 28, 2021, 03:54:17 pm »
No idea what you're talking about...

From reply #6 above

Its not possible to replace M2 with an ordinary BJT as per your circuit, as its base current will be significantly higher than that available through the GPIO weak pullup when its set as an input, which will pull down the GPIO, so it will no longer be possible to use the same GPIO to sense the switch state.
Buffering the GPIO so it doesn't get pulled down by the BJT base current is possible, (e.g. add a super-Beta emitter follower to drive the base resistor), but adds more complexity vs simply choosing an appropriate MOSFET. 
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5903
  • Country: es
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #37 on: October 28, 2021, 07:21:41 pm »
Circuit complexity? That circuit is already over-complicated.
So your gpio sets the internal weak pullup,  M2 will be turned on all the time, which will also turn M1 on.
When S1 is shorted,  M1 will keep turned on as long as the button is pressed, without any way to turn it off until it's released, which is a bit scary depending on what M1 is controlling.
After that, you read the gpio, if read low, you set the gpio as output, low level (or turn off the internal pullup), switching off M2, and opening M1 when S1 is released.
Now you'll never now when S1 is pushed again...?

Anyways, you can do the same thing much easier... Use a high gain npn bjt like BC547C, which is extremely common.
100K is the internal pullup, being the GPIO directly connected to the base.
There's a small difference: The switch instantly turns off the output.
If you want to keep M2 on while the switch is pressed, then add the diodes like in your circuit.
« Last Edit: October 28, 2021, 07:28:53 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2005
  • Country: us
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #38 on: October 28, 2021, 07:51:23 pm »
DavidAlfa, I don't think you were around for the original posts.  The idea was to have the pushbutton turn on the power, after which the processor would maintain it, and the button could then be used for general purpose input, but with a long press the processor would shut down the power.  And all of this would be done with a single GPIO pin.  I aways assumed the processor would wait until the button was released before doing anything so it could tell whether the press was long or short.  Anyway, I tried to develop a circuit using an NPN instead of an N-channel mosfet, but wasn't able to do it.  If you have such a circuit, I'd like to see it.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5903
  • Country: es
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #39 on: October 28, 2021, 08:45:32 pm »
I see problems in your circuit, but maybe it's me.
The only input voltage source is its own pullup, so you need to have it enabled all the time... thus the mosfet will be always on.

Yeah I seethe bjt problem....
You would need a second transistor, making an AND gate, so the pullup only turns on the output when there's power on it.
To turn off the output, turn off the pullup or set the pin as output, low level, for a short time.
« Last Edit: October 28, 2021, 10:15:47 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2005
  • Country: us
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #40 on: October 28, 2021, 10:19:37 pm »
Looking back at Ian's circuit, if the GPIO is configured as INPUT_PULLUP, that will be enough to turn on the N-channel and keep the power on. Then when you short the switch, that pulls the GPIO low via D1 which turns off the N-channel.  However, via D2 it also directly grounds the P-channel gate, which keeps the power on even though the N-channel is off.  C1 prevents any glitching as the P-channel gate is pulled low via the two different paths.  So it actually works quite well, and I don't see another way to have the same functionality with fewer parts.

While the internal pullup would probably be enough to turn on an NPN, the voltage at the base would be 0.6V or so, and I was not able to come up with a way to preserve the input function of the switch.  I think Ian's circuit is the best solution I've seen for this, but you can watch the OP's video covering it and four other alternatives and see what you think. 
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #41 on: October 28, 2021, 10:24:18 pm »
Yep, you don't read the input when M1 is off, as the MCU's supply is from downstream of M1!   :-// 

@Peabody: that's as good an explanation as any of my circuit. 

@all,
If you are more visually oriented, see 11:22-14:43 in doublec4 (Chris)'s video for an explanation of its function.

Chris's video, queued to my circuit: https://youtu.be/7D9L9oS4AJM?t=682

I can *think* of a few ways of doing something similar with BJTs, but they are all horribly complex.  :horse:
« Last Edit: October 28, 2021, 10:27:45 pm by Ian.M »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5903
  • Country: es
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #42 on: October 28, 2021, 10:36:33 pm »
Even more simple: Use self-latching. The MCU can turn off the mosfet at any moment by setting the gpio low.
No fancy electronics, very readily available and cheap parts.
Q2 will we switched on by the switch. The output will turn on Q1 and lock it up.

Together, D3+Q1 b-e junction have a drop of 1.2-1.4V, thus not affecting the gpio input.
When the gpio is turned low, there's only D1 in series with R4, so there'll be 0.7V, turning Q1 off and disabling Q2.

There's only a drawback: You'll have to ensure the output discharges BELOW 1.2v or it will latch again,
You could use an adittional fet to automatically discharge the output quickly(attached).

Edit: Oh I see it's a power-on circuit for the mcu itself, not for switching loads.
Then, likely you won't he discharging circuit. Just set the ouput low until it dies.
You might replace D3 with a 2.4V zener to increase the turn off voltage.
« Last Edit: October 29, 2021, 12:04:53 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline z555

  • Newbie
  • Posts: 1
  • Country: us
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #43 on: November 11, 2021, 09:14:55 pm »
There are some power management ICs out there which provide soft switch functionality at greatly reduced circuit complexity and footprint at the expense of well expense...

Checkout:
$1.80 per 100 Maxim Integrated's MAX16150
Quote
The MAX16150 is an extremely low-power, pushbutton, on/off controller with a switch debouncer and built-in latch. This device accepts a noisy input from a mechanical switch and produces a clean, latched output, as well as a one-shot interrupt output, in response to a switch closure exceeding the debounce period at PB_IN. A switch clo- sure longer than shutdown period at PB_IN results in a longer one-shot interrupt output. The MAX16150 family has two set of devices, one in which a longer switch closure greater than the shutdown period deasserts the latched output, and another in which the latched output stays asserted.



$4.39 per 100 Analog Devices' LTC2955
Quote
The LTC2955 is a micropower, pushbutton on/off controller that manages system power by generating a clean enable output from the supply monitor input and the debounced pushbutton input. It features an interrupt output that notifies the system of a pushbutton or low supply event. When the system is ready, it may use the power kill input to shut off power. If the pushbutton remains pressed for more than the configurable turn-off duration, the system power is forced off.
« Last Edit: November 11, 2021, 09:20:56 pm by z555 »
 

Offline CBF

  • Newbie
  • Posts: 6
  • Country: au
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #44 on: November 19, 2021, 10:16:06 am »
I cannot get this circuit to work. It turns on correctly but when the arduino sets the output low to turn off the input floats to high. I cannot think of a solution and believe the problem is because the arduino is tri-state or my mosfet? Datasheet and my schematic:
https://www.farnell.com/datasheets/2303831.pdf
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #45 on: November 19, 2021, 12:03:43 pm »
The Arduino output may not hold its state during loss of Vcc.  If it glitches high it will re-trigger. If you've got a decent scope, look for glitches on the out pin.

If you find a glitch, try splitting the 4K7 resistor into two 2K2 ones with a cap to ground in between to make a low pass filter, with a time constant an couple of orders of magnitude longer than the glitch so it has negligible effect.
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2005
  • Country: us
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #46 on: November 19, 2021, 07:03:58 pm »
I cannot get this circuit to work. It turns on correctly but when the arduino sets the output low to turn off the input floats to high. I cannot think of a solution and believe the problem is because the arduino is tri-state or my mosfet?

If you mean the GPIO pin labeled INPUT in your schematic, that should always be high unless you are pushing the button.  There's nothing pulling INPUT down.  But if you mean the power doesn't shut down, then that shouldn't be happening.  Are you keeping the output pin low for a while?  Remember that you have to recharge the gate capacitor through that 1M resistor before the mosfet will turn off.  After bringing the output low, try adding a 10 second Delay afterwards.  If that still doesn't work, instead of taking the output low, try changing it to INPUT mode, still with the Delay.



« Last Edit: November 20, 2021, 04:09:21 am by Peabody »
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21677
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #47 on: November 19, 2021, 07:29:54 pm »
Just to belatedly add my own to this old thread --

I did this, with the additional constraint that it run from 24V, with low leakage.



The 24VEN goes to an LDO enable, which powers the MCU's converter (24-3.3V buck) and other hardware (12V for SMPS controllers).  This circuit draws essentially MOS leakage current until enabled, and the load's minimum current draw is still many times the bias drawn by this when on, so it's no matter at all.  It also monitors RS-232, so that serial commands can wake up the MCU directly.  Filtering not shown; ESD protection is shown.

Oh, the serial wake-up part is a bit ambiguous, isn't it... the input NMOS is wired-OR with the latching NMOS I believe?  So the right half of that is duplicating the respective part of the right hand side.  Yeah I don't have this thing in front of me right this instant to confirm, tsk tsk.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2005
  • Country: us
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #48 on: November 20, 2021, 04:18:50 am »
Just looked at the schematic again, and I think the 2.2uF gate capacitor shown in red is way too big.  Its only purpose is to prevent the circuit from powering up when power is first connected.  But for that I think .01uF or even smaller would be enough.  Try removing that cap, and then see if the circuit powers down properly.  And the 1M resistor may be too high if there's any leakage through the NPN.  Try 220K or even 100K and see if that makes a difference.  I think the circuit is sound, and should work, but you need to experiment a bit with different values.
 

Offline CBF

  • Newbie
  • Posts: 6
  • Country: au
Re: Push button power circuit for Arduino... trying to modify it for 12V input
« Reply #49 on: November 21, 2021, 05:14:13 am »
I tried adjusting the gate cap values and the resistor with no luck. I successfully with a different circuit. I think a low pass filter on the base of the transistor may have worked as the output did spike to negative momentarily, as Ian P suggested. Thanks anyway.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf