Drive a 12v Fuel Gauge with a MCU

Hi Guys,

I’m building an ebike battery and I want to wire up a 12v fuel gauge to display the remaining “fuel”.

I have wired it up with a pot and playing around reveals empty on the gauge is around 6v and full is 10.5v.

I’m planning on having a step down module (input needs to take the variable battery voltage 30vdc-50vdc) and output 12vdc for the gauge and a second one to reduce that 12vdc to 5vdc for the MCU. (or a separate one taking the battery voltage and stepping down to 5vdc).

The MCU with monitor the battery voltage, convert and output a signal to the gauge.

My question is, how can I provide the 6 to 10.5vdc needed to drive the gauge? Most results I can find are overly complicated and use different approaches.

thanks,

Kane

1 Like

Hi gogreenpower
First question. Why do you need an MCU. What is wrong with converting the battery straight to Fuel gauge requirements.

Secondly what is the actual battery voltage. 30V to 50V isa pretty fair spread. Is it 50V full and 30V empty or exactly what.

Thirdly would not 0V to 12V for your gauge be OK. Like anything above 10.5V = OK and below 6V = Flat ??? Not quite sure exactly what this gauge is.
Cheers Bob

Hi @gogreenpower, Welcome to the forums!

This sounds like a task for a voltage divider circuit. You should be able to achieve this using a 20KΩ and a 5.1KΩ wired up like this diagram:

This will make the output at 50V around 10.16V and at 30V it will output 6.01V, which should be within the range for your gauge to read the charge correctly.

Hope this helps!

Hi Samuel, gogreenpower.
Like I said. Don’t know exactly what the “Fuel Gauge” is. It might need 12V separately to work. If so this should not be hard to arrange with some sort of step down converter.
Cheers Bob

Hi Rob,

Good point, I don’t need a microcontroller if I can convert the battery voltage to a range that suits the gauge. Speaking of which, it’s a generic automotive fuel gauge that operates on 12v. I have tested the gauge with 0-12v input and it displays from empty to full in the range of 6v - empty, 10.5v full, above and below this there is no movement on the gauge.

That might be the easiest way, I will be including a MCU for mqtt reporting of the battery to my Home Assistant instance. Keeping both functions seperate might be the way to go.

Speaking of the battery, it’s 36v nominal but will vary from 30v (cutoff/flat) to 42vdc (fully charged).

So, how to build a circuit that supplies a signal of 6-10.5v based on the battery voltage of 30-42vdc?

1 Like

Hi @gogreenpower

You could still use a voltage divider for this with different values, changing out the 20KΩ for a 3.3KΩ and the 5.1KΩ for a 1KΩ will give you 6.96V at 30V and 9.74V at 42V.

While it isn’t going to be exactly the right voltages for the gauge its going to be pretty close.

1 Like

I’ll play around and see where these values put the needle. But I’m not gonna lie, it will need to be on or over the full and on empty at the low end. Might have to go down the MCU route otherwise

A bit difficult.
At the 42V end your division ratio is 4 while at the 30V end your division is 5.
A voltage divider has a fixed division ratio and so is linear.
I see no reason why the meter movement should not be linear.

The only reason I can see is the use of a potentiometer to apply a varying voltage to the meter. The outcome here would be the meter resistance in parallel with the lower half of the divider and so alters the ratio of the pot as doing it this way you are effectively changing the value of 2 resistors.

If you can determine the resistance of the fuel gauge you would have a chance of calculating the required resistance.

Another method which would give closer results would be to make a divider with fixed resistors then apply a variable voltage (say 25V to 45V) to this divider and log the result and adjust from there. This will NOT be the same as using a potentiometer but will be closer to the real world application. But you will need a variable supply to do this. Most bench supplies only go to 30V but if a dual supply there should be provision to connect the 2 in series. If you do this measure the voltage applied to the top of the divider NOT at the meter input.

