 # Analog Input .5 v to 5 v

i have a pressure sensor which outputs .5 v to 5 v.

When mapping 0-5v generally its map(sensorValue, 0, 1023, 0, 255);

At .5 v my pressure is 0 psi and at 5 v my psi is 80 psi

how would i map this so its accurate since it does not start at 0v?

If your "zero" point is at 0.5V, then that's a low reading of approximately 102 (given that 5V would be 1023), so you'd do something like this:

``````psi = map(sensorValue, 102, 1023, 0, 80);
``````

You might want to first constrain the reading to make sure it doesn't go below zero:

``````sensorValue = constrain(sensorValue, 102, 1023);
psi = map(sensorValue, 102, 1023, 0, 80);
``````

I know pressure sensors that output 0.5 to 4.5V, but I don't know pressure sensors that output 0.5 to 5V. Can you check that ? Perhaps you have to adjust the constrain() and map().

When mapping 0-5v generally its map(sensorValue, 0, 1023, 0, 255);

The result here would have 4 times worse resolution than the original reading.

how would i map this so its accurate since it does not start at 0v?

The most accurate way is to use a rail-rail op-amp that scales the signal to 0-5V.

The next most accurate way is to use the map function to "stretch" the value range to the full range of the ADC. This would add ± 1 count error to 10% of the possible sensorValue readings.

``````unsigned short SenValScaled = map(sensorValue, 102, 1023, 0, 1023);
``````

Then, use float type variables when calculating psi to preserve accuracy:

``````float conversionFactor = 80.0/1023;
float psi = SenValScaled * conversionFactor;
``````

Peter_n - You are correct. It is .5 to 4.5 v

dlloyd - Although i have a basic understanding of op amps I do not know how to setup a rail to rail op amp so it has a .5-4.5 input voltage and output 0-5 v. I will definitely look into doing this.

RogerRowland - Thank you for the code.

The factor is strictly speaking 1024, not 1023, since the 5V range is partitioned into 1024 ranges.

map is overkill here, its not hard to code it up:

``````  float voltage = 5.0 / 1024.0 * analogRead (sensorPin) ;  // get voltage
float pressure = 80.0 / 4.0 * (voltage - 0.5) ;  // convert a 4V range to 80
``````

Using float early means no chance of unwanted integer truncation.

Incidentally the most precise formulation would be

``````  float voltage = 5.0 / 1024.0 * (analogRead (sensorPin) + 0.5) ;
``````

Since each ADC value covers a small range of voltage, the 0.5 means the midpoint of each range is calculated. However such precision is perhaps spurious given other errors in the system.

Hi,
I have a similar query about a pressure sensor (m3041-000006-250pg, datasheet attached). The output signal of 1-5V over the pressure range of 0-250psi. I need help converting the analog voltage to the corresponding pressure. Would it be something like this?:

float voltage = analogRead (sensorPin)* (5.0 / 1024.0) ;
float pressure = 250.0 / 4.0 * (voltage - 0.5) ;

If this is correct???, and if so, is the -1.5psi reading I’m getting when it should be at 0psi as result of the accuracy of the sensor. Would constrain effect this?

2305678.pdf (340 KB)