Controlling analogue fuel gauge with arduino

Thread Starter

killerpiraat

Joined Feb 17, 2020
18
For a demo model i want to control a analogue fuel gauge with a PWM signal. I want it to move slowly up and down and repeat.

Normally the gauge is connected to a sender, which is simply a variable resistor between 0 and 190 Ohm (EU, US is 240 -10 ohm). R2 is the sender, which is not present in my case and will be replaced by some electronics. R1 is mounted inside the gauge and the needle of the gauge is practically a voltmeter which measures the voltage over R1.
0 Ohm is empty, 190 ohm is full.

1697530064303.png

So my goal is to create a variable resistance between 0 and 190 Ohm controlled by a PWM signal.

A mosfet does sort of work, except that it is not accurate enough to make the resistance between the Drain and Source move between 0 and 190 ohm.As soon as the fet becomes active or inactive it jumps up or down.

How can i create a good variable resistance, controlled by a PWM signal, without to much hassle? I know there are some digital potmeters like this, but that will require a lot of more work.
https://www.microchip.com/en-us/product/mcp41010#document-table
 

Jerry-Hat-Trick

Joined Aug 31, 2022
494
Could you simply replace the sensor R2 with a transistor? When turned on it's (almost) equivalent to zero ohms, turned off it's essentially an open circuit, so actually leave R2 in parallel with a fixed resistance of 190 ohms. If you are using a processor like the Arduino to produce the PWM signal you might want to linearize the meter movement with a lookup table or a formula calculation as fuel gauges can be horribly non-linear, but that's fine tuning...
 

crutschow

Joined Mar 14, 2008
34,050
Generating a controlled variable resistor with any degree of precision is difficult.
Much better to have the PWM signal rapidly turn a MOSFET ON and OFF as suggested, to generate a variable (average) current.
 

Alec_t

Joined Sep 17, 2013
14,224
That would depend on the output current capability of the PWM source. Analogue car gauges need quite a few tens of mA. They do have significant inertia, so filtering probably wouldn't be necessary.
 

MisterBill2

Joined Jan 23, 2018
17,827
If R2=zero indicates empty, then that is 12 volts across the gage to show empty. That is difficult to immagine and probably a challenge for a series transistor. So you are stuck with using a PWM scheme, with 100% being one extreme. So you will be feeding the control transistor, with the current unknown.
To have a stable meter indication the PWM frequency will need to be above any mechanical response ability of the gage.
 

geekoftheweek

Joined Oct 6, 2013
1,183
I tried this once before by simply connecting a MOSFET in series with the gauge and using a PWM signal to switch it on and off. Long story short it didn't work very well. At high frequencies it wouldn't have enough off time to cool and the gauge just kept raising. At lower frequencies it was not as bad, but it would hum. It was not at all a linear response or even a somewhat decent curve.

I wish I would have thought to try a resistor in series as suggested in #2. That sounds like it might just work.
 

MisterBill2

Joined Jan 23, 2018
17,827
That does not sound like what I would expect from a PWM scheme, that sounds like a variable frequency square wave. As the portion of on time is reduced the energy delivered is reduced and so the heating will be reduced. Pulse Width Modulation varies the portion of ON time relative to the whole cycle time. That is totally different from just varying the cycle time.
 

geekoftheweek

Joined Oct 6, 2013
1,183
I understand all that... I was simply saying that in my case it didn't work as I expected it would. I tried with different frequencies and duty cycles with no reliable results. I may have just been the gauge I was using so I'm not saying it won't work for someone else.
 

BobTPH

Joined Jun 5, 2013
8,665
R2 is essentially sinking a variable amount of current. Using a voltage controlled constant current sink circuit controlled by a filtered PWM voltage should do the the trick. It would have to be calibrated to get uniform movement of the meter.
 

Ian0

Joined Aug 7, 2020
9,507
I don't see any advantage in filtering. Even moving-coil meters can be driven with pwm and the intertia of the coil and pointer integrates it provided that the pwm frequency is high enough.
A hot wire meter will integrate over a long period of time.
As the meter has a fixed resistance (I think it does) then just connecting it across the supply will give it a constant current.
If it needs the sensor resistance to be short circuit in order to read full, then it must be driven that way.
 

