Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.

Pressure Sensor code (formula) help please

Some pressure sensor code help please. My project is to read pressure via a 5v transducer. Can anyone help with a formula that will convert the reading(I assume 0-5v) to a pressure reading. PSI

mjpcarbon

Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: Pressure Sensor code (formula) help please

What transducer are you using? The spec sheet should tell you how to map the output voltage to a pressure.

Posts: 78659
Joined: Sat Feb 07, 2009 10:11 am

Re: Pressure Sensor code (formula) help please

This is what is given but how do I map it ?

Output: 0.5-4.5V linear voltage output. 0 psi outputs 0.5V, 800 psi outputs 2.5V, 1600 psi outputs 4.5V.

mjpcarbon

Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: Pressure Sensor code (formula) help please

0 psi outputs 0.5V, . . . 1600 psi outputs 4.5V.

So you have the 2 data points needed for a two-point calibration. Just use the two-point calibration calculation from the guide:

Posts: 78659
Joined: Sat Feb 07, 2009 10:11 am

Re: Pressure Sensor code (formula) help please

psi = map(volts, volts1, volts2, psi1,psi2); // And the pressure that gives us? (From the pressure sensor specs.)

See? No fancy math. Just mappings.

-jim lee

jim_lee

Posts: 654
Joined: Thu May 24, 2012 8:24 pm

Re: Pressure Sensor code (formula) help please

Unfortunately, the Map function only works with integers. The equation in the calibration guide is essentially the same - but works with floating point values too.

Posts: 78659
Joined: Sat Feb 07, 2009 10:11 am

Re: Pressure Sensor code (formula) help please

Yes, that can be a, thing. You could just multiply everything by 100 or 1000 do the math then divid it out. Or..

Use mine : https://github.com/leftCoast/Arduino/wiki/mapper

-jim lee

jim_lee

Posts: 654
Joined: Thu May 24, 2012 8:24 pm

Re: Pressure Sensor code (formula) help please

Excellent, thanks for the help

mjpcarbon

Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: Pressure Sensor code (formula) help please

Jim, I don't fully understand the example you provided

psi = map(volts, volts1, volts2, psi1,psi2); // And the pressure that gives us? (From the pressure sensor specs.)

I expected only to see high and low ranges in the map, don't quite grasp why there are 3 values in the Volts map and the same in the psi map

I realize I am in over my head here and apologize for not understanding the help you have provided

mjpcarbon

Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: Pressure Sensor code (formula) help please

volts1 is the minimum output of the sensor - 0.5v in your case
psi1 is the pressure value that corresponds to volts1 - or 800 psi.

volts2 is the maximum output of the sensor - 4.5v.
psi2 is the pressure that corresponds to volts2 - or 1600 psi.

The first parameter 'volts' is the measured value from your sensor.

Posts: 78659
Joined: Sat Feb 07, 2009 10:11 am

Re: Pressure Sensor code (formula) help please

This is what I have so far, not quite there yet though. The voltage being reported is accurate however the PSI does go up with the voltage but in 400 increments. Seems as thought the PSI is only following the first digit of the voltage * 400.
[code][
int psi = 0;
int volts = 0;

void setup() {
Serial.begin(9600);
}

void loop() {
float volts = sensorValue * (5.0 / 1023.0);
//volts = map(volts, 0, 5, .5, 4.5);
psi = map(volts, .5, 4.5, 0, 1600);

Serial.print("PSI = ");
Serial.print(psi);
Serial.print(" Volts = ");
Serial.println(volts);
delay(2000);
}

/code]

mjpcarbon

Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: Pressure Sensor code (formula) help please

As I mentioned in an earlier post, the Arduino version of map() only works with integer values. You can implement the equation posted above, or try jim_lee's version here: https://github.com/leftCoast/Arduino/wiki/mapper

Posts: 78659
Joined: Sat Feb 07, 2009 10:11 am

Re: Pressure Sensor code (formula) help please

Here's the actual folder that the mapper stuff is in..

https://github.com/leftCoast/Arduino/tree/master/libraries/LC_baseTools

LC_baseTools is full of very handy & delightful tools, but probably just confusing at this point.

You want mapper.h & mapper.cpp. Luckily they predate most everything in there so they depend on nothing and can "live" on their own.

-jim lee

jim_lee

Posts: 654
Joined: Thu May 24, 2012 8:24 pm