Pages: [1]   Go Down
Author Topic: 0.5 - 4.5v pressure sensor  (Read 1235 times)
0 Members and 1 Guest are viewing this topic.
Newcastle, NSW, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 33
Just a mechanic
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
I'm wanting to log/capture data from a pressure sensor into the Arduino.
The sensor gets +5v and ground and gives a 0.5v - 4.5v voltage back, linearly from 0 - 15psi.
(it's an automotive style sensor where the controller perceives < 0.5v is open circuit and > 4.5v is a short).

I can't get my head around the scaling to give me an answer in psi???

I can read from the analog pin and get a 0 - 1023 result,
but I'm stuck at the maths where I use the reference voltage to convert it to meaningful psi, especially when 4.5v is full scale and not 5v.

Any ideas??
Thanks!
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 221
Posts: 13848
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Something like this...
Code:
void setup()
{
  Serial.begin(115200);
  Serial.println("Start psimeter 0.1");
}

void loop()
{
  // MEASUREMENT
  // make 16 readings and average them (reduces some noise) you can tune the number 16 of course
  int count = 16;
  int raw = 0;
  for (int i=0; i< count; i++) raw += analogread(A0);  // return 0..1023 representing 0..5V
  raw = raw / count;

  // CONVERT TO VOLTAGE
  float voltage = 5.0 * raw / 1023; // voltage = 0..5V;  we do the math in millivolts!!

  // INTERPRET VOLTAGES
  if (voltage < 0.5)
  {
    Serial.println("open circuit");
  }
  else if (voltage < 4.5)  // between 0.5 and 4.5 now...
  {
    float psi = mapFloat(voltage, 0.5, 4.5, 0.0, 15.0);    // variation on the Arduino map() function
    Serial.print(millis());
    Serial.print(", ");
    Serial.println(psi, 3);  // 3 decimals
  }
  else
  {
    Serial.println("Signal too high!!");
  }
}

float mapFloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}



Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: