Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Electronic projects that are either related to the firmwares for the 9x, or simply great for radio control applications.
Post Reply
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by jhsa »

Note: I have a question. It is posted at the bottom of this post. If you can answer it, it is highly appreciated. Thanks. ;)

I have been working on a wireless In Ear Monitor system for when I play music, and I wanted to have a single power button operation, as well as a battery monitor circuit with auto shutdown because I decided to use a 2 cell LiPo battery to power it all. This is achieved by using an ATtiny85 (or ATtiny45) microcontroller.

Another requirement was that the circuit takes 0.000 mA from the battery when it is turned OFF ;)

I am posting this here because I think it could also be used on many DIY projects, including RC projects.
The operation is very simple. Press the button once to turn the circuit ON, and press the same button again to turn it OFF.
The ATtiny was programmed to turn all LEDs (Red, Yellow, Green) ON above 7.6V, then between 7.2 and 7.6, only the Red and Yellow will be ON, Under 7.2V, only the Red is ON, under 7.0V, it starts blinking, and at 6.8V the microcontroller turns everything OFF, including itself. Of course these voltage thresholds could be changed in the code to match other cell number or another type of battery.

The first picture shows the Schematic with the original switching circuit that I found on the internet.
On this circuit I needed to Add a Diode on the output because capacitors in parallel to the output would prevent the circuit from turning OFF. It also needs some load in order to turn OFF. So I added R5 (10K).
I have noticed also that with voltages above 8.0V, even with load, sometimes it was very difficult to turn it OFF. In occasions I had to disconnect the battery. To solve that problem I added R13 (150K) to the base of T1. Like this it works very well, at least with a 2 cell LiPo Battery. With more cells it might be that we must change its value, but I didn't test it, and you will understand why below.
Battery Cuttof With ATtiny85_Schematic.png
On the second picture, I have made some changes, based on experimenting.
Actually, I have some questions that I would like to have answered. More about this in a while.

Moving the capacitor C1 from the the Positive, and connecting it between the Button and the base of T1 things improved a lot. The circuit seems more stable and switches well up to 10V. Didn't test at higher voltages, but I believe it should work.
I could remove R5 and R3 and it still works as it should. I could probably even remove the diode D1 as I placed a 100uF capacitor at the output (before the diode) and the circuit still turned OFF without problems. With the capacitor connected to the circuit shown in the first picture, a 10uF capacitor before the diode would prevent the circuit from turning OFF. So, this was a good improvement. :)
Battery Cuttof With ATtiny85_V2_Schematic.png

If you don't need battery monitoring, you can just use the switching part of the circuit, ignoring all the lower part of the circuit, including T2 and R6.
This was so far the easiest circuit I found, using just 2 transistors. The original used a N channel Mosfet and a PNP trasnsistor, but I wanted to switch the positive so I've just changed the transistors and the polarity.
For T1, any NPN general use transistor should work. Something like BC546, BC547, BC549, etc.. I used an SMD BC846.
Q1 should meet the requirements of the voltage and load you want to switch.
I used an AO3407 Mosfet, that can handle 4A according to the Datasheet. I wouldn't use it for more than 1A or 1.5A :)
If using low voltage, you might need a logic level Mosfet to make sure that it turns completely ON. That means that it has to have a low Vgs (Gate/Source voltage). The Mosfet I used (Datasheet attached below) needs a voltage of at least -3V to fully turn ON at 4A. So if you are thinking about using this circuit with a single cell Lithium battery, and need to switch some higher load, I suggest searching for a suitable Mosfet Transistor ;)

The code for the ATtiny is also attached below. I assume you know how to use the Arduino IDE to compile and flash the code. Or at least connect a programmer and flash the compiled .HEX file included in the zip file. It was compiled for the ATtiny85 microcontroller..
Here is a diagram explaining how to connect the programmer to the ATtiny85.
For the circuit to work you might have to cilck on "Burn Bootloader" on the Arduino IDE so the right fuses are programmed to the chip.
You need to select the ATiny85 chip, and 8Mhz internal clock.
But before all this you will have to install the ATtiny libraries on the IDE.
attiny-programming-schematics.jpg
Now the question I have. I would really appreciate if someone could answer it.
I do understand how the circuit turns ON with the first button press.
The base from T1 becomes positive via R2, R3 and R4 when we press the button.
Once it turns ON it will connect the Gate of Q1 to Ground turning it ON as well. Then, after releasing the button, R4 will keep feeding the base of T1 keeping the circuit ON.
What I don't understand is why the circuit turns OFF when we press the button again :( I am missing how the capacitor makes that happen.. :(
Is it because when the capacitor is charged it acts like a short circuit, and when we press the button again it shorts the base of T1 to ground? Then the base becomes negative and T1 turns OFF??

