I have an ESP32 DEVKit V1 connected to an MH-Z19b CO2 sensor.
The sensor needs 4.5V to 5.5V so I connected it externally to USB.
The MHZ Pins are connected to the pins in the code, I connected Rx - Tx and Tx - Rx. I tried other Pins like Pins 41 and 40 or 25 and 27 as Rx and Tx pins on the board, nothing works. I always get the same output.
The Code I use is the following:
#include "MHZ19.h"
#include "SoftwareSerial.h"
#define RX_PIN 33 // Rx pin which the MHZ19 Tx pin is attached to
#define TX_PIN 32 // Tx pin which the MHZ19 Rx pin is attached to
#define BAUDRATE 9600 // Device to MH-Z19 Serial baudrate (should not be changed)
MHZ19 myMHZ19; // Constructor for library
SoftwareSerial mySerial(RX_PIN, TX_PIN); // create device to MH-Z19 serial
void setup()
{
Serial.begin(115200); // Datenrate serieller Monitor
mySerial.begin(BAUDRATE); // (Uno example) device to MH-Z19 serial start
myMHZ19.begin(mySerial); // *Serial(Stream) refence must be passed to library begin().
myMHZ19.autoCalibration(); // Turn auto calibration ON (OFF autoCalibration(false))
}
unsigned long getDataTimer = 0;
void loop()
{
if (millis() - getDataTimer >= 2000)
{
int CO2 = myMHZ19.getCO2(); // Request CO2 (as ppm)
Serial.print("CO2 (ppm): ");
Serial.print(CO2);
int8_t Temp = myMHZ19.getTemperature(); // Request Temperature (as Celsius)
Serial.print(" Temperatur CO2Sens (°C): ");
Serial.println(Temp);
getDataTimer = millis();
}
}
The Output i get is: "CO2 (ppm): 0 Temperatur CO2Sens (°C): -17" and it won't change. Do you have an idea where the mistake is?
Thanks a lot!