I am looking to use four 18650 batteries and a step-down DC-DC converter to power my Raspberry Pi 4. The negative terminal of the DC-DC converter is common for the input and the output.

I would like a way to monitor the voltage of the battery pack itself. The best way to go about this I could find was the PiCheckVoltage project. This seems rather abandoned but otherwise I am pretty happy with it. I would like to know if there are more recent / practical solutions to this problem that you know of.

  • 1
    Bit baffled - normally an 18650 only goes up to 4.2v so you need a boost converter to reach 5V and to handle the drop and protect the battery from draining too far. USB / HDMI needs 5v so I’m not sure the Pi can run on only 3.3v in (May be wrong with that). Have you looked at the Pi hats that are designed for this? I would take a look at learn.pi-supply.com/battery-levels for a calculator and hat (though others are available). – Andyroo Jul 8 at 11:33
  • 1
    They are connected in series. Sorry if that was not clear. – mr_tuna Jul 8 at 13:34
  • Forgive me but you will get the option for more current to be drawn and waste less from the conversion to 5v by stepping up to five volts than down from 16 unless you need the higher voltage for something... – Andyroo Jul 8 at 16:08
  • @Andyroo: Excuse me, but the consensus of opinion is that buck (step-down) converters are a little more (not less) efficient than boost (step-up) converters. For example: REFERENCE. since the inductor current is not always flowing to the load, the efficiency of boost converters is generally lower than their bucking counterparts. – Seamus Jul 8 at 20:01
  • @Seamus Math way above my head tonight :-) I find it hard to believe 16.8 volts down to 5v is better than 4.2v to 5v But it’s possible. I have nothing accurate to test with though :( – Andyroo Jul 8 at 21:59

Why not go for a dedicate i2c monitor / controller - the boards are available for a few pounds on Ali et al and not much more at end user prices?

The INA219 will measure voltage and current, cope with up to 25+ volts and come on boards ready built.

| improve this answer | |

One option would be to use an MCP3002 ADC (2 channel analogue to digital converter).

Use a voltage divider circuit (2 resistors) to convert your battery voltage to a voltage range upto 3.3V. Feed this into one of the analogue channels on the MCP3002.

| improve this answer | |

In my Raspberry Pi tablet, I use very low frequency PWM to measure the battery voltage. One half of a dual voltage comparator was set up as a sawtooth oscillator operating at approximately 100Hz. The output of this was compared against a divided-down version of the battery voltage by the other half. The output of that in turn was tied into a GPIO pin.

Software running on the Pi samples the GPIO pin approximately 1000 times per second (with no guarantee of timing accuracy). These readings are stored in a circular buffer of 16384 entries, each 0 or 1. The floating point average of all the entries is computed, shifted, and scaled, to get a voltage reading. It takes about 16 seconds to get the first reading, after which it's a rolling average of the last 16 seconds.

Response time is obviously very slow, and the reading can potentially fluctuate, but in practice it is accurate enough for its intended purpose. For critical decisions, such as the battery being so low that a shutdown should soon take place, the condition must be present for at least one minute to be considered real.

The advantage to this approach is that it requires no proprietary chips, just an LM393 that's been available for decades. The drawback is that it requires more discrete parts than a more modern solution might.

The schematic and a more detailed description can be found at A Compact Home-Made Raspberry Pi Tablet, and the source code at Power, Display, and UI Management Daemon for DIY Raspberry Pi Tablet

| improve this answer | |

The PiCheckVoltage project may be stale for a reason. It strikes me as a bit over-complicated for the situation you've described. However, parts of the code may be useful. Here are some alternatives to consider:

1. Use "protected" 18650 batteries?

18650 batteries can be bought in a "self-protected" configuration.. You probably knew this already (I didn't), and I'm not sure if this fits with your objectives to monitor the voltage, but I thought it worth mentioning.

2. A simple, cheap, reliable, easy-to-use alternative to ADCs

I'm not an expert on battery chemistry, but I can't help wondering if a 10-12 bit ADC is necessary for monitoring battery voltage. If you know the voltage threshold you should trigger on, you could use a simple comparator:

  • input voltage derived from a voltage divider

  • reference voltage from a zener, or potentiometer tied to one of the regulated power buses on the RPi

  • output of comparator to a GPIO input pin - or use it to drive a relay which disconnects your battery-buck regulator from the RPi

3. A dedicated (sophisticated) battery monitor

You may find that a dedicated hardware solution is better suited to your objective. For example, Texas Instruments makes a line of Battery management ICs to suit a variety of purposes and applications. Their battery fuel gauges may meet your needs as they cover series arrangements and different battery chemistries. The BQ34110 in particular looks attractive for use in an RPi project as it offers an I2C interface and a less-intimidating pin count.

Similarly, Maxim also offers a line of ICs dedicated to battery monitoring - for example


That's a range of solutions for your problem - and it's likely to become a more common problem as the Raspberry Pi team finally moves toward a true low-power "sleep state" from which it can be summoned.

| improve this answer | |

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.