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.



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.


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:
Solution
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.
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:
Solution
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 -



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.
 
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
 
Hello guys

Apologies for the delay, and sorry for taking the photo with my ass—I had to manage the accelerator with one hand and the phone with the other. But I’m happy to report that it’s finally working!

A big thank you to Pommie, Danadak, Rjenkinsgb, Reloadron, Crutschow, and ZipZapOuch for your invaluable input.

I started with Pommie’s solution, which was to dismantle everything and test small sections of the circuit individually. Turns out I made a silly mistake—I thought I was using 1k resistors for each transistor base, but they weren’t. In my defense, I was using those difficult-to-read 5-band blue resistors instead of the tan ones I’m more familiar with.

That said, your other suggestions were still helpful! I plan to revisit Danadak and Rjenkinsgb’s ideas if I decide to build a simplified version, as they could significantly reduce the Bill of Materials.

I tried measuring the resistance between the fuel gauge and ground as ZipZapOuch suggested, but my multimeter showed infinity.

Be80be, you’re absolutely right—the 10-ohm value was only for simplicity in the diagram. The actual values will vary for each meter. As Pommie pointed out, the system is highly non-linear, so expect some trial and error—and frustration.

Having the fuel sorted out the next challenge was the gearbox indicator, which has six wires, each corresponding to digits 1 through 6. Reloadron’s suggestion of using the LM3914 reminded me of the ULN2004, so I decided to try it. I connected each wire to its respective OUT terminal. Unfortunately, I ran into an issue: when applying voltage to IN 2, digit 2 lit up as expected. But applying voltage to IN 3 also lit up digit 2 again! Meanwhile, IN 4 worked correctly, as did 1, 5, and 6. I tried another LM3914, but the issue persisted. In the end, I resorted to using an awful lot of NPN transistors.

My last issue is the speedometer not showing a constant speed, but shaking readings. Probably is a code error, or my ESP32 not generating stable enough PWMs.

Anyway, I hope this may help to ayone building their racing rig.

 
Last edited:
I thought I was using 1k resistors for each transistor base, but they weren’t. In my defense, I was using those difficult-to-read 5-band blue resistors instead of the tan ones I’m more familiar with.

To be fair, 1% resistors are all but impossible to read, it hard to know which end is the start, and the colours are often impossible to distinguish, even under magnification.

For manufacturing I keep them in labelled boxes (expensive Really Useful boxes), so I never have to read the colours - for anything not labelled, or if there's any doubt, I stick them on a meter and measure them.

It's annoying, 50+ years of reading colour codes, and now it's a pretty useless skill to have
 
The shaking readings is because your making PWM the speed meter was reading a decoder off the crank shaft.
You could store say 20 readings and average them to get is better.
 
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
You can add a fuel tank module's float resistor to the input of a cascadable LM3914 for a precise readout from each output pin, in either mode. While the resistor element may be challenging to remove and modify, it's readily available from many sources and in many resistance ranges.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…