Baudrate for Pressure Sensing

Hello All,

I was curious about why my pressure sensor does not read in the serial monitor at 115200 baud rate, but reads at 9600? Could this be due to the controller I have interfacing between my sensor and program?

#include <Controllino.h>

const int pressureInput = CONTROLLINO_AI11;
const double pressureZero = 82.0;
const double pressureMax = 921.6;
const int pressureTransducerMaxPSI = 100000;
const int baudRate = 115200;
const int sensorReadDelay = 250;

float pressureValue = 0;

int x = 0;

void setup() {
  Serial.begin(baudRate);
  pinMode(pressureInput, INPUT);
}

void loop() {
  pressureValue = analogRead(pressureInput);
  //pressureValue = ((pressureValue-pressureZero)*pressureTransducerMaxPSI)/(pressureMax-pressureZero);
  Serial.print("pressure value: ");
  Serial.println(pressureValue, 1);
  //Serial.println(pressureValue);
  delay(sensorReadDelay);
}

You need to set the serial monitor baud rate (lower right corner) to be the same as the program setting in Serial.begin().

Thanks for replying. Oddly enough I did. So that is where I need help understanding. Setting both the code and serial monitor and it does not work.

Controllino ? Is that a ATmega2560 or ATmega328P ?
Perhaps they did something with the clock frequency, or perhaps the usb-serial controller that they use can not do 115200 baud.

You could do a test. Just send text to the Serial Monitor and see if it works.

void setup()
{
  Serial.begin( 115200);
}

void loop();
{
  Serial.println( "Hello World");
  delay( 100);
}

Where did you get this from.
Using floats with decimal places for integer values from the A/D sound weird.
Leo..

Controllino is a controller/PLC that is compatible to arduino IDE and its programming, I am not sure what microprocessor is in it. The 115200 does work because I got it working with a MAX31856 temp sensor just not with my -100~100kPa pressure sensor. You don't think it could be due to the pressure sensor not able to send at that rate, do you?

Sorry I am pretty new to programming so I am learning and trying odd things. They were Const int with no decimals and I changed them to see if I could get decimal readings. Just did not change them back

A analogRead() should have no influence on the baudrate.

The pressure sensor is an industrial grade. It is not a small that is usually seen with small controllers.
But here is where I got it from: PRessure Sensor

The rest of the specs are on the site as you scroll down.
Measuring Range: -100~100kPa
Vsupply: 24vdc
Output Signal: 0~5vdc
Connector: DIN connector @base

The code you posted is for a ratiometric sensor with a 10-90% output.
Not suitable for a 0-5volt (not ratiometric) sensor.

You basically just need this.
pressureValue = analogRead(pressureInput) /1024. * pressureTransducerMaxPSI;
That will give you the right value, but is probably not very stable,
because it uses default Aref, which is the potentially unstable 5volt supply.

Better move to an external absolute (not ratiometric) A/D, like the ADS1115.
That will also give you a much higher resolution.
Leo..

Thanks for your reply. I am using a ratiometric sensor because I am trying to sense the pressure of a chamber that may undergo vacuum pressure and the pressure needs to be part of an input flow of a gas like argon gas.

I've switched my code slightly. This is working great with 9600 baudrate just not 115200.
I presume if I were to go for something like the ADS1115 then the higher baudrate will work.

#include <Controllino.h>

float pressureInput = CONTROLLINO_A0;
/* based on 10 bit 5V TTL controller pin*/
const int analogZero = 0;
const int analogMax = 1023;
/* declarations */
float pressureMin = -100.00; //kPa
float pressureMax = 100.00; //kPa
float pascalTorr = 7.50062;
const int baudRate = 9600;
const int sensorReadDelay = 250;
float pressureValue;
float mapValue;
float voltValue;
float torrValue;

void setup() {
  Serial.begin(baudRate);
  //analogReference(DEFAULT);
  pinMode(pressureInput, INPUT);
}

float voltageFunction(float v) {
  /* analoginput to voltage */
  voltValue = v*(5.0/1023.0);
  return voltValue;
}

float mapf(float x, float in_min, float in_max, float out_min, float out_max) {
  /* mapping values: analog to ____ */
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

float mapPressureFunction1(float pressure) {
  /* gauge pressure kiloPa */
  mapValue = mapf(pressure, analogZero, analogMax, pressureMin, pressureMax);
  return mapValue;
}

float mapPressureFunction2(float pressure) {
  /* absolute pressure reading */
  mapValue = mapf(pressure, analogZero, analogMax, 0.00, 200.00);
  return mapValue;
}

float mapPressureFunction3(float pressure) {
  /* gauge pressure torr */
  mapValue = mapf(pressure, analogZero, analogMax, pressureMin, pressureMax);
  torrValue = (mapValue * pascalTorr);
  return torrValue;
}

void loop() {
  /* Converts 0-5v signal from sensor to gauge or absolute pressure range. */
  pressureValue = analogRead(pressureInput);
  
  Serial.print("voltage value: ");
  Serial.println(voltageFunction(pressureValue), 6);

  Serial.print("pressure value: ");

  /*gauge pressure*/
  //Serial.print(mapPressureFunction1(pressureValue), 6);
  //Serial.println(" kPa");
  Serial.print(mapPressureFunction3(pressureValue), 6);
  Serial.println(" torr");

  /*absolute pressure*/
  //Serial.println(mapPressureFunction2(pressureValue), 6);

  /*delay reading*/
  delay(sensorReadDelay);
}

Not according to the datasheet.

Are you making a voltmeter now? I thought you were making a pressure sensor.
Forget about 'voltage', and go directly from A/D value to pressure.

Wishful thinking. How many decimal places do you think are possible with a 10-bit A/D.

Leo..

So, not the one described in the data sheet?

const int baudRate = 115200;

Should have a warning from the compiler, 115200 is too large to fit in an int.

Duhh, good catch.
Could have been used directly (not declared), like everybody else does.
Serial.begin(115200);
Leo..

Good thinking. I might not be using a ratio metric sensor. I have a supply voltage of 24Vdc and the output signal changes from 0-5Vdc based on the pressure the sensor senses.
I am not creating a pressure sensor. I believe I am just reading the output from the sensor and converting it to pressure on the serial monitor. I was curious why it does not display on serial monitor at 115200.

Oh. good thinking. I will give that a try that

oh. I will give that a try

But doing that by first converting it to voltage and then converting it again to pressure is twice the work and twice a chance to make mistakes. Just go directly from A/D value to pressure.

pressure = analogRead(sensorPin) * sensortype; // is all you need

I see you're using a -100 to +100 sensor now.
For that one you subtract half of the A/D range (1024 / 2 = 512) as offset.

pressure = (analogRead(sensorPin) - 512) * (100. / 512);

Leo..