The Dogs Breakfast

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...

Part diagram for ups

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.

The Catch

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.

Much Cheapness

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.

tmp874F

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.

A Revelation

This item turned up for me  - https://goo.gl/Zo2Cdt

Charger and buck convertor

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”.

Testing

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.

A Winner

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.

tmp705EA Quick Aside

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 Smile 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...

Dog's breakfast

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.

tmpA8EB

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!!!)

Dog's breakfast 2

The display in this pic has now been replaced with a 32px version and the software improvements just keep coming.

tmp8FBA

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….

tmp1C3E

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”.

Facebooktwittergoogle_pluspinterestlinkedin

88 thoughts on “The Dogs Breakfast

  1. You can get almost 1A charge current out of that little board on the bottom if you change the setting resistor. It's a TP4056 chip for charging and a DW01-G on the right for battery protection if you want to fiddle with it.

    Why bother with 2 boost converters? wouldn't it be enough to connect the main supply straight to the Pi and then have diode protection (just like in your drawing) for the battery part? Aka skip 1 boost converter. That's how they do it on the Adafruit boards usually, albeit on a smaller scale.
    If you have 3A on the supply that should be enough to charge at full strength and power the Pi at the same time.

    1. Thanks for that - as it happens - the higher charge isn't needed the way I do it but I guess it would do no harm to upgrade the board - out with the tiny soldering iron.

      As for the second booster... main supply straight to the PI - well because you'd need diode protection for both the battery part and the mains part - some power supplies will handle voltage going back into them when turned off - others will blow up... so - you put diode in series - but now your 5v on your mains supply is down to 4.6 with an expensive diode, 4.3 with a cheap one - neither is a good idea. NOW - if your power supply was around 5.8 - then yes - but that THEN leaves the question - how will the TP4056 respond to having 5.8 shoved into it - especially at the higher current you suggest.

      I know - "GOOGLE IT" - but if you know the answers from experience - do tell before I get the iron out.

      1. To answer your own question - the TP4056 can handle up to 8 volts... but of course - not all power supplies can be altered... so the dual booster approach still has merits - expecially as they are so cheap.

  2. Like your approach here. What happens if the power is out for a LONG time? Any protection from over discharging the battery? If you have a nano in play then you could monitor the falling battery voltage and then disconnect the battery (mosfet) at some low (2.5v?) voltage. Hopefully the Pi has shut down before this point (warned by the nano at (2.7v?). Just some thoughts here but do go for it. I think this is will work.

    1. Absolutely John - a NANO would not only indicate to the PI to turn off before the battery gets low (the Nano takes so little current I'm not concerned about it flattening the battery much) and using the ENABLE pin(s) on the buck convertor(s).. but also could potentially stop charge on the battery reaching 100% which has to be a good thing... oh and you could do all sorts of logging, I2c slave interface etc etc....

        1. Good idea but too simple... let's say the battery goes down - Pi is told to turn off by the comparator... now we're using less current the battery voltage comes u, Pi never comes up. What's needed as the battery goes down is to firstly warn the Pi, then after a delay, turn the power off. The power should then not come back on until the battery has recovered slightly otherwise you end up in a loop of off/on.... so you need hysteresis. By the time you are finished you have a complete circuit, may as well have used a Nano. Also with processing power you get options like being able to change setting, view status on an OLED etc. Looking at designs out there, many have tried the minimal route and ended up with something that just does not do the job.I'd like to see at least 10 minutes pass between a low battery and the unit coming back on - when you get power failures, it is not unusual to get a raft of them in a row so best keep the Pi off until it is all over.

            1. Not at all - those booster chips have an ENABLE pin - not that easy to get to on the boards but if you did your own thing it would be no issue - normally enabled - take high and the output shuts off. I've not yet investigated the charger chips to see if they have the same.

  3. If I were to consider this type of solution, then I'd include some device with intelligence that would control the various elements and make appropriate measurements. At least for prototyping that would let you make all sorts of changes without the soldering iron.

    However, I don't relly understand the use part of the requirement. If you have access to mains or even ethernet, then remote power is surely the way to go. That way you can have a real UPS and distribute reliable power via ethernet or a low voltage cable?

    1. A Nano will provide the intelligence.

      You are assuming that in a given situation, with existing equipment that power over Ethernet is practical - not always. Low voltage cable - are you married? Cables around the house?

      1. I accept your comments but for 'you' I don't believe we're talking one device and there are lots of cheap poe solutions using the spare pairs and not following the standards. Then perhaps no extra wires. Also it is a bit of a leap to have a fairly critical device (i.e.needing ups) which doesn't require a reliable network connection? Finally, I don't beieve the time is too far away when lighting is powered from UPS as its power needs are now quite moderate and that would offer UPS at many more locations?

        1. Hi Richard..

          We're talking in my case, a small number of devices in each of 3 remote locations. For me, yes, I could use POE but I would not want to get into discussing to a mixed skill audience, add-on POE given the variety of wiring arrangements out there - but yes, for some, POE might be a solution - assuming of course hardwired Ethernet - not a lot of use in a wireless situation and while the technical person may well scoff WIFI - most normal people do not want wires all over and will use WIFI or radio even where not really appropriate. Sensors around the house are often wireless completely - I have visions of people spending more time changing batteries than enjoying the home 🙂

          Lighting - there is a general trend to think that lighting is becoming lower and lower power. That is not my experience. Sure, it is low power compared to filaments - but compared to Compact Fluorescent? - I don't think there is anything in it - You can of course get 3w LED bulbs - and they're about as much use as a candle. I've just retrofitted some lighting in Spain as I'd gone LED and was having a clear-out of 64k (horrible cold white) lights and noted that the warmer lighting tended also to be a little dimmer. Most of my lighting now is mains powered and most of the lamps are 15-25w LED. As for LED string - the current consumption of that rapidly rises as you get more enthusiastic.

          We are of course talking two completely different things here - a UPS for a PI should be able to handle any length of outage - no matter how big the batteries, they will run out of steam eventually and the UPS needs to inform the Pi (or whatever) that the power is about to drop.

          A lot of the tiny UPS out there that I've tested simply don't make the grade, some need a button press to come back on, some can't handle the full load while charging, some don't issue any warning etc. But even the bigger ones - I've had industrial UPS systems that given a long term (24 hours) power-out have driven the battery so low that it has never recovered. I've had units which cost a lot and yet in those same units I've seen batteries expand due to excessive charge or discharge. NONE of this should be happening in any of these devices... hence I keep looking to see what's out there and continue to experiment - as in this article.

          I have some commercial units on the way for testing so expect more on this subject.

  4. Hi,
    I've built my own UPS for my RPi and OPi + HDD using this SMPS:
    http://s.aliexpress.com/AjY3QJr2
    You can hook up a lead acid battery to it and it works right away. There is no delay between changing from mains to battery power, my PIs keep running as nothing has happend.
    It has 3 indicator leds which you can use paired with an optoisollator ic to monitor everything.
    And 6/8/10 Amps of output power should be perfectly fine.

    Greetings from Germany
    Joshua

    1. It LOOKS good - but one phrase in there worries me a little "Which power to the battery charge, no requirements for the type of battery, lead, lithium and other batteries are OK!" - REALLY? So no special treatment for Lithium batteries? I think I'd want someone else to try that first... What voltage lead-acid did you use? And in the case of long-term power outage, does it give any kind of indication that the PI can use to gracefully power down - or does it just abruptly shut off the power when the battery gets to 10v?

      1. i think they copied the design from this Drok one (as happens A LOT with Drok products...): https://www.amazon.co.uk/110V-240V-Uninterruptible-Over-discharge-Protection-Cmopatible/dp/B01K9SM78K/

        there's even this which is nice...
        https://www.amazon.co.uk/Power-Inspired-Router-Uninterruptible-Supply/dp/B0187PWCLO/

        but honestly, if one has to go for the UPS way (and it's viable, as a basic UPS can be bought for less than 40$), i'd do as in this video, bypassing the inverter... https://www.youtube.com/watch?v=-Ur-D37-juo

      2. Of course you shouldn't consider putting LiPo / LiFe / Liion batteries on this supply. It is designed for lead acid batteries, as you can see on the plugs which are commonly used on lead batteries. I think it is a marketing trick or the seller has low electronic knowledge.
        I bought a 12v 2.2Ah battery from a german reseller (reichelt).
        The datasheet suggests between 13V-15V roughly to charge and 13.8V as float-charge voltage.
        Due to their design lead acid batteries are nearly unbreakable, so overcharging is no issue.

        The PSU has a small trim pot next to the screw terminals which lets you select the output voltage.

        I've set it to 13.9v and it is working just fine. The battery is float-charging.

        If mains fails it starts discharging until it reaches 10.9 Volts. After this it needs to be reconnected to mains or you have to swap the battery and start it with the small pcb mounted button next to the trim pot.

        As I said for powerloss indication I use the 3 leds which are soldered on a seperate pcb which you can see on the product photos

        One led indicates mains power, another one whether it is charging and the third if it's turned on.

        By simple connecting an optoisolator (optokoppler in german) to the mains indicator led and to a GPIO you can monitor whether mains has power or not.
        Another way is to use a non-invasive power meter (these with a coil) which can measure the power being drawn from mains and as a result can sense a blackout which triggers a shutdown.

        If you want I can send you a photo of my setup.
        I also wanted to make a youtube video about it in the near future.

        Joshua

        1. Thanks for the clarification Joshua - I'm assuming it doesn't have any specific battery protection or digital level low-power signal? For my projects I want the computer to have adequate time to shut down when the voltage is dropping, for the output to disconnect before the battery suffers and the whole lot to come back up shortly after power is restored. SO MANY of the so called Pi solutions out there fail to manage this simple trick. For me UPS means unattended. Still, lots of potential answers coming up.

      1. He's right - the +B and +out are commoned - so you'd need to parallel the b- outputs to the battery and the - outputs to the load. The only thing with using these boards as against doing your own is getting to pin 8 the enable pin if you want to control that. on mine there APPEARS to be an easy to cut track but boards differ. How much the batteries are charged could be the difference between them lasting a couple of years or many years.

        1. well, if you and Aidan come out with a pcb with all this knowledge, published on oshpark or easyeda, everyone could even buy a full kit by them and with adequate skills, solder it on their own 🙂

          or publish on tindie, as many do... 😉

          sure using premade boards, if easily interconnectable and "hackable" (like a track cut, as you say) is easier for everyone, but leads to bigger boards...

    1. as stated on that link, they're just battery protection boards, nothing to do with an ups functionality with all the bells and whistles Peter explained many times (recovery from flat, shutdown of the OS, etc)

  5. Hi Peter,

    Have you ever considered to use P-Channel MOSFET instead of regular diodes? Then you can use 2 MOSFET's and one dirty cheap 4 AMPS up converter. Cheap (I mean really CHEAP) MOSFETs are available for example from Aliexpress:

    https://www.aliexpress.com/item/20PCS-FQP47P06-47P06-MOSFET-N-CH-60V-47A-TO-220/32432271459.html?spm=a2g0s.13010208.99999999.262.23Zkws

    What they can do and how to use them? Answers - here:

    https://www.youtube.com/watch?v=IrB-FPcv1Dc&list=PLN-sn0AkfeorOZnNqPCWNinHtGEfGt81M&index=8

    BR,
    Aidas

    1. Hi - you know - I SHOULD have considered using P-channel MOSFETS - but I didn't probably as I'd never really considered any that handle gate-source voltages over over logic levels - but you're absolutely right - aside from costing perhaps a little more - they WOULD appear to make FAR more sense than using and kind of DIODE - I wonder why more people don't point that out - and thanks for the info.

      For anyone wondering what on EARTH we're talking about - diodes drop voltage - up to 0.8v or so for a silicon diode and up to 0.4v for upmarket diodes... not a lot - but when you're talking about 3 to 5v that is a significant chunk. MOSFETS can have a really significantly low on-resistance which can amount to VERY low voltage drop. Very good - will remember that for next time.

      1. I've checked the price for IRLML2502 on mouser.com - it's just 0.33€ if you buy 1 and 0.25€ if you purchase 10 of them. And it's capable of 4.2A (continuous) with R(on) only 0.045Ω (max), if VGS = 4.5V. Yes, it's N-Channel MOSFET, but why not to add it to the ground instead of Vcc? Similar P-Channel MOSFET IRLML6402 has bit higher R - 0.065Ω and it's still very acceptable for 1A or even 2A (have you ever experienced RPI consuming 2A?). And these MOSFET's are really tiny (SOT-23) - circa 3mm x 3mm

  6. Here is a very simple circuit used with Lead-Acid batteries (They are easy to charge and they keep charge for a very long time) Do not attempt to charge any other kind of battery with circuit... they will blow it up!

    Lead-Acid UPS

    Part List:

    R1 - 39 ohms 1/2W
    D1, D3, D4 - 1N4001 or similar diode
    D2 - 13V zener rated 1W
    C1 - 220uF electrolytic capacitor rated 25V
    C2 - 10uF electrolytic capacitor rated 10V
    IC - 7805 or similar 5V regulator
    BAT - 12V lead acid battery

  7. Pete,
    Not all protection boards have charging and balance the batteries specially the cheap Chinese ones that are not real BCMs. For these you need to have constant current/voltage feeding the circuit to fully charge the batteries. This one promises a charger on it https://www.amazon.com/dp/B01I9TXMR6/ref=cm_sw_r_cp_ep_dp_q7Slzb5HVPYTQ but since there are no real specs....

    Here is a good example of someone building a UPS using the PCB, a Charging circuit and finally a relay to decouple the power source, charger and drain source using those low cost boards.
    https://www.youtube.com/watch?v=kuEgZELszLk

    Hope this helps as I am working on building my own.

  8. Yes that correct , but it is moor than a expensive battery charge circuit , its a UPS system in 1 IC with I2C and a loot of type's of battery .
    It is waiting for a chines cheap offering .

  9. about the board of the 18/10 added note: is there any led that turn on when battery low? can it eventually be removed and used those pads as an indicator connected to a gpio to detect low power and force a shutdown?

    i see only 1 led in the bottom middle of the board... and what's that unpopulated pad above the led?

          1. Yes, all options open - but I am impressed by the output voltage stability at low voltage - from this unit. Indeed I'm pondering the idea of the 5v running the Nano... as that might be better than running the Nano on a really flat battery directly - with a MOSFET turning on and off output to the load.... might make a mockup. I have a logic level MOSFET somewhere. For me, if the battery gets really low, you've had no power for hours - what's another 15 minutes to let the battery recover before turning the power back on!

              1. 1.8 is - I was just pushing to see how far it would go. I've just grabbed a couple of IRF5305 devices... I realised you must power the 328 and oled from a 3v3 source to get steady A/D reading and also OLED does not like any lower voltage. So the 733 regulator is looking good for that. By feeding the 328 and OLED from the buck convertor that gives them a steady supply throughout the whole range of battery voltage.

                But that then leaves turning the buck off or it's output to the load. That should work as although the 328 is only putting out 3v3 and the buck output is 5v, the threshold for the gate is 2v and there's only a 1.7v difference. But now I can't go sailing over 5v output and that is hopefully where the mosfet comes in. It occurred to me that a second mosfet from the power input to the load could be turned on instead of the first mosfet to bypass the battery when there is power... the only potential issue there is, when there is no input power, the gate is then much higher voltage than the rest of the mosfet but according to the spec that device can handle +-20v on the gate. Need some breadboard.

        1. Of course a fatal flaw there is that you would have to fit an on-off switch. Most meters today have the power integrated into the control - or even auto-shutoff - which is fine but you might not want to leave the buck running for any length of time even with no load for fear of draining the battery?

  10. I was thinking about the same idea... but with bit of twist... run a 3.3v from vin... to one of gpio pins and have the nano monitor the pin... so when the power goes out it would know how long it can run on a given power... estimate how long it can stay up... then if it runs the power to so some level.... shutdown and run some counter... so when the power comes back least it could estimate how how it was dead.... i had that problem with one my clients... a dirty fix was... each time m1 & rpi 0 come back i just set the time to opening time of the shop 🙂 since content runs on a fixed time loop...

    1. Hi Erik.

      See updated diagram and I'm already using a 328-based Nano-type board (£1.40 from China) powered by the buck convertor, to monitor the battery voltage - and to control a MOSFET on the output (P-channel) and and SSD1306 to display the state. It's all coming along well, but I suspect the end board will use two of those boosters. I COULD take the load off the charger by another simpler method - bypassing the whole lot with another MOSFET when there is power... haven't tested how the MOSFET will handle reverse voltages yet but that's next.

  11. Hi Peter, I read your blog with pleasure, thanks for all. But the schematic at the beginning is a little confusing for me. The module charging Lion is not connected precisely, B- and OUT- are different lines, pass true by FS8205A, driven by DWO1A. If you short this lines with blue line, there will be no protection for Lion at all. And one converter in the middle may be excluded. Actually using converter after TP4056 will loose some of charge current. So it is simply to wire the diode from 5,1Vin to 5,1Vout. And the second diode at the top converter MT3608 is not needed, because there is an diode on the board that can make this function and closed loop of MT3608 will close the internal MOSFET when occur a little bit voltage at the output . There was a better way to switch 2 power inputs to one outputs using TPS2113A https://www.pololu.com/product/2596 , but it is cheaper to use a diode of course.

    1. Hi there.

      Ok first things first I have updated the blog and you'll note I've now corrected the wiring. Secondly I'm currently toying with that combined unit - and using a P channel MOSFET to turn the output on and off - as I need the 5v out to feed the NANO which is doing the switching. The Texas chip is good - but WAY, WAY too expensive (but thanks for the info). That would be the most expensive item on the board by some way.

    1. Checked this further - it seems this particular solution DOES wait for the caps to charge up first before powering the R.Pi.

      Personally, I like the "separation" idea of this. i.e. this UPS shield deals only with the shutdown and powerup - but I think it misses a trick because there is no separate hardware watchdog timer circuit. The idea being that another script runs to toggle a GPIO pin, if the R.Pi hangs for any reason, then the hardware watchdog reboots the R.Pi.

      Bear in mind that if you wanted more battery backup time, then all thats needed is a separate lipo battery back up placed beforehand (which you can buy cheaply anywhere).
      This separate battery backup would also power the dumb peripherals through a connector on the shield (which lessens the need to provide power through the R.Pi)

      In the end, its all about deciding what things are important to have UPS backup and not - I'd say it is only the R.Pi "brains" that is important really. If any other device needs to have significant power to power down, then they should have their own UPS soluition anyway

      1. See my "list of requirements" - further down in comments.. I'm pretty sure none of them cater for one particular combination... i.e. the power has dropped, the battery is on it's way down, the unit has informed the PI to shut down - BUT now the power is restored..... before the unit has had a chance to turn off the power.

        I'm ploughing ahead with a solution - but your comment about time to charge the battery just hit me - I'm going to put ALL of those timing sessions in EEPROM so they can be adjusted..... funny how things trigger you off.

        1. @Pete - it does cater for that too!
          Heres the info from their datasheet

          CHARGE MODE
          - charging the supercapacitor using the step-down DC/DC converter when external power supply voltage is available at the input
          - The load device at the output (Raspberry Pi or another SBC) stays disconnected from 5V power rail until supercapacitor voltage rises above 4.2V

          NORMAL OPERATION
          - The Raspberry Pi (or another SBC) is powered from the external power supply
          - The supercapacitor is either being charged or charging is completed.

          BROWNOUT (or short-term power failure)
          - starts when input voltage falls below 4.8V
          - external power supply will be disconnected
          - Raspberry Pi or another SBC is powered from supercapacitor backup.
          - The Raspberry Pi receives no information about power failure.
          - In case of power recovery continues with Normal operation.
          - ends when supercapacitor voltage falls below 3.8V. The Shutdown mode is started.

          SHUTDOWN
          - starts when supercapacitor voltage falls below 3.8V in Brownout mode.
          - The Raspberry Pi or another SBC remains powered from the supercapacitor via step-up DC/DC converter
          - The information about power failure is communicated to the SBC. The SBC must immediately start with shut down procedure.
          - A power recovery during this mode has no influence on the shut down procedure. The procedure will be completed and the the SBC will be powered off regardless of the external power.
          - after completing the shutdown procedure or latest when the voltage at the supercapacitor falls below 1V the Raspberry Pi or another SBC will be disconnected from 5V supply rail.
          - wait until external power supply voltage will be back to start charging again

  12. Glad I found this blog - thanks Pete for the detailed investigation. I've been working on a very similar design lately.

    B6287Y/MT3608 seems to be a nifty chip, and the board is dirt cheap. My main potential problem with it is that it uses a fairly high quiescent current - about 1.. 1.5 mA which may drain the LiPo battery (I am simply using the enable="always on" for more complicated reasons)

    The other problem is that these chips may spontaneously catch fire? https://www.youtube.com/watch?v=ojw112KoNBI&feature=youtu.be&t=81

    So now I am now rolling my own. I've started with MIC2250 (which should give me about 50 uA quiescent current). Total parts (no PCB) should be less than $1. The alternative would be NCP1403, although it requires a bit more expensive parts.

    1. Hi Adi - erm MIC2250 - 80% efficient - that's not very good at all... 2.5v min is also above the MT3608 and I checked Ebay and Aliexpress, the former - the chips were horrendously priced, the latter, nothing - did I miss something.... however always nice to see alternatives...NCP1403 - as you say not that cheap and poor efficiency at around 80% - and for the life of me I could not see how much output current the latter could handle...???

      1. Valid points in general but not an issue in my case. My application (a solar-powered wireless water sensor) has extremely low consumption in active move (think that I need to have about 4 uA on average if we factor in the duty cycle of one reading every 10 min). So because it's mostly idle efficiency is not a concern - quiescent current is the critical value to optimize for.

        The water sensor is 12V-powered but the solar-charged Li-ion is 2.5 ... 3.7V) so that's why I need a boost to connect the two.

        Re. MIC2250, 2.5V minimum is probably OK for me (NCP1403 is a bit more tolerant to very low voltages as I believe it can go as low as 1.8V). But in my case 2.5V minimum is not an issue. I don't think I am even supposed to let the Li-ion battery drop below that 🙂 (and, besides, there is not much juice left below that voltage)

        Total boost price comes a little above $1 including all passives (I haven't even optimized prices yet - this is for a basic prototype). Here is my Digikey cart: http://www.digikey.com/short/qtqf50

        For NCP1403 design the total price is a bit higher mainly due to the output capacitor (which needs to be is much larger at 33 uF)

  13. I should write a bible on UPS requirements..

    None - NOT ONE of the solutions I've seen to date has been properly thought through as an "uninterruptible supply".

    Here are what I think are minimal requirements (and incidentally "we're working on it" having almost given up looking for inexpensive solutions.

    An uninterruptible supply should clearly be able to handle a couple of amps output - that's an easy one.

    It should be able to shut down the target processor via a port bit (or should I say give the processor information to shut down). That is missing from some but again is an easy one.

    It should, in the event of the battery going flat and having shut down the processor, be able to recover in the event of the power coming back on.

    And to do that, there are TWO essentials - at least one of which is missing from every solution I've seen:

    From a flat battery, when the power is restored, the unit should give the battery a little time to recover some energy and THEN turn on the output- and should be able to handle enough incoming current to supply the load AND give some current to the battery to charge it.

    And here's the REAL killer...

    When the voltage goes down and the signal is sent to the Pi (or whatever) to shut down, IF the the power is restored BEFORE the power is turned off... the unit should WAIT to give ample time for the Pi to shut down - and then STILL REMOVE power, wait a few seconds and RESTORE power in order to ensure that in all cases the Pi (or whatever) actually comes back up.

    Am I the ONLY person who needs unattended setups?

    SO - I'm sitting here with a half built prototype and apparently Aidan is doing a board layout - I've no idea how well this will all work - we can but try... meanwhile - my "work in progress" - don't ask questions about it because it's a "work in progress" - is linked below - look near the end where I handle hopefully all possible states... it really isn't rocket science.

    This is intended for an Atmega328 chip but the idea applies to any cheap chip really...

    https://bitbucket.org/snippets/scargill/RBLqyE

    1. "... the unit should WAIT to give ample time for the Pi to shut down - and then STILL REMOVE power, wait a few seconds and RESTORE power in order to ensure that in all cases the Pi (or whatever) actually comes back up."

      @Pete - Have a look at the links I provided above. In particular the "data sheet" which says

      "Once a shutdown has been initiated there is no way back: The procedure must be completed even if power is restored while shutting down. This is an important feature for protection against repeated power failures."

      If you wanted more control - you could just do this after the PI has booted - using a combination of hardward watchdog "addon" and maybe mosfets / relays? (provided by another shield perhaps?)

      Just thoughts on a UPS "modular system" approach

  14. Hi Peter . At first glance - it does look like you've found one that does the shutdown correctly!!! Well, that's one - this needs further investigation...

    That 1 minute could be better. Not sure what he has against batteries (charging circuit for a supercap will be easier).

  15. Ok, so I spent the day working on a prototype of a simplified version of what Aidan is busy laying out right now - and importantly - getting the software to do the job - I got a bit carried away with the latter...

    Anyway rather than try to describe what I've spent my time doing - here's a video

    https://youtu.be/44Lvdf7o4GQ

  16. Amazing!

    After testing many wrongly considered "UPS" boards, My home automation Raspi is backed by a horrendous https://www.amazon.es/gp/product/B00IMCF8FA .

    It is dumb, heavy, and expensive (46€), but -on the other side- it can power my Internet router, the fiber ONT and a network switch.

    I solved power-down detection pinging a couple of devices periodically.

      1. My UPS is so cheap it hasn't got any monitoring ports.

        Anyway I am using NUT with a fake ups plugin I cooked. Instead of asking the ups, my plugin check some (non-power-protected) LAN connections in order to notify (Telegram) me and start shutdown.

    1. Haha, yes, I have two APC ES-500's old enough that I've had to manually replace the batteries. My main Pi, router, switch & NAS are connected.

      They were enough to see me through working from home during the "Great Flood" in Sheffield a few years ago where we had power for 2 hours at a time then off for 2 hours.

      1. Well, check the latest update to the blog - a lot of work last night - got the buttons on - worthwhile software additions and fixes (now an optional warning beeper).. I'm pretty chuffed with where this is heading.. of course, only for smaller projects with the current hardware.

  17. Seeing as you're nearly there it doesn't seem fair to add anythings else BUT! There are some established USB interfaces for UPS systems that might make some work dead easy? http://networkupstools.org has a lot of info and software both for the UPS and clients. Now you've gone with some some intelligence perhaps it is easy to implement this stuff? The network bit I think is for a number of devices hanging off one UPS. At the very least there is some info on what might be tunable parameters and what people like to see on displays.

    1. New info always appreciated - however - works - cheap - reliable - and I'm not trying to impress buyers:-) people are more than welcome to change the software to whatever their hearts desire - I have loads of space left in the 328.

  18. Rather than using the tp4056 boards, I found similar sized boards that charges and give a 5V output when on battery or supplied so the same as your newer boards but much smaller. I'm not sure if these have been mentioned here see: goo.gl/eLT11z . I've been using them and seem much more useful that the 4056 boards, they are very small and dirt cheap. It comes with a USB socket to supply the 5V, I simply solder onto the pins to get the 5V but if you removed it the board would be tiny.

    1. So the short answer is NO they've not been mentioned here as I was not aware of them.... IF the claims are true - I like the increased charge and so I've ordered 5 -you'll see that I'm using a single board in my new "dogs breakfast" MK2 prototype so these would work a treat with the MOSFET stuck on the output... however - 1 amp out is a little lower than the chips I'm using - but then charging is a little higher - so they'd likely be good for many SBCs but probably NOT the RPI3... however - small is good - they're on the way, check this space in maybe 3 weeks?

      And thanks for that - as you say - dirt cheap.... just like the 328-based boards I'm using to control them!!! Good - excellent.

  19. Hi Pete,

    Nice little project. Have you considered adding an ltc4150 to the mix, it's a nice little chip for knowing exactly how charged/discharged your battery is. It also can give a good indication of the health of the battery.

    Using lipo's with coulomb counting gives a much better indication of state of charge than simply measuring battery voltages.

    Glen.

  20. I'd like to present some thoughts, as I see you guys going into directions which I have explored 2-3 years ago.
    1. forget about stepup modules when using the 3.7V Lipo all 40 pin Raspis will work fine on 4V down to 3.6V (a charged Lipo's voltage 4.2V)
    2. to address the issue of short periods of power coming back and being off again, you will need a microcontroller which goes through a state machine. Once the boot is initiated, you go through, and if power is off after that, you can shut down again. You will obviousely wait a few seconds after power is back before you initiate reboot.
    3. the mentioned 4056 charging circuits are ideal, in my design which I have linked in my earlier post, I change the resistor for setting charge current to a higher value like 5k or 8k, this prevents smaller power supplies to go down too much if you have a completely discharged Lipo.
    I hope this helps.

    1. My comment would be that it does not SEEM to have intelligence in the form of a processor.

      My ideal supply - and that I've pretty much achieved will....

      1. Run of mains until the power fails
      2. Run off battery until the battery fails
      3. When the battery fails it will inform the Pi and give it time to shut down before removing power.
      4. If the power returns BEFORE running right down it will non-the less complete the power cycling of the Pi to ensure we can't end up with a Pi shut down permanently or needing manual intervention.
      5. Ideally it should be programmable for voltages and delays etc.

      I've gone way past that with the little Arduino design but of course, you have to make it rather than buy it...

      This particular model - I would ask those questions - it does not look like it would have any of that.

      1. You're right about the intelligence part!
        I was just wondering about whether the module mentioned satisfied the power requirements; as I recall from your previous experiments, the other modules fail to provide enough juice.

        Not just RPi or MCUs, but I want to use UPS for other boxes such as Android TV box or automation gateways that may need up to 2A current, hence the query.

        Once you're done with your design, could you please share the working schematic and PCB design please?

        1. Might be a long wait.... mine is done the hard way on breadboard, we had a board made but there were too many issues. Aidan will have another go but this is only a tiny part of the number of projects he's onto. I personally would like to see a variation that uses 2 MOSFETS - to bypass the unit altogether when the battery is really low but the power is back on... to make sure that works reliably could take some experimenting - expect that to be an early spring project.

  21. Cheers Pete. Do you think the final mosfet can be eliminated by using the pi run pad to restart the pi . In that way the pi can be let to shut down at leisure in case any process takes longer?

Leave a Reply

Your email address will not be published. Required fields are marked *