2

I'm trying to read CO2 data from a MH-Z19C sensor with an ESP32 board but I'm not getting anything. The error code from the library is 2 indicating a timeout (no data received).

Did I get the wiring wrong? I wonder if the sensor is fried ?

Library: MH-Z19 by Jonathan Dempsey

Connections:

  • MH-Z19C RX to TX2 (17)
  • MH-Z19C TX to RX2 (16)
  • MH-Z19C VIN to Power Supply 5V
  • MH-Z19C GND to Power Supply 3V

Code:

#include <SoftwareSerial.h>
#include <MHZ19.h>
#include <Wire.h>
// pin for uart reading
#define RX_PIN 16 // Rx pin which the MHZ19 Tx pin is attached to.
#define TX_PIN 17 // Tx pin which the MHZ19 Rx pin is attached to.
MHZ19 myMHZ19;
SoftwareSerial mySerial(RX_PIN, TX_PIN);
void setup() {
 Serial.begin(9600);
 // Start Co2 sensor
 mySerial.begin(9600); // (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))
}
void loop() {
 // Wait a few seconds between measurements.
 delay(5000);
 int CO2;
 // Request CO2 (as ppm)
 CO2 = myMHZ19.getCO2();
 Serial.println(String(CO2) + " ppm");
 if (myMHZ19.errorCode != RESULT_OK) {
 Serial.print("Failed to receive CO2 value: ");
 Serial.println(myMHZ19.errorCode);
 }
}

backwards wiring esp32 power supply circuit

asked Feb 28, 2023 at 3:54
7
  • 1
    It is too difficult to follow your wiring in those pictures. A schematic diagram would be much better. You have mentioned a 3.3v and a 5v supply. Do these share a common ground? Commented Feb 28, 2023 at 5:20
  • 1
    It is unclear how the GND are connected between the boards. It will be better to have a schematic than those pictures. Commented Feb 28, 2023 at 5:20
  • ok edited. note that the board is powered with USB while the sensor is powered by a power supply module. Commented Feb 28, 2023 at 22:25
  • I would connect the esp gnd to the z19c gnd. Commented Mar 1, 2023 at 0:10
  • 1
    It means connect PIN1 of ESP32S(GND) to pin2 of of Z19C(GND), basic 101 electronics. Commented Mar 1, 2023 at 1:53

1 Answer 1

1

This is not a Winsen Mh-z19 sensor (or any clone following it's specs) so you won't be able to read data using a mhz19 library. Most probably it's a HC8 sensor and someone would have to rewrite library to get data from it. Here are specs: https://pcus.ru/download/hc8.pdf and some more info: https://spezifisch.codeberg.page/posts/2022-08-23/co2-sensor-reverse-engineering/

answered Oct 29, 2023 at 21:08
1
  • how do you know it's not mh-z19? Commented Dec 15, 2023 at 3:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.