This started off as a simple discussion on UPS for the likes of the Raspberry Pi and other micro boards but developed into so much more. Some great conversation, some ideas – and a project at the end which could fit a lot of requirements at very low cost. Read on...
What you see above is just the basics – in reality you NEED a processor to make this work well – a simple £1.20 Atmega 328-based board will do – and I’ve done that, added a display and written the software… but let’s go back a little first…
The Early Days
So the basic idea is simple enough – each of these boards is DIRT cheap… the MT3608 boosters are able to output 2 amps. the smaller charging board however is only able to output a little over 0.5 amps – useless for powering, say a Pi3. So – the little board at the bottom charges the battery as long as there is incoming 5v. Similarly as long as there is incoming power, the top booster powers the Pi…. it’s output being 5.8 roughly, dropped by a diode. The middle board, powered by the battery, has a SLIGHTLY lower output voltage and so thanks to the diode arrangement does nothing.
Oh, as has been pointed out elsewhere – don’t take that 4200maH figure above too literally – Chinese artistic licence. Indeed, don’t buy that battery…
If the power fails, the top board outputs nothing – and so the middle board takes over.
Here’s the thing, if the battery gets well down and the power comes back up, the top board takes over powering the load, the middle board does nothing and so the bottom board can concentrate on charging the battery as quickly as possible.
If you have an old laptop battery, the total cost of this up to now is around £3 or so. Next, stick the smallest cheapest Arduino-clone on, in a final version controlling the outputs of those MT3608 boards (they have an enable pin on the chip) and using the analog input to measure battery voltage, ensuring the PI (or whatever) is given the opportunity to shut down when the battery is low – and also (new thought having read what Tesla has done) limiting the battery charge to below full – limiting to 85% apparently does WONDERS for the battery life. I have also made a prototype below using a cheap combined charge/boost board and a MOSFET to turn the output on and off while giving me 5v for the Arduino type board. Works a treat.
And yes I’ve seen lots of boards out there that do all this, yes they’re expensive – as the cheap ones by and large fail to provide UPS somewhere along the line – usually during recovery from a flat battery. so – I thought, why not DIY… I just happen to have a pal who’s a whiz at PCBs.
The argument for Two Boosters
Of course part of the reason for using TWO of these boosters is the inadequacy of the charging circuits based on the common TP4056 – but thanks to Antonio pointing me to a link to a Chinese lady paralleling them up – I then went off on a search and found these… a cheap 3 amp circuit (the only worry is it says in the ad that it is a 4056 circuit but I’m not seeing a 4056) and a slightly more expensive multi-4056 circuit. With this one only then needs a single booster circuit which does not then need outgoing diodes. The multi-4056 circuit seems to be simple enough – all grounds common – all inputs common, all outputs/battery+ commoned. 3 amps output would typically allow for running, say. a PI and providing a reasonable amount of charge to the battery at the same time.
Thanks to this video - https://www.youtube.com/watch?v=uJmQ9W3Yqc8 we have a circuit for multiple 4056 in parallel – which is another option for experimenters.
Looking at the spec of the chip it should be able to handle 800ma without breaking a sweat – so 4 of them would give 3.2 amps. I personally would not use those light outputs – I’d take them to the NANO (with internal pull-ups, bearing in mind the LED outputs are open collector). That would then give the NANO additional information.
According to THIS spec sheet – pin 8 on the TP4056 is an enable pin, normally high. They could be paralleled up and taken to the NANO – which already could control the output (via the enable pin on the MT3608) – ensuring the battery is never too discharged – but now the enable on the 4056 along with the analog input on the NANO could ensure that the battery is never fully charged – and that of course increases battery life. I2c (2 pullup resistors) would allow for programming things like maximum charge voltage, minimum discharge voltage and more – and remaining Nano pins could if needed be used as status LEDs.
This item turned up for me - https://goo.gl/Zo2Cdt
For £1.20 this claims to be a charging module with boost step out of 5v, 9v etc etc… adjustable.
So first things first – this unit really is as small as it looks. On applying power it has 2 dim lights – one green, one red. On applying a load, the green light goes out - the red light comes on full. Input can be 4-8 volts – I fed in 5v USB – so just under 5v. At this point no battery is involved. Just for the sake of it I set the output to 5.1v and applied the output to a Pi2. Well, that’s out – the voltage dropped to 4.6v. However I put an ESP8266 on there and there was no perceptible voltage drop.
Incidentally for the sake of it I checked the unconnected output and it would go as high as 26v so you might find some completely unrelated use for this – like higher voltage fairy light control etc.
The claim is that you can charge at up to 1 amp and discharge at up to 2 amps. I’m making no such claims but “works for me on a Pi2”.
To test further I stuck a 4.2v Lithium battery on the “Battery” side – with no load and no power, no lights came on – a good thing – on test the power out was 5.1v as you might expect. I wired up a Pi2 and this time the output voltage stayed rock steady – my first test of course was a little unreal because the unit is meant to work with a battery. Still no lights. I plugged in USB and the red light on the board came on cleanly. The battery almost immediately jumped to 3.8+volts. I disconnected and reconnected the USB power several times with no discernable effect on the Pi.
Without power, I watched the battery voltage go down to 3.6v – still 5.1 on the Pi – I must stress at this point, this was a Pi without an SD in it - I was not about to screw up an SD for experiments. The buck convertor on the board was running cold, a good start. At 3.13v the output was still 5.1v, no noticeable drop.
Now bear in mind this is not a solution for UPS – there is no circuitry here for warning the Pi of impending doom without a controller (see below), but I’m wondering as a protection against power glitches and short term outages – well you can’t argue with £1.20 – you could fit this inside many cases!! Actually I could think of a number of uses for this – only got a 12v fan handy? Not problem? Want to drop the supply to the 5v fan to make it a little quieter? No problem… the list goes on.
Some good thought has gone into this board, predominantly single-sided, the bottom track layer is almost all ground and the designer has put PTH holes under both chips to get some heat transfer going – which may account for it running cool up to now.
This circuit of course suffers from the charge circuit going to the battery and the battery going to the booster… this means that when the battery is flat – and power is re-applied, the charger circuit will not only have to charge the battery but also run the load… time will tell how well that works.
I decided to leave this attached to the SD-free Pi for a while for the battery to die. More on this later…. already this is better than some of the attempts I’ve seen so far some of which can’t even handle pulling the power lead out! It kind of makes up for some of the little boards I’ve bought recently which have been so bad they just ended up in the bin!
2.8v and still the output was rock-solid at 5.1v…. in reality I think I’d be wanting the power output to turn off well above this point. 1.8v and STILL a solid 5.1v out… this was starting to look unusually good – and at this point the output stopped. Not completely I may add – it’s voltage dropped to 1.8v while the battery went back to 2v. Nice behaviour so far. Now to reconnect the power. I should say you’re not supposed to take Lithium batteries that low – I was just learning.
I plugged in the power and the Pi came on – however a measure of the battery voltage indicated that the charge chip could not keep up – the voltage of the battery started to go back down to under 2v.
The Pi remained active but I imagine only just – and eventually stopped again, only to start up moments later – I imagine this situation would have continued forever. This would have worked a treat with something like an ESP8266 board as it’s average current would be much lower but with the Pi, this would not work out in practice… so - as elsewhere to make this work what would be needed is the ability to turn the output off until the battery sufficiently recovered.
I disconnected the load and let the battery charge. it took no more than a few minutes for the battery to get enough charge that the circuit could run the Pi and slowly top up the battery at the same time.
The answer here would be turn the output off at say, 3.1v and not allow it to go back on until the battery was at say, 3.6v. And that, pretty much is what I’ve done (don’t get hung up on those figures – they’re programmable).
The CHIP is marked B6287Y – a kind reader has pointed out that this is in fact the MT3608 - so that looks like a good choice of chip.
HOWEVER in the process of all of this I spotted a flaw in my initial thinking - and I'll bet others have been caught out with this.
So we add a NANO or similar to control this - the power gets down to, say 3.2v and we issue a warning for the PI to turn off. The voltage gets down to, say 3.1v and we turn off the output. Now the battery will of course recover instantly but falsely - so we don't turn the power back on until the battery gets back to 3v6. That all SOUNDS good - and there are those who use a GPIO to do just this. But..
BUT… what happens if the warning comes on - and shortly thereafter BEFORE the cut-off voltage is reached, the power comes back on ???? We've already set the Pi on a course to reset!!! Solution, continue on as if we HAD reached the cut off point and modify the idea from there. When the battery voltage reaches 3.6 (in the example below) turn it off for 10 seconds then back on. If the output was OFF - no harm done but a few seconds wasted - if it never GOT turned off then this power cycles the Pi to let it turn on normally. I wonder how many designs fail at this point.
Right now I’m sitting in front of that combined board – I have the Nano board running off the 5v output – which begs the question – how do I turn the output off for reset and shutdown? Well, easy – a P-channel MOSFET. That is running – I’ve covered the case where the shutdown signal is set but the power then comes back on (simply proceed with the shutdown – and then start again.
While I think on – just an aside– everything I’m doing here uses one battery which makes like easy – one could use 2 or 3 in parallel – but when it comes to using the batteries in SERIES life gets a little more complicated. Banggood just sent me some 3S 20A 18650 protection boards – in which you can connect up to 3 batteries in series and it will protect them individually – which is handy for people like me who are terrified of Lithium batteries.
Entitled 3S 20A Li-ion Lithium Battery 18650 Charger PCB BMS Protection Board 12.6V Cell these boards are dirt cheap but claim to be able to handle 20 amps load. With 3 cells, the charging voltage is 12.6v – output power claim is 20 amps but how quickly you can charge them is a little vague, I’m not sure I’d want to try charging at 20 amps Important to stress this is just a protection board – the comments on their site include links to voltage and current limiters. The little chips they use are DW01KA and here’s a link to more info.
The Dog's Breakfast
Well, i spent much of the past weekend on this UPS subject – aside from answering umpteen blog questions – and taking the grandkids to the lake!
Just to show what can be done for VERY little cost… I’ve done the software , I’ve had the breadboard out and I’m very pleased with the result - which really is only the beginning...
This is what is referred to in the trade as “a dog’s breakfast”. Above was my first attempt It is NO-WHERE NEAR as complicated as it looks thanks to all those wires.
This one is an utter bodge and I managed to achieve voltage drops in a single wire of well over 0.2v…… however, ugly and sinful as it looked – the bottom half of this was a working UPS in the true sense of the word.
See that green wire to the right of the lower board? Pretend that is three buttons called UP, DOWN and SET (you’re going to have to use your imagination here. See that Arduino-type board on the right? Pretend that doesn’t have a USB chip and LED. And that 800maH Lithium battery, well, that’s the only battery holder I had at the time. Think of it as a 18650 – and finally think of all of those wires as being on a PCB, thicker and shorter. Oh and forget the two LEDs on the breadboard – they were there for testing.
Oh and it should be about maybe 25% of that size.
Now that you have a true mental image of this… you know, sometimes it is easier to stick a camera in front of me…
Here’s a video – I finished my first prototype over the weekend and well, I got carried away with the software – take a look... https://youtu.be/44Lvdf7o4GQ
The Dog's Breakfast 2
Then came the tidied up breadboard. It actually worked – and worked well – it had most of the things I wish other designs had and yet remained cheap – which is a bonus… got the little things (even getting the warning GPIO signal the right way around is important – I originally had that HIGH when on standby until I noticed it was actually trying to power the PI as the little green light on the Pi was JUST glowing!!!)
The display in this pic has now been replaced with a 32px version and the software improvements just keep coming.
and at the Pi end….. of course there are many scripts to respond to a port bit and turn the Pi (or other device – I keep saying Pi just for ease)… or better yet in my case – as always Node-Red comes to the rescue – 2 minutes works and…. it sends an email before turning off. That of course is just icing on the cake. Or you could trigger an alarm somewhere via MQTT…. or….
And now – well, last night I headed off to my friend Aidan’s to get three buttons fitted (and disconnected that wasteful RED LED). This morning I got up early to finish the software and update BitBucket.
The Kitchen Sink
As this is starting to grow, I’ve separated later efforts into their own blog entry called “The Kitchen Sink”.