12v Pico Battery Monitor

Hi Everyone,
I’m looking to build a 12v battery monitor and I thought this would be a fairly common thing to want to do. I can’t find much in an out of the box solution.
Is there a Picodev option to monitor an external battery?
Or is this something I could mock up on a bread board?
I’d also want to charge a lithium battery to power the pico from the same 12v source so I still can report a flat (12v) battery.
I plan to build this into a LoRa system once I have the basic monitor figured out. (I’m an electronic newbie and a programmer oldie)
Any assistance greatly appreciated.
This is for. Lions Club bbq in a park where they need to monitor the battery that lights the gas so it’s public service project :cowboy_hat_face:
Thanks
David

2 Likes

Hi David,

What a project!

A couple questions that will hopefully help everyone with future replies:

  • What chemistry is the battery? SLA, Lithium Iron Phosphate, Li-ion cells? The key part here is multiple cells and the usable voltage range - a LiFePO4 battery sometimes has an inbuilt BMS to handle cut-off
  • What kind of environment are they running in? A shaded enclosure like a picnic BBQ?

Back to the project…
Unfortunately, there isn’t a PiicoDev module but a solution is very simple(and breadboard-able)!
A voltage divider can be used to divide down the voltage to a <3.3V level for the Pico’s ADC
image
(From topic: Makerverse USB-C LiPo Charger (CE08374) - #19 by John219336, though you’ll have to use different values for a 12V battery.)

The second battery is also quite easy, schottky diodes from the positive terminal of the battery into the Vsys pin will preference the highest voltage supply (USB, 12V battery or LiPo)

Keen to see how it goes!

1 Like

Hi Liam,
My understanding so far is the battery I wish to monitor is a 12v lead acid battery of the type used in a golf cart. I don’t know why they need such a large battery to start a gas bbq but I’m still in the requirements phase :cowboy_hat_face:
I think I can prototype a solution using a 12v car battery for testing. If I use parameters in my program I should easily be able to adjust the output. I’m guessing I’d also have to adjust those resistors depending on the maximum and minimum voltage of the battery. I think the battery lasts for ages until someone jams the start button in and the starter clicks away until the battery is flat.
My plan is to build two units that communicate via LoRa similar to my recent Gate Alarm project so a club member can drive in range and push a button on a hand held device and that will trigger a response from the bbq returning the voltage. The bbq is some distance away but I think they hope to get the range to reach the pub but that’s just speculation :cowboy_hat_face:
Most of the difficult coding is already done on the other project. It already sends the pico battery voltage from the gate to the house in a json encoded txt message.

Thanks for your interest.

David

1 Like

This would be my starting point. (see below)

Voltage at ADC pin would be about 1/10 Battery voltage. Test to determine what ADC values relate to what battery voltage. 1/10 ensures the voltage at the ADC pin does not damage the microcontroller.

Suggest the following as the power supply unit, have used them numerous times and they work well.

The 5V power supply output could be connected to the LiPo charger @Liam120347 has shown and to any other electronics. BTW the Pi Pico has an internal ADC designed to measure VSYS therefore no need for external resistors; but a Pi Pico W would need external resistors.

In my opinion a LiPo is not needed. The 5V supply will still be working down to a low level of the 12V battery. At or slightly about 5V it would stop working.
If you activated a message when the battery is at 10V; the battery would still have enough power to send this message for quite a while.

Regards
Jim

image

1 Like

Hi James

At this point the battery will be damaged, possibly beyond saving. At best it will need an intelligent (9 stage??) charger to have any chance of rejuvenation.

The generally recommended lowest discharge point for a 12V lead acid battery is 10.8V. Most low voltage cut off devices are set or recommended setting point at 11V. All published discharge curves have a cut off at 10.8V.

Methinks a rethink of a proposed alarm level might be a good idea.
Cheers Bob

1 Like

@Robert93820 Agree.
I didn’t check the general recommendations for lead acid batteries.
My idea was to give @David191372 some ideas as a starting point.

So yep if my project, I would get the software to message when it fell to 11V.
I thought about stopping the BBQUE switch from working at this voltage too.
Then the battery could not get depleted further by the switch jamming.

The small current draw from the microcontroller and LORA would still allow for some messages to be sent. And then stop completely when it fell to 10.8V. At this point the microcontroller could turn itself off.

The resistor divider is a very crude but very simple way of detecting battery voltage.
Thanks for your information.

Cheers
Jim

1 Like

Hi James
If any such system is remote (that is if it can’t easily or quickly be accessed) one of the low voltage shut down devices which are available would be a good idea just to prevent battery damage. A lot of these are high current (several Amps) devices but there may be lower current ones around, I have not had occasion to look.
Cheers Bob

3 Likes

Thanks for all the details. It may take me a little time to digest it all.
I found this site to calculate the voltage divider resistance values
https://www.allaboutcircuits.com/tools/voltage-divider-calculator/ so that seems fairly easy.
I’ll give that power supply suggested above a try. I’m not really worried about the pico discharging a golf cart battery to the point of damaging it. The people who look after the bbq may address the button jamming problem.
The pico device on the bbq end will be set to use as little power as possible. It can wake up every 15 seconds or so and listen for a request for data. If it doesn’t get one it can go back to sleep. The remote reader device will normally be out of range so I can put a power switch on that and turn it off when not in use. When on, it can send say 4 requests one every 5 seconds until it gets a response then display the voltage received.
I’ll post more details on what I come up with and how it goes.
Thanks
David.

3 Likes

Hi David,

So keen to see what you end up making! And cheers for everyone jumping in to help!
That diagram from Jim will come in especially handy :slight_smile:

Liam

Hi Liam,
I started playing with resistors and a multi meter today.
Plus I also placed an order for all the parts.
So I’ll wait out the Christmas delays and see what I come up with.

David

1 Like

Hi David

Not a difficult task.

The division ratio is simply (R1 + R2) / R2
Vout = (Vin / (R1 + R2)) * R2.
R = Ω, kΩ, MΩ. Does not matter as long as R1 and R2 are the same multiplier.
This will be accurate for your application.

The following info is for completeness only and if you prefer can be ignored in your case.
The above formula is only accurate with a high or infinite load resistance.
AND a source resistance of zero or very low source resistance.
Where the load resistance is less than about (R2 * 10) it must be considered as a resistance in parallel with R2 or the error may be intolerable.
Where the source resistance is greater than about (R1 / 10) it must be considered as a resistance in series with R1 or once again the error might be too great.

There is another use for this simple network and that is for impedance matching. The use of commonly available resistors however limits the use to low or audio frequencies due to the inductance of the resistors becoming significant at higher frequency. The calculations for this application are a little more complex.

Just a bit of trivial background for you to take on board. But don’t let it worry you.
Cheers Bob

2 Likes

Hi Bob,
Sounds like you know what you are talking about :slight_smile:
I have a question. Is this likely to discharge the battery on its own?
I notice the two resistors are simply hooked positive to negative and the reduced voltage is measured between the two resistors.
Should I be going for a very high resistance to minimise this?
Maybe it’s insignificant for a golf cart battery but what If I was trying to monitor a couple of double A’s?
Thanks
David

2 Likes

Hi David

Yes. By how much will depend directly on the total resistance value and battery capacity.
The leakage current in Amps is the voltage divided by the total resistance in ohms.
Example. Voltage = 12V, total resistance might be 25kΩ (25000Ω) then the current would be 12/25000 = 0.0005A or 0.5mA. Compared to what your load is likely to be it is not very significant BUT it is there. You would normally have this connected after any main switch so it is only monitoring while the equipment is in use.
A less cumbersome formula is V divided by R in kΩ result in mA. so 12(V) / 25(kΩ) = 0.05(mA). Same thing but now we have the resistance and current with the same multiplier.

Correct.

The higher resistance will reduce your leakage current but you will run into other problems. Total resistance is not critical but try to keep it below about 20k.

A total R of 10k would be a leakage of 0.3mA which is not the end of the world but would affect battery life.By how much would depend on what percentage this 0.3mA is of your load current. Example, if your load current was 0.3mA it would expect it to halve your battery life

I believe to monitor you would connect this Vout to an ADC input to do the monitoring. In this case I think the input resistance of the ADC will be very high and can be safely ignored.
Cheers Bob

4 Likes

@David191372 In electronic design there are always compromises.
The current drain of the resistors is minimal compared to other components.
The power supply I listed is cheap and works well but draws 6ma not powering anything.
There is a Pololu power supply (see below) that is much more expensive but only draws 500uA.

The Pico (if you will be using one) draws about 20mA when running.
LoRa board 100mA when transmitting.

I am beginning to think the design should be something that wakes every hour or so to check the battery and send a message. Then it turns itself off. With its own supply that will last at least 6 months. If the sense resistors draw about 300uA as @Robert93820 said they would not greatly affect the Golf Cart battery.

But with the Pololu supply and resistors would still be less than 1mA current drain and no need for another supply (battery). Depends on how much you want to spend.

Regards
Jim

3 Likes

Hi Jim,
I have previously built a LORA device very similar to this and it works quite well. The LORA module came with a battery and I just connected a 5v USB solar charger and everything worked.
That project didn’t need me to design anything electronic at all. Just components clipped together.
For this one I have to use my brain :slight_smile:
Strategic sleep commands for the LORA module helped with power consumption and sleeping the pico as well helped a lot. It can run 3-4 days with no sun and only needs about an hour to charge up the little battery.

I’m not worried about power demands on this BBQ project it’s more a learning thing for me to understand more about what is likely to happen.
I have bread boarded a voltage divider with R1 = 25k and R2 = 6.6k
I needed a couple of resistors in series to manage this with the resistors I had lying around.
With an input voldate of 12.8v these resistors show 2.64v on my metre which is as the formula predicted. So 10.8v should produce 2.25v and 14.8v should produce 3.09v output.
So far so good.
As shown in the photo below I have hooked the Vout of the resistors to ADC pin 1 on my PICO w.
In this test I just plan on powering the Pico from USB.
Now where do I hook the negative lead to from the 12v battery.
I don’t want to guess and fry it already :slight_smile:
I have done some reading and I see a pin called ADC_VREF and another named Analog Ground.
If I had to guess it would be Analog Ground.

Thanks
David

3 Likes

Hi David,

Glad to see everything coming along so quickly!
You’re spot on with Analog Ground.

ADC_VREF is the top of the ADC’s sensing range (definitely dont connect it there!

Liam

2 Likes

Hi David.
Looks like you are getting the hang of all this or getting some idea anyway.

As Liam said “analog gnd” is the correct place for negative battery. Should be the same as any other ground pin but would be closer to the actual analog pins physically which is less likely to cause any problems. If you use any outputs you can use any of the other grounds.

Don’t connect ANYTHING to “adc ref” as I think it is an output and will not concern you with this exercise anyway.

Keep going, you’re doing well.
Cheers Bob

PS: While we are here I note you have Pico plugged into a breadboard using the header pins. When reused be wary of the points where the header pins are plugged in. They are quite large and with lesser quality breadboards the female spring contacts are a bit reluctant to return to the original position. I have discarded a couple of el cheapo boards where the female contacts have been pretty much destroyed by these header pins.

I am not suggesting your board falls into this category but just be aware of this and make sure any component you insert is a firm fit or you might find yourself building in faults before you start.

3 Likes

Hi David,
Glad its going well. The voltage range is within the limits of the Pico pins (3.3V).
With respect to ADC_VREF and ADC_GND; the following from the Raspberry Pi Pico datasheet.

You would connect a reference voltage source to ADC_VREF if you wanted something like 0 to 1V rather than 0 to 3V3. But, cannot go negative or greater than 3V3.

From the Pico schematic, how ADC_VREF is derived. Comes from RP2040 pin ADC_AVDD.

image

ADC_GND is related to the Pico board and the ground plane within it. Essentially it is the same as Digital GND. You can use it as the connection to the battery GND if you want but it wont make a lot of difference.
The internal 3V3 reference is suitable for what you are doing so ADC_VREF should be left alone.

WARNING: It looks like you have the battery connected to the breadboard. Personally I would use a seperate breadboard to ensure the 12V lead from the battery is no where near the Pico. 12V on any pin will kill the Pico.

When testing on a breadboard, it is too easy to short something out and dead Pico.
I have found the following to be excellent when using the Pico and seperate it from other circuitry.

All the best
Regards
Jim

PS good info from Robert & Liam

1 Like

I have used one of those LIPO expansion boards on my previous project and did think they a simple way to break out the pins and connect to cool stuff including those picodev modules. I didn’t need to use it to connect a battery as the LoRa board came with a battery connector and a battery. That saved quite a few decisions on that project. I have ordered a couple of these expansion boards already for this project but thanks for letting me know I’m on the right track.

I have noticed that the bread board sockets are a little inconsistent and I have decided to check the connections are good. Once I have the plan consolidated it will definitely be out with the bread board and in with the PicoDev Expansion Board.

PS
I have left the resistors connected as show in the picture above for about 10 hours and the voltage has only dropped from 12.80 to 12.79 on my little 7.0Ah battery so I can’t see the ambient drain of the voltage divider being a problem on a larger battery.
I’ll post further details of this project along the way.

Same with some breadboards I have used, even using normal resistor sized wire they become intermittent after a while. The advice from Robert about the breadboard sockets not springing back properly. I have one good board which always works but it cost a lot. I think the spring steel and tinning of it is less than ideal on a lot of breadboards.

One thought occurred to me.
I have read Golf Cart batteries can be as high as 48V. These are probably Lithium.
As you have said the battery is 12V lead acid, but I’d like to know for sure if my project.

Regards
Jim