I am measuring pressure in bars from OsiSense™ XMLP pressure sensor (4-20 milliamp) on a arduino uno. When the machine im measuring pressure on is switched off the reading is 0v as expected. When the machine is on (the sensor is on) the reading is 1v as expected.
When the machine is on and hydraulics are active the voltage fluctuates as expected.

The problem I have is I don't know the maths to translate the voltage to bar pressure.

From a previus question i've asked from 0v to 5v the equation is:

// This is for the DEFAULT 5V analog reference.
// v = the voltage at the pin in Volts.
// p = the pressure in bar.
// Note that 'bar' is the pressure relative to the
// normal atmospheric pressure at that moment.
float v = (float) analogRead(A0) / 1024.0 * 5.0;
float p = v / 5.0 * 100.0;"

Is it just a matter of changing the equation to take into account the 1v when the sensor has power and then dividing by 4 instead of 5:

RawVoltage = (float) analogRead(A0) - 1;
float v = RawVoltage / 1024.0 * 4.0;
float p = v / 5.0 * 100.0;"
  • 2
    Please add a circuit (wiring). Also explain how you reasoned about dividing by 4 instead of 5. Last which model are you using; the pressure range depends on the device. 4-20 mA is 0-100% of the pressure range. Nov 21 '17 at 17:22
  • Thanks for getting back to me so quick. I'm sure its something easy im missing. The pressure sensor reads 0 to 100 bar. 0mA to 20mA is 0v to 5v range which is %100 of the possible readings. 4-20 mA is 1v to 5v and is 80% or 4v. The first 1v (0 to 4mA) just tells us the sensors has power and is working ok and reading 0 bar. What I need to workout is 0 bar to 100 bar (4 mA to 20 mA). you can see a diagram on the post here: arduino.stackexchange.com/questions/45485/… Nov 21 '17 at 20:54

If I understand your question correctly, when the sensor is on,

  • 4 mA (1 V on the Arduino) means 0 bar
  • 20 mA (5 V on the Arduino) means 100 bar.

Is that correct?

If that is correct, there you just have to linearly map the voltage range to the pressure range. The equation is

P = (v − 1 V) / 4 V × 100 bar

or, in C++:

float v = analogRead(A0) / 1024.0 * 5.0;  // in volts
float p = (v - 1) / 4 * 100;              // in bars

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.