Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Microcontroller-based resistor ladder for gas gauge

Menticol

Active Member
Hello everyone!

I'm working on repurposing a Chinese motorcycle dashboard for a racing simulator. I’ve successfully generated the 12V PWM signals to control the RPM and speedometer indicators as needed.

1730263919283.png


Now, I want to work on the fuel gauge. The gauge reads as "full" when its cable is shorted to ground and "empty" when it’s open. By precisely varying the resistance to ground, I aim to display intermediate levels such as 20%, 40%, and 80%.

The schematic below (apologies for the low quality) shows my approach. Each test point input is connected to an ESP32 micro-controller output, controlled programmatically. Only one transistor must be conducting at any given time.

1730263628048.png

Unfortunately, this circuit currently produces only random values on the gauge, and I’m not sure why. I’m aware this issue could be resolved with relays instead of transistors, but since I plan to use the same approach for the gearbox indicator, I would prefer to avoid the clicking noise and the wear and tear associated with relays on this application.

Any input (no pun intended) will be very appreciated
 
Last edited:
Fuel sender gauges are notoriously none linear. Try switching (and removing all others) one transistor at a time and gradually increase (resistance or number transistors turned on) until it starts to make sense.

Sorry can't be more help.

Mike.
 
Fuel sender gauges are notoriously none linear. Try switching (and removing all others) one transistor at a time and gradually increase (resistance or number transistors turned on) until it starts to make sense.

Sorry can't be more help.

Mike.
Good catch Mike! Indeed, the resistor values shift wildly between 0 and 96 ohm (I used 10 ohm imaginary resistor increments for diagram simplicity purposes).

The strange thing is, by using the resistors alone, the increases are perfectly predictable and repeatable. Only when the transistors are added the indication goes wild, from zero to 40% to empty to full. I wonder if the transistors are not properly saturated, or if they are adding their own resistance, throwing off the scale.

No need to stick to transistors. If you or any other collaborator has another way to accomplish this, it will be very welcome.

Thank you very much
 
I just noticed you have labelled all the ESP pins as INPUT - they should be outputs to switch the transistors.

There are chips which will behave like a resistor (google digital potentiometer). MCP4151 springs to mind. However these may be too high a resistance.

Mike.
Edit, I would move the resistors into the collector of the transistors and increment them (10,20,30 etc.) and ground the emitters.
Edit2. You could possibly use binary values of resistors (5,10,20,40 etc.) and put a binary value on the ESP pins.
 
Last edited:
I just noticed you have labelled all the ESP pins as INPUT - they should be outputs to switch the transistors.

There are chips which will behave like a resistor (google digital potentiometer). MCP4151 springs to mind. However these may be too high a resistance.

Mike.
Oh, that's a bad translation on my part. I meant that the ESP32 pins are configured as digital outputs, and are connected to each transistor base. But to make testing easier I temporarily got rid of the ESP and proceeded to inject 3.3v directly by hand, hence the test points. I wonder if 3.3 is enough to turn the transistor fully on.

Already checked digital potentiometers, but sadly only found 10K models
 
If you configure the outputs as open drain, scale the R's so not much current
is sunk in the output you can eliminate the transistors. Something like this -

1730292243906.png


The IRF530 just the symbol used for the ESP32 open drain configured outputs.

You can adjust the R's to emulate the non linearity of gas tank sensor.
 
A single transistor switch to ground & the lowest value resistor, fed with a PWM signal should work? If it does not work cleanly at that, you could add a 100uf ? cap across the circuit as well?

As long as the PWM frequency is high enough to keep the voltage at the gauge input constant, it should work as well as a proper sender.
 
Have you given any thought to just using an old LM3914. The chip can be set for dot mode and only needs a few external components.

Ron
 
Use a MOSFETs instead of BJTs.
The base current of the BJT may be affecting the readings.
 
Instead of shorting with a wire, use your meter set to amps and measure the current to short from test point to ground. How many amps is it.

Once we have that, setting up a 4 to 8 bit ladder is easy.
 
That can not be right are you sure you have to use 10 ohms most gas sensor are way higher than that
I wouldn't want to be heating gas with the senser at 10 ohm reading your 14 watts at Q1 you looking at a bomb LOL
 

New Articles From Microcontroller Tips

Back
Top