Another point. This meter will be designed to operate with a particular tank “sender” unit with the appropriate scale. The tank unit might be connected as a rheostat and not a potentiometer. I don’t know how these things work these days. It can’t be just a resistance and series meter as the reading would go up and down with battery charging voltage. Is the printed meter scale linear ?? Maybe not .

All good fun.
Cheers Bob

Would a DC motor controller work? Something like this DRV8838 Single Brushed DC Motor Driver Carrier | Buy in Australia | POLOLU-2990 | Pololu | Core Electronics ?

Hi gogreenpower

I don’t know what a DC motor controller has to do with your current project.

Basically I think what you need is something like this.


This is just a sample of what I think would work. Basically it is a 1mA full scale deflection (FSD) meter movement configured as an expanded scale voltmeter. With the example shown it will read from 30V (zero) to 42V (full scale).

To configure your meter we need to know something about it.
Are there any markings on the scale like “fsd” or a type number.
Where does the needle come to at rest with no power applied at all. Below “Empty” or at the Empty mark. It is quite possible it has some sort of zener built in as you say it reads empty at 6V
Need to know some more things so if you can could you set it up like this.


If possible use a variable voltage supply. DO NOT use a potentiometer unless there is no other way. If the voltages are too low for reliable measurement increase the resistor to 10k or 5k. Use 1% or better types. Just note the value.

Measure and record the voltage at “A” and “B” under the following
Zero voltage applied (should read “0”
With the meter needle on Empty.
With the meter needle on Full.
With the meter needle as far as it will go (Full scale) in the case of this point being above the “Full” mark.

This should tell pretty much just what that meter is and if it could have a zener or something else built in.
Cheers Bob

Hey @gogreenpower

Another thing to bear in mind is that both LiPo and LiFePo4 batteries don’t have a linear voltage in relation to their remaining charge.

Generally speaking the output voltage will drop significantly between 100% and 80% with then very little change in voltage until ~20% where the voltage drops rapidly. Below is a graph for a single cell LiPo, the graphic will maintain a similar shape with increased cells just with the voltage increasing.

I’d say that with the gauge you have it would likely display that it is on the upper end of full most of the time before rapidly dropping down.

Hi Dan, gogreenpower

I would agree with that. But gogreenpower seems keen on trying to use this “fuel gauge” which sounds a bit ike an automotive device.

I am not convinced it is going to work too good. I don’t think this meter is a straightforward moving coil meter. I believe there is some other skulduggery going on. I think the fuel gauge system in my car is a series of pulses of some sort but how this is processed at the end of the day is anybody’s guess.

That is why I have asked gogreenpower to do the few measurements, to give us a better idea of what this meter actually is.

Even if this meter does work it will be a basic volt meter and as such will be a linear measurement. As you point out, the discharge of a Lithium cell is anything but linear and this meter is probably going to spend most of its life at about 3/4 full with a rapid decrease at the end.

I don’t quite know how these LED “fuel Gauges” work. Like the 4 indicator LEDs on a power bank. The first one and the last one might be close to the mark but I think the 2 middle ones are an educated guess. I must try to find out how they do this one day soon. The only way I could guess is they know the mAhr capacity to start then measure the mAhr usage and work on that. But that would depend on a complete charge every time. Or they might use a VERY sensitive volt meter.

e will see what these measurements I asked for show up.
Cheers Bob

Side math.

Based on a liner conversion
6V - 10.5V from 30V - 42V

The formula to convert from Battery Voltage Vb to meter (drive) voltage Vm ie get.

Vm = (Vb * 0.375) - 5.25

(edit updated to match 30-42 volt rage)

Hi Michael

All good if it was linear
The upper battery voltage is 42V not 40V which becomes non linear.
I think there might have been a measurement problem using a pot as a variable voltage divider to provide a variable voltage. This would be greatly affected by the meter resistance. But there is something funny going on which might become clearer when the results of the measurements I requested are known. If the meter is a moving coil type it should be linear. Something was not so with that measurement.
Cheers Bob

Ops my bad, I update the post to reflect the correct formula based on the 30-42 V range.

Thanks for point that out.