4

I'd like to power my Arduino circuit like a smartphone. That is:

  • When the device is unplugged, power by rechargeable battery
  • When the device is plugged in, power by mains and charge battery at the same time

I'd like to not go the expensive shield route and instead purchase some inexpensive breakout boards from Aliexpress or eBay if possible. I'm willing to put in the time to learn if someone will point the way.

Can someone please provide some guidance?

6

Yes, charging a battery and supplying an Arduino at the same time is possible as long as we manage the caveats (see below) of in-circuit charging.


This is what I use:


This is how it works:

  • charger is fed via solar panel and/or USB supply,
  • battery is continuously supervised and charged on demand
  • Arduino is connected to the output side of the charger

This works because the load that the Arduino presents is relatively small compared to what the charger can feed (and what the battery can take). During recharging the charge current will predominantly flow through the battery. And since the current through the battery drops once it gets full, the charger can still recognise this drop and finish the charge cycle – even though the Arduino is connected all the time.


Example setup:

I took some quick snapshots, please excuse the image quality. Charger is in the center, Arduino to the upper left, battery in a holder to the lower left, solar panel to the upper right.

The Arduino has a voltage regulator, but I don't use it in this setup. An explanation why and when to use the regulator is beyond the scope of this question and a matter for another answer.

charger turned off

In the first photo the charger input is only connected to the solar panel, but the panel voltage is low. So the charger is actually off and the Arduino is running off the battery.


charger in charge mode

In the second photo the charger is now connected to a USB power supply. The charger is on and in CC/CV charge mode (as indicated by the red LED of this charger model).


charger in standby mode

In the third photo the charge cycle is completed, the battery is full (as indicated by the blue LED of this charger model). Note that the charger could determine the charge completion even though the Arduino is connected and running (no power saving tricks involved here).


Background info:

The charger switches between CC and CV mode, depending on the level of discharge the battery is in. Particularly, my charger uses CC mode in case the voltage on the battery side is below 4V and CV mode in case the voltage on the battery side is above 4V. The current limit can be configured and the voltage limit is hard coded to around 4.2V, which makes the circuit save for a device like Arduino.

The charger switches between CC and CV mode.

Image source: Nanjing Top Power

Other chargers may have other thresholds, but that doesn't matter as long as it fits your battery type and uses constant current/voltage only. I have no particular recommendation for a charger, but so far have a good impression of the one I used in this answer.


Caveats:

There are a couple of cases to consider, though:

Deep discharge

Should the battery voltage ever go below around 2.9V (e.g. deeply discharged battery), the charger will switch into trickle charge mode where only very small amounts of current are passed to the battery – too little current (i.e. too low a voltage) for the Arduino to run. Arduino will go into brown-out and try to restart until the battery has recovered. So this can become a state in which your Arduino won't respond for an unknown amount of time.

High load

If the load connected to the battery draws a current that isn't small anymore – compared to the battery charge current – then the charger cannot recognise a full battery anymore, since the current as seen by the charger will never fall off at the end of any charge cycle. So watch out how many gadgets you connect to this kind of in-circuit charger.

Wrong charger type

There are a multitude of ways to charge a battery. Things like trickle charge, pulse charge, timer based charging, and so on. None of these would likely work, as the voltage those charger types generate could upset the Arduino and the load the Arduino presents could upset the charger.

Please also note that some chargers don't supervise the battery. With Li-Ion or Li-Poly (and other) batteries this would be a very bad idea. Always choose a charger appropriate for your battery.


Alternatives

The charger I use employs a linear regulator. That's not very efficient, other topologies are possible. But they might require supply filtering for the Arduino.


Shameless plug

I wrote a library for the purpose of supervising an Arduino's supply voltage (and chip temperature). This technique allows to check the battery level without any additional components. That library is called CoreSensors.


Further links:

3

There are many ways you can do this, as you mention there are ready made shields that do this.

You need to take a few thing into consideration:

  1. Power - how much power will your cirquit be drawing, as many of these boards will only be able to deliver 3-600mah is this enough, at the same time you will find out how long your cirquit will be able to stay on battery power.

  2. Complexity - a ready made controller/charger is already made to work togheter, if you go for a separate charger and booster module you might end up with unwanted power loss, or you need ekstra buttons/sliders to control power.

You could in theory use 1 lipo cell directly to power your MCU, as the voltage spans from 3,6 to 4,7 Volts pr.cell and charge the lipo when NOT in use (you cannot charge a lipo directly while in use, thats why you need a controller). This would be the cheapest way.

  • That got me puzzled: "you cannot charge a lipo directly while in use". While it's true that the charging circuit would be irritated by an additional load in parallel to the battery, are you saving you can't have battery charging without turning off the device? Because that's not the case (e.g. see your phone/computer). I think a good answer should address exactly this issue, as everything else follows from there. – sekdiy Mar 22 '16 at 10:31
  • Charging lipo is done in stages: – Hans Neve Mar 22 '16 at 10:41
  • Sure, but there are controllers that handle load switching. Since you suggest a controller, why not suggest one that does? I would if I could. ;) – sekdiy Mar 22 '16 at 10:44
  • sparkfuns LiPower shield would get the job done, but OP is looking for cheap china solution. and I gave a few considerations to think about. My comment reg. Lipo's was aimed at directly connecting the battery to the 5v line, a full lipo will supply (aprox) 4.7V and deliver down until brown out. I should also mention that draining a lipo too much might destroy it. – Hans Neve Mar 22 '16 at 10:53
  • I've been looking at the SparkFun DEV-13158. Ignoring the fuel gauge and the fact that it produces multiple output voltages, we have: charger -> battery -> voltage regulator -> Arduino. So, no magic compared to a breakout board. Of course I agree that the battery voltage has to be monitored in order to prevent a deep discharge. – sekdiy Mar 22 '16 at 11:45
0

Can someone please provide some guidance?

power your arduino from a power bank and then power the power bank via ac adapter.

simplest and likely most inexpensive solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.