Microcontrolled variable resister control Ohm fuel gauge

You are still talking riddles.
I think you want something that tells an Arduino or similar how much fluid is in the tank. Then that Arduino or similar has to somehow emulate the 0Ω to 190Ω variable resistor to signal the level gauge.
You have not come up with a suitable sensor fo the tank yet. Also what size is this tank. Really have to know that before even considering a sensor. What is in the tank. This may have a bearing on the sensor type. And the list of unknowns goes on.
I have asked that you do a couple of measurements to establish what pin 2 may do.
What you mean by “no resistance” 0Ω or open circuit (no connection).
And a few other questions.
Had no results and all you do is prattle on about 5V meters (270º), digital pots (which may be valid), meters with bimetal strips (???), JFets, optocouplers, DAC and so on.
Maybe you should start again. Start with sensor. You already have one available that goes with the gauge but apparently that is not suitable. Without deciding on that and knowing what it expects in the way of supply if any and what it outputs I feel all this is useless and you are bashing your head against a brick wall.
Word of advice. You can’t successfully start a project in the middle and believe me I have worked on quite a few projects with a cost bottom line of many millions of dollars.

Hi Bob, I am intending on using a capacitance probe. That does not matter.
I have written code, which I can amend if/as required. (output to gauge 0-255 PWM)
Anyway, that is not what I am asking.
The fuel gauge that I have I attached owners manual in my second post.

I thought leccie had said that there was 30 MA. No, it wasn’t.
The readings in the table are what the leccie told me.
Open circuit means that the signal wire was not connected to ground, and voltage between signal wire and ground was 4.99 V, and there will be no current flow.
Yes, we missed reading the voltage with the 150 Ohm resistor.
The current reading with the 200 Ohm resister must have been incorrect (maybe loose connection during reading?)
0 Ohms, [empty] (no resister between ground and the signal wire)- signal wire connect direct to ground.

As I asked at the start, how to control a gauge with an item like an Arduino, where the gauge is controlled by resistance on the signal wire.

Kind regards…Rossco

Hi Ross.
Please accept my apologies. I completely missed that chart. Some of the numbers quoted in your original post did not compute so confused the issue a bit. I also did not realise you already had a suitable sensor and an Arduino programmed and could produce a PWM signal.
I re-calculated the mA figures from the resistance and voltage numbers. I have come up with the source impedance of the supply at pin 2 of the gauge as approximately 270Ω. I say approximate because the figures on the chart do not quite compute but are fairly close. I would have to know exactly how the measurements were taken to comment further. You have to be a bit careful when using a DMM for current measurements on the mA ranges as the internal meter resistance can be significant compared to the low values involved here and must be considered if accuracy is paramount. That is why Suggested the 10A range as this resistance is very small. In this case a close approximation will do.

It is now pretty clear you only need method of simulating a 0Ω to 190Ω variable resistor using Arduino.
I think there is a fairly easy way to do this. Connect a 190Ω resistor from pin 2 to ground. Now the idea is to shunt some of the available current around this resistor so a smaller current flows through it has a smaller voltage drop across it which would give the impression of a smaller value resistor. If this seems confusing don’t worry I am pretty sure it would work. It would be similar to another resistor in parallel with the 190Ω.
Although the current involved is quite modest it would probably be a good idea to use a logic level Mosfet to do the current shunting. Core have a device that can apparently be directly driven by Arduino, SKU: CE04538 which is a little board with the Mosfet and a couple of components on it. The connections are clearly marked.

So, connections:
190 resistor Gauge pin 2 to ground.
Connect Gauge pin 2 to Mosfet Drain (D).
Connect Mosfet Source (S) to Ground.
Connect Mosfet Gate (G) to Arduino PWM pin.
The theory here is that as the Mosfet gets turned on for longer (increase duty cycle) periods the average bypassed current increases which should decrease the apparent value of the 190Ω resistor. For instance at 50% duty cycle (PWM 127) the average current through the Mosfet should be half of available so half through Mosfet and half through resistor which should now look like 95Ω to the gauge.

The Arduino and sensor should not be powered from Pin 2 of the gauge as this will not be 5V but should be powered separately. Arduino and Gauge grounds should be connected together (Common)

Try this. As far as driving the gauge goes I am pretty confidant it will work. You made need a capacitor from gauge pin 2 to ground but I don’t think so. If you do start small, 0.47µF, 1µF. To big may cause unforeseen problems.

This may work in reverse. If so reverse the PWM mapping in your sketch. From say 0 - 255 to 255 - 0.

Let us know how you go.
Cheers Bob