I do mess with electronics and all I know I have learnt by myself,with the help of other people, and the internet..
Thanks in advance if you can answer my question ;) :) If you do, many of us will have learnt something.. :D

Thank you

João
Attachments
Batt_Cuttof.zip
(3.21 KiB) Downloaded 268 times
AO3407A-Alpha-&-Omega-Semiconductor.pdf
(109.82 KiB) Downloaded 260 times
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by MikeB »

When the circuit is ON, the "top" of the capacitor is at the battery voltage (via R3, 100K) and the "bottom" of the capacitor is at the base voltage of T1.
When you press the switch, the "top" of the capacitor is pulled down to the collector voltage of T1 (probably around 0.5V), so the "bottom" of the capacitor is driven to a negative voltage, turning T1 off and so the power goes off. I would expect that if you hold the switch pressed long enough it will all switch back on again.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by jhsa »

Thanks Mike.. Well, it does.. :) But I had to keep it pressed for about 3 seconds.. Any way of preventing that happening?
I mean, the way it works now is fine for its purpose..

What about the first schematic? it seems to work a bit differently..
But the second does seem to handle the switching a bit better..

Thank you
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by jhsa »

MikeB wrote: Mon Aug 28, 2017 5:12 pm I would expect that if you hold the switch pressed long enough it will all switch back on again.

Mike.
Mike, I paralleled another 10K resistor to R2 and the circuit didn't turn ON anymore after turning OFF, when keep pressing the button.
Do you think this is a good solution?

Thanks

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by MikeB »

I'm not sure why that has the requred effect, and it may depend on the exact battery voltage whether it works or not.
When you switch it off, does the next press very soon after turn it on again or do you need to wait a bit?

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by jhsa »

It happens as you say.. The lower the voltage, the longer I have to wait.
about 1.5 or 2 seconds at 3.3V, about a second at 5V, need to do it quick at 7V and up, but if I keep the button pressed, the circuit turns ON. But I can see that is progressive.
Thanks
João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
Kilrah
Posts: 11108
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by Kilrah »

Since there's a microcontroller there I'd use the usual soft power circuit and have it do the logic for when to keep power or not...
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by jhsa »

The microcontroller already does the logic for when turning the power OFF, when the battery gets under a certain voltage, and gives me an indication of the battery state.

I could, but I don't want to, use the microcontroller to turn the circuit ON and OFF for a couple reasons..
First, I needed it to be small hence an ATtiny85 and I'm using all its pins.
Second, even using the right voltage regulators for low quiescent current, it wouldn't be a 0.00uA current draw as with the circuit shown here.
I have a couple projects, like for example the magnetic RC Power switch that uses the principle you describing. Switch state, micro go to sleep again.. We are still talking about some 12 micro amps, but still, not 0 micro amps :)

It could be an option, but I would need a micro with more pins :)

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
Kilrah
Posts: 11108
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by Kilrah »

