Electronic – arduino – Issue reading pressure transducers and getting floating value

arduinopythontransducer

So I'm trying to read a Honeywell pressure transducer off an Arduino Mega and I'm just getting floating values. I've tried ground the line straight to the Gnd and then I get a consistent 0 but otherwise it just floats. I have the excitation (positive) line for the transducer connected to the Arduino 5V output, the common (negative) line connected to Arduino Gnd, and the output line is connected to analog pin A8.

The code on the Arduino looks like:

#include <Arduino.h>

int pressInput = A8;

void setup() {
  Serial.begin(9600); // set the baud rate
  pinMode(pressInput, INPUT);
}

void loop() {
  String input;
  if (Serial.available()) { // only run through loop if data has been sent
    input = Serial.readString(); // read the incoming data
    if (input == "press") {
        int pressValue = analogRead(pressInput);
        Serial.println(pressValue);
    }
  }
  delay(100); // delay for 1/10 of a second
}

And I'm communicating with the Arduino via python and that code looks like:

def read_press():
    #Command to get the pressure value
    pressure_in_voltage = send_arduino_cmd("press")
    pressure_in_psi = 75.0 * (float(pressure_in_voltage)/1023.0) * 5.0 - 37.5
    #pressure = max pressure/(4.5V-.5V) * (voltage/max voltage) * 5V - offset (max pressure/(4.5V-.5V))
    return (pressure_in_psi)

With this code I'm getting random pressure values for example:

133.321
102.529
165.945
93.365
117.558

Any thoughts on how to debug this or what could be going wrong in my Arduino code? I've tried this with three of the same transducers and gotten the same result so I don't think it is an equipment failure on that side. I've also tested voltage across the + and – and it is 5V UNTIL I connect the output line and then I can't see any voltage across any of the lines. I've also connected the ground and common lines to a 5V power supply to ensure it wasn't an issue with the Arduino power and got the same result.

Best Answer

The analogRead() method returns an integer between 0 and 1023 on a 0-5V swing. Your transducer produces a 0.5V - 4.5V range (from the datasheet you linked to). That's a 4V swing. So analogRead() can be expected to yield values covering from about 102 to about 920. (10% or 0.5V off each end).

The pressure range of that transducer is 0 to 300 psi (again from the datasheet). So I'm wondering if 500 psi is a good test, you didn't blow the device properly, but that's certainly outside its range of linearity. If I plug 102 and 920 into your formula, I get ~0 and ~300. So your formula is good. I cannot explain why it's unchanging, other than perhaps you damaged the device with pressure at least 66% over its rated pressure.

Please also see this from the documentation:

Pullup resistors The analog pins also have pullup resistors, which work identically to pullup resistors on the digital pins. They are enabled by issuing a command such as digitalWrite(A0, INPUT_PULLUP); // set pullup on analog pin 0 Be aware however that turning on a pullup will affect the values reported by analogRead(). Details and Caveats The analogRead command will not work correctly if a pin has been previously set to an output, so if this is the case, set it back to an input before using analogRead. Similarly if the pin has been set to HIGH as an output, the pullup resistor will be set, when switched back to an input.

So you may want to remove the INPUT_PULLUP verb if you used it earlier.

EDIT

I think you might have it connected wrong -- following the above formula, ~330 is about what you'd get if the digital pin got ~5.0V. So may want to check your connections. With some pressure on it, a pigtail on the ADC pin should show <= 4.5V. If not then you have something connected wrong.