So…let me get this correct.

You have a fuel gauge that requires a resistance type sender … IE the sender resistance varies from 0-190 ohms. ( Very common type )

You have a different type of sender,/sensor unit that you need to interpret the input from using a microcontroller…

You then need the microcontroller to replicate variable resistance to the gauge to show level…

You could do it several ways…

  1. Just get a display for the microcontroller and ditch the gauge. ( This has advantages of having a “custom” gauge )

  2. Use a digital potentiometer driven by the microcontroller

  3. Use the analog output pins ( 0-5v) to drive a transistor connected to the gauge that will essentially mimic the fuel sender. This will be fiddly to calibrate if you dont get your values corect

This what can be acheived

Hi Ross
Conducted an experiment to-day (Thursday) with 270Ω, 190Ω resistors, Arduino and one of those Mosfet boards mentioned above.
Results what I expected and described. Will not be home to-morrow so will record and post results with numbers on Saturday.
Cheers till then. Bob

Thanks, Bob.
Will look again over the long weekend. Might be a little while before I get to try, as having some leave, and other stuff to do.
Kind regards…Rossco

Use a device that can provide that variable resistance. The gauge is not going to respond to anything other than a resistance to ground. Supply of V or A or mA or PWM or anything else won’t make the gauge respond.

If you can’t find a suitable device then make one by connecting a stepper or servo to the shaft of a potentiometer, and drive the stepper or servo from the Arduino.

Or, use this:

Get 16 resistors of values between 0 and 190 ohm. Tie each output of the mux to earth through one of the resistors, arranged by value. Tie the gauge input to the common, and the data inputs to Arduino data outputs. The 4-digit value you put out to the mux from the Arduino will select one of the resistors as the path to earth for the gauge.

Hi Jeff
Agreed. To use that gauge the end result has to be a resistor variable from 0Ω to 190Ω or something that looks like this to the gauge.

Good call Jeff. I had not seen that unit but I also have not looked. I have yet to find the time to have a look at the whole Core inventory. Daunting task. I was think along the lines of a LED bargraph driver in dot mode. 2 in series would give 20 points but I think these things tend to control the current which we don’t want.

The unit you suggest would have 16points so 2 in series would have 255 which is good. whatever the input is from the sensor would have to be converted to 8 bit BCD but there are probably libraries to do this. I have not looked.
The down side to this unit is the quoted “ON” resistance of 70Ω. Now I am assuming that this is the resistance between common (sig) and the selected output (input). 70Ω is a significant part of 190Ω and if stable can be accounted for BUT this will be the minimum value to ground which could be attained. I think this might equate to something like the tank being about 30% full. In other words can never get to empty.

Although a bit messy the same thing could be done with an Arduino driving logic level mosfets in a BCD manner, switching resistors with BCD weighted values. If 30 points are enough 5 bit (5 Mosfets) would do. Values would take a bit of working out but can be done. Advantage is Mosfets only have a few mΩ ON resistance.

I have done an experiment with a PWM switched Mosfet across the 190Ω resistor and used an arbitrary 270Ω to represent pin 2 source impedance. This shunts a proportion of the current around the 190Ω resistor and looks like a variable resistor in parallel with the 190Ω. Value from ∞ to 0. Seems to work well with an important proviso. The gauge works have to respond to the AVERAGE voltage produced by the 190Ω/Mosfet combination. If not and the gauge is trying to follow the PWM pulses back to the drawing board. The Arduino I used has a pretty modest repetition rate of ≈ 1kHz. Increasing this to 2 or possibly higher kHz may improve this tendency but would have to generate your own PWM signal. Not hard to do.
As a matter of interest I also lashed up a 1mA meter with a 2k4Ω resistor (100Ω in meter) to finish up with a 2.5V FSD Analog meter of 1kΩ / V. As anticipated this arrangement averaged out the pulsed voltage quite nicely. But it is the ballistics of the meter movement doing this. Not magic.
Will post the details of this experiment later this week end.
Cheers Bob