jhsa wrote: Tue Aug 29, 2017 9:26 pm First, I needed it to be small hence an ATtiny85 and I'm using all its pins.
Doesn't help. You can probably save at least one though, which would be enough to sense switch position :)
jhsa wrote: Tue Aug 29, 2017 9:26 pm Second, even using the right voltage regulators for low quiescent current, it wouldn't be a 0.00uA current draw
It sure can by cutting its own power completely (holds Q1 on when on, and when it's time to power off releases it resulting in the exact same thing as now).
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by jhsa »

Kilrah wrote: Tue Aug 29, 2017 9:35 pm
Doesn't help. You can probably save at least one though, which would be enough to sense switch position :)
The only way I could use another pin would be using the reset pin, which I obviously don't want.. I need all the other pins as you can see on the schematic.. Other people might have another needs :) The code is simple and it can be changed :)
It sure can by cutting its own power completely.
Yes, I have been also looking into it, but then you need a 2 button operation.. I want a single button operation.
If you know of a circuit that uses a single button connected to a microcontroller to turn itself ON and OFF and drawing 0.0uA, I would appreciate it.. I have been working on it and didn't find a way of doing it.

as I said, I can do it, but it is not a 0.0uA circuit when turned OFF.. I know the current it draws is probably less than the battery's self discharge ;) but still....

I gotta say, I do like the 3 second delay I have on my magnetic RC switch that this circuit doesn't allow. But for turning most projects (and not just RC) on and off, this is enough..
Anyway, thanks for your input and advice..

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
Kilrah
Posts: 11108
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by Kilrah »

jhsa wrote: Tue Aug 29, 2017 9:50 pm I need all the other pins as you can see on the schematic..
You can easily drive 2 LEDs form a single pin.
jhsa wrote: Tue Aug 29, 2017 9:50 pm Yes, I have been also looking into it, but then you need a 2 button operation.. I want a single button operation.
That's what all the radios with a push power button do...

Basically the same schematic as now but removing the timing stuff, and wiring the button to the microcontroller so it can know when you press the button for turn off.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by jhsa »

Still, not a 0.00uA power solution :)
And I want a single button operation. I initially tried the microcontroller solution, but can't find a way of doing it for 0.00 operation. :)

What do you mean by timing stuff?
João

Sent from my thor using Tapatalk


My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by jhsa »

Kilrah wrote: Wed Aug 30, 2017 7:00 am
You can easily drive 2 LEDs form a single pin.
Not in my current application. I need both LEDs to be ON at the same time.. Actually, when the battery is full, all 3 LEDs are ON. So, having 2 on the same pin does not work.
Even is one LED was ON at the time, this wouldn't work. because one of those LEDs would be always ON depending if the pin was high or low. When the 3rd LED is ON, then I couldn't have the other two OFF, or am I missing something? ;)

For applications where there are only 2 LEDs, and only one is ON at the time, that is an excellent idea though, specially on an ATtiny85.. :)

Thanks
João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
Kilrah
Posts: 11108
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by Kilrah »

You turn both leds off by setting the pin as an input, and to have both on "simultaneously" you just toggle high/low rapidly.

I'm giving you ideas, as always the web is full of info to look deeper, for example first Google result for "2 leds 1 pin": http://www.batsocks.co.uk/readme/p_tut_led16.htm

Instead of taking the hint you straight say "no it doesn't work", so no point me bothering further.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by jhsa »

Thanks, I will, although the circuits above are good enough for my project. That information will be very useful for future projects or for others..
I found another circuit that I will breadboard. It also looks good, and it needs a long press to turn OFF. I would like to change it to a long press to turn ON instead.. :)

http://www.mosaic-industries.com/embedd ... tery-power

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by jhsa »

Kilrah wrote: Wed Aug 30, 2017 8:57 am
Instead of taking the hint you straight say "no it doesn't work", so no point me bothering further.
I thought it didn't work, so I said it didn't work.. Obviously it does, my mistake, and I do apologize for that..
All ideas are welcome as I already said and I thank you for that.. It is your choice to bother giving them or not ;) :)
As you say, the internet is full of resources, and that is what I have been doing.. I am just sharing what I did, whether is correct at other people's eyes or not.. It works well for my application.
I also keep saying that I want / need 0.00uA operation, and as far as I understand a microcontroller can't do it alone without taking a few microamps. The micro can be put a sleep when OFF and takes probably less than 1uA. The problem is that all low quiescent current voltage regulators that I FOUND were quite expensive, or the current was a bit too high for my taste.
And if I found a way of doing my magnetic switch without a micro, I would do it as well. The problem is that I need to hold the switch (or magnetic sensor) for 3 seconds before it turns the circuit ON and OFF.
And this I could only do with a microcontroller, until now..
Sometimes I prefer real electronic circuits to micros.. :)
Thank you again

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Single Button ON/OFF switch W/ Battery Monitor and Auto Shuttdown

Post by jhsa »

Good article the one you've posted..
Thanks

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

Post Reply

Return to “General RC Electronic Projects and Discussion”