Serial write adding characters

Hi everyone,

I am using an arduino uno board, and I've connected it to a MH-Z19B CO2 sensor with the TX RX pins. When I am using println, the first time it will always add some characters in the beginning when looking in the serial monitor. I think it is the return from the serial.write. Is it possible to turn this off? Or is this caused by something else?

In this case the output should be 2 times 255. However my output will look like this:
22:39:33.142 -> ⸮⸮y255
22:39:33.188 -> 255

void setup() {
Serial.begin(9600);
while (Serial.available() >0) {
  Serial.read();
}
}

void loop() {
byte cmd[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
byte response[9];

Serial.write(cmd, 9);
Serial.readBytes(response, 9);
Serial.println(response[0]);
Serial.println(response[0]);
delay(1000);
}

MH-Z19B CO2 sensor with the TX RX pins.

So you have both the sensor and serial monitor connected to Serial (USB) at the same time? That will not work well.

I would suggest that you use a different serial port for each. Since the serial monitor is tied to hardware serial (pin 1 RXD and pin 2 TX) connect the sensor to a software serial port.

Also, check out the serial input basics tutorial.