Hi all.
Apologise for delay but had a skin graft on the bridge of nose and wearing of spectacles quite uncomfortable.
However. Results of experiment described above.
Arduino: Duemilanove (old), powered separately via USB. Analog input from Arduino 5V output via 10kΩ / 10 turn potentiometer with turns counter fitted. Both Bourns brand, good linearity and repeatability.
Test set up: As previously described. Separately powered. Voltage (V) and current (mA) monitored with USB tester Ruideng AT34. Oscilloscope connected across 190Ω and Mosfet and set up to read peak V (VPk), Average V (VAvg) and negative duty cycle (-DC). Frequency indicated at just under 1kHz. Voltage remained at 4.99V.
Pot pos 0 turns, 2.08VPk, 2.08VAvg, 10mA, 0% Duty Cycle
Pot pos 2.5 turns, 2.08VPk, 1.52VAvg, 12mA, 25% Duty Cycle
Pot pos 5.0 turns, 2.08VPk, 1.04VAvg, 13mA, 50% Duty Cycle
Pot pos 7.5 turns, 2.04VPk, 0.50VAvg, 15mA, 75% Duty Cycle
Pot pos 10 turns, 0.0VPk, 0.0VAvg, 17mA, 100% Duty Cycle.

As you can see the average V is quite linear over the 0 to 100% range.
If the gauge responds to this average I think this is the simplest way to go. You will be effectively putting what looks like a variable resistor across the required 190Ω. You will have to try it and see. This should be a simple enough trial using a potentiometer instead of any sensor. This would prove whether or not this approach would work.

If it does not work and the variable resistor method is the only option there is a way!!!
Thanks to Jeff’s prodding of the old grey matter a binary approach could be used.
I have a suggestion in mind which would require 6 Arduino digital pins, 6 small 5V relays driven by a darlington relay driver array IC and 6 resistor values. These values may be a single resistor or 2 resistors in series/parallel to get the required value.
These resistors could be switched into a series circuit in a binary sequence to give you a value between 0Ω and 190Ω in 38 steps of 5Ω increments.
You recently implied that anything over 30 steps would be OK so this will give you 38 steps.
To do this at the end of the day the ADC numbers produced by your sensor from empty to full have to be 0 to 38. This would normally be done by re mapping.

Tank linearity. This is a bogeyman. How critical is it? Most fuel gauges I have seen (mostly automotive) have not been super accurate by any means. An indication at best. Only you know what the tank shape is and what accuracy you need. If you are going try to manipulate numbers I think this should be done at the 0 to 1024 ADC level before any re mapping to give you better control. I think it will be difficult to make a part of the range non linear and the rest remain linear. I was thinking the easiest way may be to make a new scale for your gauge if correction is really required. Something like the AC scales of an analog multimeter. The meter actually reads peak volts but is converted to RMS simply with the scale marking. The lowest range is usually non linear at the bottom end to allow for the non linearity of the rectifier diode at the low voltage levels.
I will post my suggested circuit in the next few days (when I draw it).
Cheers Bob

Hi all.
Here is my suggested circuit to get binary control of 0 to 190Ω resistor in 5Ω steps (38 steps).

The IC is a Darlington transistor driver suitable for inductive loads with built in reverse voltage suppression diodes.
The relays are nice little pcb mount 5V relays with 2.54mm standard pin spacing
Obtainable from Alltronics. IC cat no Z3010, Relay cat no S411. Resistors probably obtainable from Altronics and certainly over the counter from Jaycar.
With zero input all resistors are shorted and gauge pin 2 is grounded (empty). As input is increased from “0” to “38” the relays are switched in binary sequence thus inserting resistors into the circuit to result in 38 steps of 5Ω until max “38” is reached. At this point you can see that bits 6,2 and 3 (32+4+2=38) are high operating relays 6, 3 and 2 inserting R6,3 and 2 into circuit. 160Ω+20Ω+10Ω+190Ω. There would now be 190Ω from gauge pin 2 and ground (full). This binary sequencing adds up for all values 0 - 38.
I believe this may be what you are looking for.
Cheers Bob

The trick now is to get the values 0 to 38 into binary form and onto 6 Arduino digital pins 1 (high) active. There must be some Arduino Gurus out there who have an easy way to do this. I think I can think of a long winded way which I may experiment with if I get time. Even for my own interest I would like to know how to do this.

Thanks Bob.
Do you have to use the IC.
Can you just use 6 output pins, or would this be too much current for the MCU?

Hi Ross.
Maybe not, but for the convenience of being safe and the required diodes being built in I believe it would be $5 or so well spent. Very easy to use, All 8 channels are straight through connections. Ch1 in pin i, out pin 18 etc. Some relays have built in diodes in which case one has to be very careful with polarity. The spec sheet for these has no mention of diodes.
Cheers Bob

