1

I am getting analog voltage data, in mV, from a fuel gauge. The calibration readings were taken for every 10% change in the fuel gauge as mentioned below :

0% - 2000mV
10% - 2100mV
20% - 3200mV
30% - 3645mV
40% - 3755mV
50% - 3922mV
60% - 4300mV
70% - 4500mv
80% - 5210mV
90% - 5400mV
100% - 5800mV

The tank capacity is 45L.

Post calibration, I am getting reading from adc as let's say, 3000mV. How to calculate the exact % of fuel left in the tank?

Enihr
  • 299
  • 1
  • 3
  • 12
  • 1
    This is a question of statistics not one of programming. To make it one of programming, you might indicate (with some code) how you are reading the ADC - single instantaneous values are probably inadequate - some sort of sample averaging or signal conditioning is probably required. Moreover, if the result you want is in %, then there is no purpose in first translating your ADC readings to mV - plot ADC vs fuel level - voltage is irrelevant, and the conversion will only introduce unnecessary and avoidable rounding error. – Clifford Jun 30 '19 at 20:32

2 Answers2

4

If you plot the transfer function of ADC reading agaist the percentage tank contents you get a graph like this

enter image description here

There appears to be a fair degree of non linearity in the relationship between the sensor and the measured quantity. This could be down to a measurement error that was made while performing the calibration or it could be a true non linear relationship between the sensor reading and the tank contents. Using these results will give fairly inaccurate estimates of tank contents due to the non linearity of the transfer function.

If the relationship is linear or can be described by another mathematical relationship then you can perform an interpolation between known points using this mathematical relationship.

If the relationship is not linear than you will need many more known points in your calibration data so that the errors due to the interpolation between points is minimised.

The percentage value corresponding to the ADC reading can be approximated by finding the entries in the calibration above and below the reading that has been taken - for the ADC reading example in the question these would be the 10% and 20% values

Interpolation_Proportion = (ADC - ADC_Below) / (ADC_Above - ADC_Below) ;    
Percent = Percent_Below + (Interpolation_Proportion * (Percent_Above - Percent_Below)) ;

.

Interpolation proportion = (3000-2100)/(3200-2100)
                         = 900/1100
                         = 0.82

Percent                  = 10 + (0.82 * (20 - 10)
                         = 10 + 8.2
                         = 18.2%

Capacity                 = 45 * 18.2 / 100
                         = 8.19 litres 
uɐɪ
  • 2,540
  • 1
  • 20
  • 23
  • Wow! Thanks for explaining this in such a lucid manner. Can't appreciate enough. Let me try out. – Enihr Jun 28 '19 at 10:04
1

When plotted it appears that the data id broadly linear, with some outliers. It is likely that this is experimental error or possibly influenced by confounding factors such as electrical noise or temperature variation, or even just the the liquid slopping around! Without details of how the data was gathered and how carefully, it is not possible to determine, but I would ask how many samples were taken per measurement, whether these are averaged or instantaneous and whether the results are exactly repeatable over more than one experiment?

Assuming the results are "indicative" only, then it is probably wisest from the data you do have to assume that the transfer function is linear, and to perform a linear regression from the scatter plot of your test data. That can be most done easily using any spreadsheet charting "trendline" function:

enter image description here

From your date the transfer function is:

Fuel% = (0.0262 x SensormV) - 54.5

So for your example 3000mV, Fuel% = (0.0262 x 3000) - 54.5 = 24.1%

For your 45L tank that equates to about 10.8 Litres.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • Hi, Thanks for your response. However, I didn't quite understand how you arrived at 0.0262 and 54.5. Can you break it down please ? – Enihr Jul 01 '19 at 10:38
  • It is done by linear regression, but I did not do the math because the spreadsheet software did it for me. Equation of a straight line is y=mx+c – Clifford Jul 01 '19 at 11:04
  • @Enihr : If you really want the maths: https://en.wikipedia.org/wiki/Linear_regression, but really Excel or Google Calc or whatever will have a _Show Trendline - Linear_ option on their charting functions, with an option to show the equation on the trendline. – Clifford Jul 01 '19 at 20:51