Go Down

Topic: 0.5 - 4.5v pressure sensor (Read 1 time) previous topic - next topic

nitrolx

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!

robtillaart


Something like this...
Code: [Select]

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;
}




Rob Tillaart

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

Go Up