Pi Pico battery tester

highvaper

Well-Known Member
I have been working on a little pi pico based pid project https://fuckcombustion.com/threads/bakx-heating-principle-inspired-desktop-vape.54964/ and wanted to power it by some Molicel P28A lipo batteries I have.

The problem is I have bought the batteries over the years and dont know which have similar capacities - when pairing them up its better to use batteries of similar life so one doesnt get overloaded. So put I together a little battery tester I thought other people my find useful as I cannot be the only one with a load of 18650 batteries which may need recycling.

The tester uses a voltage divider to make sure the adc input to the pico is protected and under 3.3v. Im using 2 x 100K Ohm resistors in order to half the voltage - this could be adapted for larger voltage batteries, you just need to adjust the voltage divider resistance accordingly. Note: Test your resistors - i assumed what was labelled was the correct resistance - out of the same packet 3 were different.

When i wired up the correct resistors the pico reading from an adc pin and adc ground i got 4.2v which matched the multi-meter - tbh it doesnt really matter what the exact voltage is as long as everything is kept the same between tests of each battery comparing them is easy.

The plan was to the apply a load of some kind and take a voltage reading every few seconds so I could watch the voltage slowly decline. That didnt work as soon as the load was applied the voltage dropped by about 3v immediately.

So i had a play around with a relay and realised that if i wired up the voltage divider to Norally Closed and the load to Normally Open it could switch between taking a reading and applying a load automatically and so could just leave the pico to it while the battery drained.

A picture may explain it better:


The blue circuit is when the relay is on and battery under load. The black when the relay is off and taking a measurement. Note: The connections for controlling the relay arent shown in the above.


In reality it looks like:



The micropython code which controls it:

Python:
from machine import ADC, Pin
import utime

pin_relay = Pin(0, mode=Pin.OUT) #real pin 1 - also power relay and ground it from pico

adc_pin = Pin(26, mode=Pin.IN)   #for ground use adc ground pysical pin 33
adc = ADC(adc_pin)

while True:
    pin_relay.off()
    utime.sleep_ms(100)
    adc_value = adc.read_u16()
    voltage = (adc_value * (3.3 / 65535)) * 2  #We are dividing voltage in half in voltage divider

    #Change A to B to C and mark up each battery
    line = str(utime.time())+ ",A," + str(adc_value) + "," + str(voltage)
    print(line)
    file = open("readings.txt", "a")
    _ = file.write(line + "\n")
    file.close()

    if voltage >= 3:
        pin_relay.on()
    else:
        pin_relay.off()
        print("Voltage too low")
        #dont turn relay on as it will engage load on battery

    utime.sleep_ms(5000)

So we get a readings like:

Code:
time,battery,adc_reading,voltage
1713304922,A,42218,4.251755
1713304927,A,41818,4.211472
1713304932,A,41658,4.195358
1713304937,A,41562,4.18569
1713304942,A,41498,4.179245
1713304948,A,41434,4.172799
1713304953,A,41402,4.169577
1713304958,A,41354,4.164742
1713304963,A,41290,4.158297
1713304968,A,41258,4.155074
1713304973,A,41242,4.153463

After a few hours discharging some batteries you can plot a graph like:


And zoomed in to the last part of the test


The squiggles around 3v is when batteries got below 3v and the load wasnt turned on but as i left it for a bit they recovered and the load was reapplied hence it holding around 3v.

I need to redo the tests on A & B as maybe i have got the second reading labelled wrong as A1 & B2 and A2 & B1 seem to match much better - the A1, A2, B1, B2 were two tests on the same batteries to see if the results were consistent. But even if they are correct there is only about 30 secs over 40 mins between them so could be due to them being hotter or some other slight change (i have tried to keep everything the same in all tests other than changing the battery but ambient temp could affect things a little bit).

Notes if you do make one:
Dont forget to keep an eye on the temperature of the battery while discharging in case you put too much load on it.
I had some grief trying to get the relay to work initially the LED was flashing but nothing was happening (the relay should make a click sound when switched) - i was being cautious and hand removed the jumpers which separate the signal and relay supply but with them on it worked.
 
Last edited:
Top Bottom