BobTPH

Joined Jun 5, 2013
8,665
I don't see any advantage in filtering. Even moving-coil meters can be driven with pwm and the intertia of the coil and pointer integrates it provided that the pwm frequency is high enough.
A hot wire meter will integrate over a long period of time.
As the meter has a fixed resistance (I think it does) then just connecting it across the supply will give it a constant current.
If it needs the sensor resistance to be short circuit in order to read full, then it must be driven that way.
Well, we do have one poster who says he tried that and it was unworkable. I have no experience with them, so the best I can do is approximate what the resistive sensor was doing. I would be nice to know at least the range of resistance of the sensor and the range of currents as it varies. Someone said 10s of milliamps, so we know the order of magnitude.
 

Alec_t

Joined Sep 17, 2013
14,224
What is the measured resistance (R1) between the +12V terminal and the sensor input terminal?
If you have a ~190 Ohms resistor connected from the sensor terminal to ground and the gauge powered, how long does it take for the needle to move from 'full' to 'empty' when you short out the resistor?
 

Sensacell

Joined Jun 19, 2012
3,400
How about using a "gated current sink"?

A single transistor current sink is adjusted to provide full-scale deflection of the needle when on 100% - a fixed constant current.

Then apply the PWM to turn the current sink on and off at some higher frequency.

Should provide decent linearity, and good power supply rejection, the power dissipation should be constant regardless of supply variations?
I think most attempts at PWM just blast the poor thing with full supply voltage, leading to premature failure and poor linearity.
 

Ian0

Joined Aug 7, 2020
9,507
Well, we do have one poster who says he tried that and it was unworkable. I have no experience with them, so the best I can do is approximate what the resistive sensor was doing. I would be nice to know at least the range of resistance of the sensor and the range of currents as it varies. Someone said 10s of milliamps, so we know the order of magnitude.
I’ve tried it recently with moving-coil meters and it works. I have driven a hot wire meter electronically, but so long ago I forgot how I did it.
Considering that the “instrument voltage regulator” on old cars was a bimetallic strip oscillator with a period of seconds I think that should be enough evidence that it integrates!
 
I wish I would have thought to try a resistor in series as suggested in #2. That sounds like it might just work.
It might help to know the resistance of the gauge. If it's a hot wire/bimetal gauge it should remain reasonably constant through the range of readings although it will go up a little as it gets hot. The advantage of the hot wire/bimetal gauge is it's simplicity in the days before automotive electronics and because of a significant thermal/mechanical lag the needle doesn't jump about when the vehicle is moving over rough terrain.

Depending on the gauge you are using it may be that the circuit was powered by a (rudimentary) voltage regulator which, in the old days, was a similar hot wire/bimetal device which clicked in and out to give an average 10V because the battery voltage can vary depending on the charging voltage of the dynamo with speed. Alternators have their own voltage regulation so the voltage across the battery will rise to around 14.5V when being charged.

Just to be clear, my post #2 meant that the sensor resistor R2 should be replaced with a fixed resistor of 190R (maybe 10R in series with 180R to use standard values) and the transistor should be in parallel with R2 so that the PWM signal turns it on and off with varying mark/space. The Arduino UNO PWM frequency is 490Hz which should be fine. If you use analogWrite(Tr,0); so the transistor doesn't turn on the circuit will see 190R in series with the gauge; if you use analogWrite(Tr,255); it'll be effectively zero ohms in parallel with 190R. A loop to ramp from 0 to 255 should show a steadily rising meter needle. Put delay(1000); between each step to give the meter time to catch up. You can change this delay to be longer or shorter to see how it responds.

Without the fixed value of R2 in place I still think it should work to some extent but depending on the resistance of the gauge you may have only a small range of PWM mark/space for it to work. For example, suppose the resistance of the gauge is 190R in which case I think a mark/space of 50/50 would show tank empty.
 
Top