# Analog pressure transducer

Hi, I'm new to this and I am experimenting with an arduino and a analog pressure transducer.

Sensor:
Input: 0-10,34 bar(Gauge Pressure);
Output: 0.5-4.5V linear voltage output. 0 bar outputs 0.5V, 5,18 bar outputs 2.5V, 10,34 bar outputs 4.5V.
Wiring: Red: +5V; Black: ground; Blue: signal output;

How can I translate these values to the arduino?

I have now something like this:

``````int pressen = 0; // Set pressure sensor input on Analog port 0

void setup() {

}

void loop() {
// MEASUREMENT
int raw = analogRead(pressen); //Reads the pressure sensor raw value on analog port 0

float voltage = raw * 0.004887586;
float pressure = 0.0;

// MATH

{
pressure = voltage * 10,3/4.0;   // it raises 10,3 bar over 4 volt      faster =>   pressure =  voltage * 2,575;
}
}
``````

But this assumes output ranges from 0 to 5 v, how can I adjust this for 0,5 to 4,5 volt? My pressure will never get above 8 bar, does this mean I don't have to worry about the 4,5 volt?

The comma won't work here, use a decimal point:`pressure = voltage * 10,3/4.0;`

In any case, to calculate pressure from voltage, it is better to use all the information you have. The response of the gauge appears to be linear with an offset (as the attached plot shows), which would be better than what you have now. The best fit linear equation is shown in red on the plot and can be easily inverted to obtain pressure from voltage.

So you want the output in bar?

0.5V = 102.3
4.5V = 902.7
Range from 0 to 10.34 bar is 802.4

So:

``````//Measurement
float raw = analogRead(pressen);  // I'm not sure what mixing int with float will do, so I've made this a float
//Math
float pressure = (raw - 102.3) * 10.34/802.4;
``````

You won't get more than 3 digits of accuracy because you are only starting with 10 bits, and not even the entire 10 bits. There are ways to get more useful bits out of the Arduino's 10 bit ADC. There are also external 16 bit ADCs.

If you want speed, use unsigned int and use integer math by multiplying everything by 100, then merely display the decimal point in the appropriate place when you send it to the display. I reduced 1034/80240 by dividing both by 2 to get the largest number to fit in an unsigned int.

``````//Measurement
unsigned int raw = analogRead(pressen) * 100;  //
//Math
unsigned int pressure = (raw - 10230) * 517/40120;
``````

Drat. I just realized that the max value in raw is 80200, larger than an unsigned int.

So let's make that multiplied by 50.

``````//Measurement
unsigned int raw = analogRead(pressen) * 50;  //
//Math
unsigned int pressure = (raw - 5115) * 517/40120;
``````

Thanks a lot for your help. Haven't got the parts here at home, but I'm gonna try it first thing in the morning!

Um... in my madness to speed up the math using integer math, the end result is not 100 times, it is 50 times.

Unless speed is really an issue, easier to just use floats.

Just one more question:

Shouldn't 4.5V = 902.7 be 4.5V = 920.7 ?

Drat! You are absolutely right. 920.7

Darn transcription errors...

So the delta is 818.4

Thank you very much for catching that. I corrected the numbers as necessary below:

``````//Measurement
float raw = analogRead(pressen);  // I'm not sure what mixing int with float will do, so I've made this a float
//Math
float pressure = (raw - 102.3) * 10.34/818.4;
``````
``````//Measurement
unsigned int raw = analogRead(pressen) * 50;  //
//Math
unsigned int pressure = (raw - 5115) * 517/40920;
``````

Thanks again, it works with the float, with the int it doesn't....
But I don't need speed, so the float is fine!