# Issue reading pressure transducers and getting floating value

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.

## migrated from stackoverflow.comAug 3 '17 at 8:52

This question came from our site for professional and enthusiast programmers.

• Could you give an example of how it should look? – thesonyman101 Aug 2 '17 at 19:33
• Ah yes @thesonyman101 so it is at ambient atmosphere with no pressure on it so it should consistently be reading between 12-16 psi because pressure at sea level is around 14 PSI. – clifgray Aug 2 '17 at 19:36
• Sorry but I disagree. Pretty sure it should read zero at ambient unless the inside of the transducer is in vacuum. But I still can't imagine what's causing the weird values other than floating pin/ floating ground. May want to make sure the input pin has pullup enabled. – TomServo Aug 2 '17 at 19:45
• @JLH oh you're right that may be the case. Either way I'm still pretty far from zero! – clifgray Aug 2 '17 at 19:49
• Every time I've had bizarre analog reading issues it's been because of either lack of a common ground or the pin needed pullup resistor enabled. Please check that, if it works will be happy to make that my answer. – TomServo Aug 2 '17 at 19:51

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.

• All that info makes sense and seems in line with what I've been thinking. This transducer doesn't get an overpressure fault until 900 PSI according to the data sheet so I wasn't too worried about the 500. I also tried 250 PSI and got the same condition. I'll keep digging on it! – clifgray Aug 2 '17 at 21:50
• @clifgray See latest edit. Almost certain 336 means you have it connected wrong.... – TomServo Aug 2 '17 at 23:29
• Thanks for the help and it turns out you were right. The honeywell connecter wasn't actually making good contact with the leads from the sensor and thus I wasn't getting the correct values even though it was all wired correctly. I just built my own connector for the back end with some female molex pins and epoxied it up and now it is working as expected for all of my transducers. Crazy all of the standard Honeywell connectors weren't working. – clifgray Aug 3 '17 at 21:24