Help with maths/conversion formula?

I want to read a value from an oil pressure sensor, but I don't know how to convert the analog input values to meaningful data.

The following image is part of the manufacturer's data sheet:

I plan to use a simple voltage divider circuit to read the signal into an analog pin, so that part's not an issue. I'm more concerned about converting the 0-1023 values to something that matches the sensor values (0-5bar) according to the Characteristic curve described in the image.

I suppose I could just make some simple comparison values so that if the analog-equivalent-of-the-resistance is within a certain boundary, then I can declare that value as 1, 2, 3bar etc. But what I don't have any clue about is how to interpret the formula described for the Characteristic curve. I never studied maths past the age of 15 so I'm completely out of my depth here. Can anyone shed any light on where I should start?

Post a link to the data sheet. The image does not define the meaning of some of the symbols.

However, the image you posted gives a characteristic curve, which presumably converts the "typical" sensor resistance to a pressure value. It would be best for you to calibrate the sensor yourself, which means to determine the resistance at various known pressures, and work out the characteristic curve that fits best.

We can help if you want to take the latter route, but post the data sheet first.

1 Like

I think the resistive divider is an issue - if the sensor is one leg of the divider, the voltage output won't be just linearly related to the sensor resistance.

1 Like

The sensor resistance is easy to calculate from the divider reference resistance, and the ADC measurement, but the formula depends on how the divider is wired.

Unfortunately, if the sensor resistance is as low as the posted data suggest, the voltage divider will consume a great deal of power.

The low resistance can be handled with a bit of real circuitry. I just googled "low ohm measurement", above my pay grade but essentially the idea is to pass a known small current through the resistor and measure the voltage drop. To get a big enough signal to use the analog inputs on. Def cannot be done directly as pointed out.

Unless those R values are kilohm. :wink:

The data sheet seems to show a nominal example and two that would be at the extremes, handled by fitting to a third order polynomial; there are websites where you can plug in as many points as you want and get that done for you, just "simple" maths.

isn't the one I used (and can't find just now) but looks similar. If I wasn't so lazy, I'd try it with the numbers from the datasheet.


1 Like

The image from the data sheet gives a 2nd order characteristic curve for the "typical" sensor resistance, but 3rd order curves for the +/- tolerance values.

One wonders why, as there is no reason to do so. 2nd order fits to all three data sets work well, as shown below:

I posted the data part of the data sheet in the original post, but the rest of the images are available here:

I have to admit, the answers to this thread have gone completely over my head. Formulas beyond simple multiplication/division are Greek to me, and therefore expressing any sort of curve within the Arduino's code is more of the help I was looking for.

That's what I said but as much googling as I am allowed to do on this seems to suggest that these low ohm sensors are meant, in the old days, to be directly measured as part of a simple circuit with a meter powered by automotive voltages.

So while another track of insomniacal googling finds modern signal conditioning amplifiers on a chip, all very whizzy, it looks like a simple voltage divider, albeit one that will use some energy, is a valid approach.

MAXIM has some signal conditioning stuff.

More than as usual, YMMV. All just my abject curiosity and tenden7to want to play above my pay grade.



It is only +, -, *:

  int v = analogRead (...) ;
  float R = .... v .... ; // calculate resistance from ADC reading
  float pressure = -0.3682 * R*R + 36.465 * R + 10.648 ;  // formula direct from datasheet

The calculation of R from the adc depends on the precise circuit which I don't have.

1 Like

What kind tool generates this stunning output?
(And of course determines the coefficients of the best fit algebraic equation?)

Would probably be better to pre-calculate the pressure values for each value of the analog input and store that as a lookup table. If you do not need the 6 or 7 digit precision of a float, storing as an integer takes less space, and with something as imprecise as this the analog value can be divide by 2, 4, or 8, etc to give less data points and a more stable gauge reading.

Older automotive sensors were commonly wired in series with the gauge and driven from a regulated 6V power source (crudely regulated). The gauge itself was a bi-metallic spring with the spring being heated by the current flow. 6 volts was used because early automobile batteries were 6V, when 12V batteries became common it was easier to regulate the voltage down to 6V than to redesign all the gauges to operate at the higher voltage.

Kaleidagraph. It took just 2-3 minutes to generate that figure, and most of the time was spent typing in the numbers.

In C/C++, the formula relating the resistance R and the pressure P is taken from the "typical" characteristic curve (a quadratic equation) as follows:

float R = -0.3682*P*P + 36.46*P + 10.65;

Usually you would measure R and calculate P, which is simple enough. But first, get to the point of measuring R.

Did you expect this project to be just a few minutes work?

Not at all: I've been playing with Arduinos for many years now so I'm aware of what's involved, and my prototype is already reading R values and displaying them on a custom-made 7-segment display board driven by multiple MAX7219 chips.

But, as others have proven, converting the data sheet into an actual formula was indeed a few minutes' work.

First, it is sure this is NOT Greek!! (GRuser speaking!!)
Good description from david_2018 "how it works" answer #11 , para 2
Excellent math from jremington
My suggestion :

  1. put a some hundreds ohm (ie200-330ohm) resistor in series (Vcc->R->sensor->GND)
  2. use a sketch to analog read between R and sensor
  3. use a air pressure tank with indicator to "calibrate" yours
    Good luck

If you already have R, then the calculation for the pressure is obtained by solving the quadratic equation for the characteristic curve.

Given this equation for the "typical" sensor response:

float R = -0.3682*P*P + 36.46*P + 10.65;

You get

float P = 0.8948E-6*R*R + 0.0271*R -0.2887; 

But the linear equation works just about as well:

float P = 0.02899*R - 0.3427;

Check for R = 48 Ohms: P = 1.048 ATM

Your sensor won't have the typical values, so for better accuracy, you will need to calibrate the sensor by measuring R at a few different known pressures. A straight line fits works well.

1 Like