Creating PWM signal with low level resistance as analog input

Hi all,

i want to use a fuel level sender and use those resistance values to create a PWM to drive a mosfet to make a more accurate fuel gauge and eliminate fuel slosh as much as possible.

But the analog input value only ranges between 3.53V (91Ohms) for full position and 4.91V (3.94Ohms) for emtpy.

I have looked and tested several script but as long as i do not get a decent voltage range between 0 and 5 V this doesn't work.

How do i go about this?

What doesn't work? What do you mean by "doesn't work"? What happens and what did you want to happen?

(I should not really have to ask you these questions. Have you read the forum guide?)

I am using the fuel gauge as an unknown resistor so the Arduino can constantly measure the change in resistance. Because the sender just has a range from 3 to 90 Ohms the input voltage on the analog channel will not drop enough so i only have a range from 3,53 to 4,91V

Or am i doing something terrably wrong here. I want to use the analog in to create an analogOut.

Could you point me to the forum guide? there is a lot on here, not seeing it at the moment

thank you

Analog input setup as a votage devider with a 220Ohm as the fixed resistor

That will give you a reading between about 722 and 1004. That's a range of around 282 values, enabling you to estimate the fuel level to about 0.35%. Isn't that enough?

If i could understand how to use these numbers to control PWM range..
it is indeed 723 to 1005.

Could you help point me in the right direction?

Ah, maybe I'm starting to understand what your problem is.

You're getting a value from 723 to 1005. You want a value between 0 and 255 to use with analogWrite()?

analogWrite(PWMpin, map(analogRead(analogPin), 723, 1005, 0, 255));

It's in the sticky posts at the top of almost every section of the forum.

Wa!

that did the trick! so simple actually but if you are looking at it too long you do not see it anymore.
I was only focussing on the voltage range input and thinking about ways to modify resistance, even getting another level sender with a higher range resistance

Now how to setup a non-linear output in relation to a linear input...

If it's non linear, what is the relationship?

Can you express it in terms of a mathematical formulae?

If not, can you express it accurately enough as a series of linear relationships over different value ranges?

The best i can put it is that the gauge works on the principle of the amount of current it is being fed. The more current can pas through the more the needle moves to empty. At 255 PWM the needle is spot on at Empty, but at 0 PWM it goes way beyond Full. I have to change from 0 to 85 to be at the original position but the scale does noet make any sense anymore. Full to half is very sensitive and when the needle is at 1/4 the sender is in the middle position

Tomorrow i will try and setup formula in relation analog to pwm

You could power the sender through a 220 ohm resistor from the 3.3volt supply, and swith Aref to 1.1volt in setup(). That will give you about 900 A/D values to start off with.

Multimap() could convert the A/D values into the correct PWM values.
Maybe you should also use a 3.9 ohm (3W cement) resistor (for safety) in the drain line of the mosfet.
Leo..

So you could...

  • make a voltage divider from 3 volts with one leg your sensor
  • read the divider voltage with an analog input in your arduino
  • do what ever calculations you need to ***
  • output this to the gauge.

*** by the way, the level sensor algorithm is the largest code section in an automobile's ECU code. Literally. We built fuel modules that includes the level sensor so I've an experience in this area.

@Wawa i tried this but gives me a much smaller resolution to work with

I can experiment with the Multimap function but i still have a lot to learn.
So it can be possible to send out a different range PWM in relation to the AnalogIn?

@JohnRob what exactly do you mean with 'one leg your sensor'?

i would be much appreciative if you could assist me with the calculations.
Physically using the fuel sender with gauge as intended i works spot on.
The use of Arduino will be getting the fuel slosh out so the needle will not follow the sender.

As i have it now with a resolution of analogWrite(PWMpin, map(analogRead(analogPin), 723, 1005, 0, 255)); as per help of @PaulRB the needle goes beyond the Full mark so has to be trimmed back but that throws off the reading of the complete scale..

Not according to my calculations.
Try this sketch (untested).
Leo..

// 4-91ohm fuel sender test sketch for UNO
// 200 or 220 ohm resistor between 3.3volt pin and A0
// fuel sender between A0 and ground

int rawValue;

void setup() {
  Serial.begin(9600);
  analogReference(INTERNAL); // switch to 1.1volt Aref
}

void loop() {
  rawValue = analogRead(A0);
  Serial.println(rawValue);
  delay(500); // dirty delay
}

I think you need to make some calibrations.

  1. Starting with an empty tank, make a note of the analogRead() result (==723), then fill it with, say, 5 litres, note the reading again and repeat until the tank is full (==1005). Make a table of litres-of-fill vs the reading.

  2. Connect a pot to an analog pin and write a simple sketch to control the PWM and write the PWM value to serial monitor. Connect this to the fuel gauge and adjust the pot to make the gauge read empty, 1/4, 1/2, 3/4 and full. Make another table of the PWM value for each gauge reading.

@Wawa with this i do get a higher range, from 95 to 730

@PaulRB good idea, will do this tomorrow.