Serial Monitor reverse question marks

Hi Arduino gurus!
I have an Arduino Uno setup with a CO2 monitor, with code that should output the CO2 values from the sensor.
However, when I upload the code and run the serial monitor outputs reverse question marks (as uploaded on the picture).
I know a lot of people have had the same issue, and I tried to implement the same solutions but nothing has worked. The baud value matches in Serial Monitor and the code.
Can you help me figuring out what is wrong? Below I have attached the code, pictures and hardware setup.

Best regards
Valdemar

#include <SoftwareSerial.h>
SoftwareSerial SerialCom(13, 12); // RX, TX

// analog interface
const int analogPin = A0;

// PWM interface
const int pwmPin = 9;

void setup() {
  SerialCom.begin(9600);
  pinMode(pwmPin, INPUT_PULLUP);

  delay(180000); // preheat the CO2 sensor for 3 minutes

  Serial.begin(115200);
  Serial.println("Analog:,UART:,PWM:");
}

void loop() {
  int ppm_analog = get_analog();
  int ppm_uart = gas_concentration_uart();
  int ppm_PWM = gas_concentration_PWM();

  Serial.print(ppm_analog);
  Serial.print(",");
  Serial.print(ppm_uart);
  Serial.print(",");
  Serial.println(ppm_PWM);
  
  delay(60000); // sleep for 1 minute
}


int get_analog() {
  float v = analogRead(analogPin) * 5.0 / 1023.0;
  int gas_concentration = int((v) * (5000/2));

  return gas_concentration;
}


int gas_concentration_uart() {
  byte addArray[] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
  char dataValue[9];
  
  SerialCom.write(addArray, 9);
  SerialCom.readBytes(dataValue, 9);

  int resHigh = (int) dataValue[2];
  int resLow  = (int) dataValue[3];
  int ppm_uart = (resHigh*256)+resLow;

  return ppm_uart;
}


int gas_concentration_PWM() {
  while (digitalRead(pwmPin) == LOW) {};
  long t0 = millis();
  while (digitalRead(pwmPin) == HIGH) {};
  long t1 = millis();
  while (digitalRead(pwmPin) == LOW) {};
  long t2 = millis();
  long tH = t1-t0;
  long tL = t2-t1;
  long ppm = 5000L * (tH - 2) / (tH + tL - 4);
  while (digitalRead(pwmPin) == HIGH) {};
  delay(10);
  
  return int(ppm);
}

![Screenshot 2022-06-23 at 12.37.50|423x500](upload://dZ


s9EKHDV4z2wAjhiEXvcpmdYDm.png)

make sure the speed (e.g. 9600) is the same in the code and the serial monitor of the IDE (lower right)

Hi @gcjr
Thank you for your reply. I already made sure as this is some of the common mistakes :slight_smile:
“The baud value matches in Serial Monitor and the code.”

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.