Hi Ross.
Add on to yesterday’s post.
Another reason for playing safe by using a relay driver.
Arduino is quoted as supplying ??mA per digital output. Also is a figure for maximum device output which is nowhere near the per pin figure multiplied by number of pins.
Most of the time there will be more than one relay operated. In fact the number “31” requires 5 relays operated at the same time. This total could approach or exceed the device capabilities.
I have seen in the past the opinion that diodes are not required when driving relays directly from Arduino as pins are returned to ground in the LOW state. That may well be but for about $0.05 each I tend to err on the safe side and use them. Be aware the reverse voltage spike generated by the collapsing field can be many times the value of the original operating voltage. 50 or 60V or even more in some cases.
Nowhere yet have I seen which Arduino you are using. I have been assuming 5V logic. I am not sure but I thing some may be 3.3V logic or a mixture.
Cheers Bob

Hi Bob
At this stage have not decided on which MCU.
Leccie down town has made (not sure of names) items where he has piggybacked a chip onto device to program and then put this onto a PC board. Device that we were testing on was 5 Volts.
Regards Ross

So you don’t know what you are going to use!!! Nice to find out now.
So who are we dealing with here. You or “leccie down town”???
So leccie down town should know how to interface with your gauge.
So Have I been wasting quite a bit of time trying to interface an Arduino with your gauge when you may not even use an Arduino.
This sort of thing is hard enough to do remotely without having any idea of your level of expertise and never having set eyes on your gauge device. Now you tell us that

Well I wish you and “leccie down town” lots of luck but at this stage I feel that I have to withdraw from this conversation as I now don’t know what you are really trying to do.
Good luck

Thank you Very much for your information that you have provided Bob. Much appreciated.
I have always said controlled by a microcontroller.
Have been testing on an Arduino though.
Like I said, much appreciated, I would not have thought of 5 Ohms resisters in step.
I have been learning and do the code, then going to his place to test when he has a spare time (He is studying ATM)
Kind regards…Ross

Controlled by a microcontroller understood.
But which one?
I always thought Arduino so have been thinking along these lines. But there are also lots of different flavours of these too. Which one??
Then you come up with something that you and Leccie down town are playing and testing with.
Without knowing and having some surety about what you intend I am afraid I have to give in.
Cheers Bob

Hi Ross.
One more step. I have experimented with Arduino re outputting binary on the digital I?O pins. It turned out far simpler than I anticipated.
It seems there is no need to type HIGH or LOW to switch pins on or off. “1” or “0” works just as well.
The “bitRead” command returns a “1” or “0”.
I tested the following sketch using a potentiometer as I don’t have your sensor and it works well. Herewith sketch:
//Sketch to output Binary value of a number to Digital I/O pins Arduino:
//Bob Rayner 13/04/21:

//Assign pin names:
const int Bit0 = 2;
const int Bit1 = 3;
const int Bit2 = 4;
const int Bit3 = 5;
const int Bit4 = 6;
const int Bit5 = 7;

int potpin = 0; //analog pin used to connect potentiometer
int val; //variable to read the value from the analog pin

void setup() {
// put your setup code here, to run once:

//Declare assigned pins as outputs:
pinMode(Bit0, OUTPUT);
pinMode(Bit1, OUTPUT);
pinMode(Bit2, OUTPUT);
pinMode(Bit3, OUTPUT);
pinMode(Bit4, OUTPUT);
pinMode(Bit5, OUTPUT);

Serial.begin( 9600 );


void loop() {
// put your main code here, to run repeatedly:

val = analogRead(potpin); // reads value of pot (between 0 and 1023):
val = map(val,0,1023,0,39);// scale it to use with resistor ladder:
//Note map is 0-39. There are 38 steps required and mapping did not toggle:
//to 38 until 1023. mapping to 39 results in 38 distinct areas:

//Samples input number (val) and writes binary value to relevant bit output pin. High active (1):
digitalWrite(Bit5, bitRead(val, 5));
digitalWrite(Bit4, bitRead(val, 4));
digitalWrite(Bit3, bitRead(val, 3));
digitalWrite(Bit2, bitRead(val, 2));
digitalWrite(Bit1, bitRead(val, 1));
digitalWrite(Bit0, bitRead(val, 0));
delay(1000);// Delay to sample every second. Change to suit requirement:

//Print info to serial monitor for diagnostic or check purposes. Comment out when not required:
Serial.print(", “);
Serial.print(”, ");

Sorry it would not upload as a sketch. There must be a way of doing it as others have done it OK. Copied via clipboard as text.

So there you just about have it. What you have to do now is interface your sensor with Arduino, re map ADC output to 0 - 39. Use this sketch and the output interface circuit I produced previously and you should be in business.

Note. I had to re map to “39” as 38 did not toggle until ADC reached 1023. Doing this provides 38 clearly defined sections of the range.
Cheers Bob