MH-Z14 / MH-Z19 CO2 sensor

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
User avatar
pwassink
Normal user
Posts: 60
Joined: 31 Oct 2016, 08:33
Location: Vorden NL

Re: MH-Z14 / MH-Z19 CO2 sensor

#21 Post by pwassink » 25 Feb 2017, 11:58

ThinkPadNL wrote:Have a look here: https://gathering.tweakers.net/forum/li ... 5#50345695

It seems the module is very sensitive to infrared light, so you should cover it from direct sunlight.
Also airflow is something that can influent the readings badly.
Yes,

That is exactly what was happening, it was on the table in full sunlight, i did spend some time with a modified cardboard box
with a kind of labyrinth which will let air flow through but almost no light and it was much more stable then ..

Even with the box inside the house it is quite sensible, but not as wild as it was in the direct sunlight , thanks ..

Peter

hugo11
Normal user
Posts: 17
Joined: 08 Nov 2016, 20:30

Re: MH-Z14 / MH-Z19 CO2 sensor

#22 Post by hugo11 » 10 Mar 2017, 18:17

maybe a tip what could help as I never had issues with light

I ordered one of these cheap smoke detectors off ebay, removed the crap and installed the ESP and MHZ19 into it.. working fine.

http://www.ebay.com/itm/Fire-Smoke-Sens ... pFsJv_PcRA

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: MH-Z14 / MH-Z19 CO2 sensor

#23 Post by manjh » 17 Aug 2017, 06:37

tedenda wrote: 03 Aug 2016, 00:51 Yes, it's probably best to keep these as separate plugins. My intention is to continue to develop the SenseAir plugin to more data of the S8-sensor and also support more variants of sensors from SenseAir.

Myself and colleagues have run the SenseAir plugin for several weeks and I have not had any problem and have not heard of problems so SoftSerial seams to be okay for this application.
I have set up an ESP unit with several sensors, of which one is a Senseair S8. Works great, but when I try to link it to an "Air quality" device in Domoticz, it does not feed any values. In Domoticz it stays on zero.
I then defined a "user-defined" device, and linked the S8 to that idx. Values come in just great.
As a workaround I now use a script that copies those values from the user-defined into the air quality, but that is a workaround not really a solution to the problem.
Where should I report this bug for plugin P052?

LisaM
Normal user
Posts: 513
Joined: 11 Apr 2017, 18:29

Re: MH-Z14 / MH-Z19 CO2 sensor

#24 Post by LisaM » 17 Aug 2017, 18:49

manjh wrote: 17 Aug 2017, 06:37 I have set up an ESP unit with several sensors, of which one is a Senseair S8. Works great, but when I try to link it to an "Air quality" device in Domoticz, it does not feed any values. In Domoticz it stays on zero.
I then defined a "userdefined" device, and linked the S8 to that idx. Values come in just great.
As a workaround I now use a script that copies those values from the user-defined into the air quality, but that is a workaround not really a solution to the problem.
Where should I report this bug for plugin P052?
It's not a bug, at least not in ESPEasy. Domoticz doesn't provide a standard device for this purpose...

s3030150
Normal user
Posts: 20
Joined: 29 Nov 2017, 14:27

Re: MH-Z14 / MH-Z19 CO2 sensor

#25 Post by s3030150 » 24 Mar 2018, 08:26

Hello, maybe nobody will kill me for asking this here.

Anyone tried to get the MHZ19B working as standalone INO file wihout ESPEasy?

I'm experiencing zero responses from MHZ19B after certain period of time (cca 45-60minutes). The only solution is to power cycle the ESP8266 together with MHZ19B. Simple reset of ESP8266 does not help

With ESPEasy (using same hardware, just different program) the sensor is working fine forever, so I must be missing something in the code.

Could anybody help me with this, please? I would like to ise the ESPEasy code from Dmitry to read MHZ19B without using ESPEasy. The reason is that I need HTTPS support and I'm using custom 433MHz signal decoding from my meteo station, which is hard to implement for me (and no reason to do it) into ESPEasy.

If someone could do me a favor and waste some time to help me, I will paste my short code (and wiring and details) here or anywhere else. Please let me know.
Thanks

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#26 Post by TD-er » 24 Mar 2018, 12:49

You better have a look at the way the bytes are parsed from the serial port.
That seems rather elaborate, but the key is that you sometimes loose sync and have to find the right 'sync' again by throwing away some bytes and check the checksum.

s3030150
Normal user
Posts: 20
Joined: 29 Nov 2017, 14:27

Re: MH-Z14 / MH-Z19 CO2 sensor

#27 Post by s3030150 » 24 Mar 2018, 12:57

So that's the shift about in espeasy sources? I will take espeasy sources and try to adapt it so it can be used in standalone program. I don't want to soil this thread with out of topic things but I'm quite helpless 😁

God help me haha 😁 thanks!

EDIT: got it, sorry for going off topic. Since I already have this comment here, I'll paste the function with shifting. thanks!

// mhz19uart is softwareserial

Code: Select all

int readCO2() {
	byte command[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};
	byte uartReturn[9];
	mhz19uart.write(command, 9); //request co2value CO2

	while (mhz19uart.available() && (unsigned char)mhz19uart.peek() != 0xFF) {   // read byte after byte until we get the beginning 0xFF
		mhz19uart.read();
		shifts++; // count the shifts so we can see how much it happens
	}

	memset(uartReturn, 0, 9); // pre-fill uartReturn array with zeroes
	mhz19uart.readBytes(uartReturn, 9);  // read the response from serial

	if (uartReturn[8] == checksum(uartReturn) && uartReturn[1] == 0x86) {  // if CRC is correct and second byte contains command sent previously
		int co2value = (int)uartReturn[2]*256+(int)uartReturn[3];  // calculate ppm value from high and low bytes
		return co2value;
	} else {
		return -1; // return error - crc or wrong data returned
	}
}

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#28 Post by Barb232 » 28 Mar 2018, 18:36

i am measering always 5000 ppm, temperature values are ok.
What is the problem?

s3030150
Normal user
Posts: 20
Joined: 29 Nov 2017, 14:27

Re: MH-Z14 / MH-Z19 CO2 sensor

#29 Post by s3030150 » 28 Mar 2018, 18:39

@Barb232 Paste the code

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#30 Post by TD-er » 28 Mar 2018, 18:41

The sensor outputs always the max range value when it boots.
So if you're getting this value over and over again, the sensor is rebooting over and over again.
Try to improve the power supply to the sensor and use it on 5V, not 3V3.

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#31 Post by Barb232 » 28 Mar 2018, 18:42

// same problem with espeasy software !!!!
// always 5000 ppm

#include <stdio.h>

#include "Arduino.h"
#include "mhz19.h"

#include "SoftwareSerial.h"

#include <ESP8266WiFi.h>
#include <WiFiManager.h>
#include <PubSubClient.h>

#define PIN_RX D3
#define PIN_TX D4

#define MQTT_HOST "192.168.178.67"
#define MQTT_PORT 1883
#define MQTT_TOPIC "/fhem/sensors/co2/mhz19"
#define MQTT_TOPIC2 "/fhem/sensors/co2/temp"

SoftwareSerial sensor(PIN_RX, PIN_TX);
WiFiManager wifiManager;
WiFiClient wifiClient;
PubSubClient mqttClient(wifiClient);

static char esp_id[16];

static bool exchange_command(uint8_t cmd, uint8_t data[], int timeout)
{
// create command buffer
uint8_t buf[9];
int len = prepare_tx(cmd, data, buf, sizeof(buf));

// send the command
sensor.write(buf, len);

// wait for response
long start = millis();
while ((millis() - start) < timeout) {
if (sensor.available() > 0) {
uint8_t b = sensor.read();
if (process_rx(b, cmd, data)) {
return true;
}
}
}

return false;
}

static bool read_temp_co2(int *co2, int *temp)
{
uint8_t data[] = {0, 0, 0, 0, 0, 0};
bool result = exchange_command(0x86, data, 3000);
if (result) {
*co2 = (data[0] << 8) + data[1];
*temp = data[2] - 40;
#if 1
char raw[32];
sprintf(raw, "RAW: %02X %02X %02X %02X %02X %02X", data[0], data[1], data[2], data[3], data[4], data[5]);
Serial.println(raw);
#endif
}
return result;
}

static void mqtt_send(const char *topic, int value, const char *unit)
{
if (!mqttClient.connected()) {
mqttClient.setServer(MQTT_HOST, MQTT_PORT);
mqttClient.connect(esp_id);
}
if (mqttClient.connected()) {
char string[64];
snprintf(string, sizeof(string), "%d %s", value, unit);
Serial.print("Publishing ");
Serial.print(string);
Serial.print(" to ");
Serial.print(topic);
Serial.print("...");
int result = mqttClient.publish(topic, string, true);
Serial.println(result ? "OK" : "FAIL");
}
}

void setup()
{
Serial.begin(115200);
Serial.println("MHZ19 ESP reader\n");

sprintf(esp_id, "%08X", ESP.getChipId());
Serial.print("ESP ID: ");
Serial.println(esp_id);

sensor.begin(9600);

Serial.println("Starting WIFI manager ...");
wifiManager.autoConnect("ESP-MHZ19");

}

void loop()
{
int co2, temp;
if (read_temp_co2(&co2, &temp)) {
Serial.print("CO2:");
Serial.println(co2, DEC);
Serial.print("TEMP:");
Serial.println(temp, DEC);

mqtt_send(MQTT_TOPIC, co2, "");
mqtt_send(MQTT_TOPIC2, temp, "");
}
delay(5000);
}

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#32 Post by Barb232 » 28 Mar 2018, 18:49

I am using 5V (external USB plug).
it boots with 410 and after a few measurements it runs into 5000
i am putting a case over it to prevent sunlight

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#33 Post by Barb232 » 28 Mar 2018, 18:58

other question: is the espeasy with this sensor now ok? I read in the documentation, that there are memory problems and i should use custom espeasy firmware.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#34 Post by TD-er » 28 Mar 2018, 19:45

Barb232 wrote: 28 Mar 2018, 18:58 other question: is the espeasy with this sensor now ok? I read in the documentation, that there are memory problems and i should use custom espeasy firmware.
Where is that warning?
ESPeasy is running just fine with the MH-Z19 sensor for almost half a year now.

Maybe you should add some capacitor to the power pins of the sensor. It may take up to 200 mA peak. The ESP module itself may also require quite some peak.
And some cheap USB chargers don't really output what is being written on the case.
Also the USB cable itself may cause quite some voltage drop during peak currents.
Like I said, it only outputs the max. value during startup of the sensor.

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#35 Post by Barb232 » 28 Mar 2018, 19:48

TD-er wrote: 28 Mar 2018, 19:45
Barb232 wrote: 28 Mar 2018, 18:58 other question: is the espeasy with this sensor now ok? I read in the documentation, that there are memory problems and i should use custom espeasy firmware.
Where is that warning?
ESPeasy is running just fine with the MH-Z19 sensor for almost half a year now.

here:
https://www.letscontrolit.com/wiki/inde ... _MH-Z19%22

s3030150
Normal user
Posts: 20
Joined: 29 Nov 2017, 14:27

Re: MH-Z14 / MH-Z19 CO2 sensor

#36 Post by s3030150 » 28 Mar 2018, 19:56

ESPEasy works fine even with the MH-Z19B version of the sensor, no problem here.

I'd say this:
- don't enable wifi, just test the sensor with a simple sketch without wifi (wifi won't consume power so powering the sensor will be more stable)
- calibrate the sensor (leave it outdoors for 30 minutes and upload the sketch which does zero point calibration in setup() once or twice
- if above does not help, have a look at the cabling and power requirements

apart from your problem, I see two things in your code:
1. is the shift I had problem with lately. sometimes you won't get the 0xFF as the first bit after sending command and you have to wait for it (look at my function few comments above). You are also not checking for the checksum, try to implement it. 1st byte of the answer should be 0xFF, 2nd is 0x86 and the checksum is the 9th byte. This way you will get only valid responses
2. is the delay(5000), I would do it using millis() instead just like you have it in the static bool exchange_command() function

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#37 Post by Barb232 » 28 Mar 2018, 19:58

ok, thank you. i will try that.

s3030150
Normal user
Posts: 20
Joined: 29 Nov 2017, 14:27

Re: MH-Z14 / MH-Z19 CO2 sensor

#38 Post by s3030150 » 28 Mar 2018, 20:04

also try reading via PWM to see if the sensor has bad values, this code is working for me, just change the PWM pin.

Code: Select all

int pwm_pin=D8; // put the input pin here
int prevupdate=0;
int updateseconds=5;
int pwmvalue=0;
unsigned long tmptime=0;
int calibrateafter=300; //minutes


boolean timerExpired(unsigned long whenms){
  if(abs(millis()-whenms)>0) { return true; }else{ return false; }
}

int read_pwm_value() {
  int th = 0;
  int range=5000;
  double ppm = 0;

  do {
    th = pulseIn(pwm_pin , HIGH, 1004000) / 1000;
    ppm = range / 1000 * (th - 2);
  } while (th == 0);

  return (int) ppm;
}


void setup() {
    Serial.begin(115200);
    pinMode(pwm_pin,INPUT);
    Serial.println("Starting...");
}

void loop() {
    // put your main code here, to run repeatedly:

    if((abs(millis()-prevupdate)) > updateseconds*1000){
      Serial.print("reading PWM value... ");
      tmptime=millis(); 
      pwmvalue=read_pwm_value();
      Serial.println(String(pwmvalue)+" and reading took "+String(millis()-tmptime)+"ms");
      prevupdate=millis();
    }



}

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#39 Post by Barb232 » 28 Mar 2018, 20:13

same problem with pwm

Code: Select all

395 and reading took 15795ms
reading PWM value... 405 and reading took 14056ms
reading PWM value... 405 and reading took 13051ms
reading PWM value... 405 and reading took 12048ms
reading PWM value... 2525 and reading took 1932ms
reading PWM value... 4990 and reading took 12047ms
reading PWM value... 4990 and reading took 12048ms
reading PWM value... 4990 and reading took 13051ms
reading PWM value... 4990 and reading took 12047ms

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#40 Post by Barb232 » 28 Mar 2018, 20:19

snip
- calibrate the sensor (leave it outdoors for 30 minutes and upload the sketch which does zero point calibration in setup() once or twice

snip

where can i find this sketch?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#41 Post by grovkillen » 28 Mar 2018, 20:22

I removed the warning on the wiki... haven't looked into that until you noticed it.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

s3030150
Normal user
Posts: 20
Joined: 29 Nov 2017, 14:27

Re: MH-Z14 / MH-Z19 CO2 sensor

#42 Post by s3030150 » 28 Mar 2018, 20:27

yeah so try calibrating it then.

you can use my test sketch which I put together from various sources around github. Disables ABC and performs calibration after 30 minutes, then it starts reading from serial.

Not sure if you should disable ABC at every start of your program or it remains disabled forever or until you enable it again. can somebody answer?

Code: Select all

#include <SoftwareSerial.h>
#include <SPI.h>
#include <Wire.h>


#define INTERVAL 5000
#define MH_Z19_RX D5 //RX
#define MH_Z19_TX D7 //TX



byte mhzResp[9];    // 9 bytes bytes response
byte mhzCmdReadPPM[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};
byte mhzCmdCalibrateZero[9] = {0xFF,0x01,0x87,0x00,0x00,0x00,0x00,0x00,0x78};
byte mhzCmdABCEnable[9] = {0xFF,0x01,0x79,0xA0,0x00,0x00,0x00,0x00,0xE6};
byte mhzCmdABCDisable[9] = {0xFF,0x01,0x79,0x00,0x00,0x00,0x00,0x00,0x86};
byte mhzCmdReset[9] = {0xFF,0x01,0x8d,0x00,0x00,0x00,0x00,0x00,0x72};
byte mhzCmdMeasurementRange1000[9] = {0xFF,0x01,0x99,0x00,0x00,0x00,0x03,0xE8,0x7B};
byte mhzCmdMeasurementRange2000[9] = {0xFF,0x01,0x99,0x00,0x00,0x00,0x07,0xD0,0x8F};
byte mhzCmdMeasurementRange3000[9] = {0xFF,0x01,0x99,0x00,0x00,0x00,0x0B,0xB8,0xA3};
byte mhzCmdMeasurementRange5000[9] = {0xFF,0x01,0x99,0x00,0x00,0x00,0x13,0x88,0xCB};

int shifts=0,co2ppm;

long previousMillis = 0;

SoftwareSerial co2Serial(MH_Z19_RX, MH_Z19_TX); // define MH-Z19

byte checksum(byte response[9]){
  byte crc = 0;
  for (int i = 1; i < 8; i++) {
    crc += response[i];
  }
  crc = 255 - crc + 1;
  return crc;
}


void disableABC() {
 co2Serial.write(mhzCmdABCDisable, 9);
}

void enableABC() {
 co2Serial.write(mhzCmdABCEnable, 9);
}

void setRange5000() {
 co2Serial.write(mhzCmdMeasurementRange5000, 9);
}

void calibrateZero(){
 co2Serial.write(mhzCmdCalibrateZero, 9);
}

int readCO2() {
  byte cmd[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
  byte response[9];
  co2Serial.write(cmd, 9);
  // The serial stream can get out of sync. The response starts with 0xff, try to resync.
  while (co2Serial.available() > 0 && (unsigned char)co2Serial.peek() != 0xFF) {
    co2Serial.read();
    shifts++;
  }

  memset(response, 0, 9);
  co2Serial.readBytes(response, 9);

for (int i=0; i<9; i++) {
  Serial.print(" 0x");
  Serial.print(response[i], HEX);
}
Serial.println(" Response OK. Shifts="+String(shifts));


  if (response[1] != 0x86)
  {
    Serial.println(" Invalid response from co2 sensor!");
    return -1;
  }



  if (response[8] == checksum(response)) {
    int responseHigh = (int) response[2];
    int responseLow = (int) response[3];
    int ppm = (256 * responseHigh) + responseLow;
    return ppm;
  } else {
    Serial.println("CRC error!");
    return -1;
  }
}

void setup() {
  Serial.begin(115200);
  unsigned long previousMillis = millis();
  co2Serial.begin(9600); //Init sensor MH-Z19(14)
  delay(500);
  disableABC();
  //setRange5000();
  delay(1800000);
  calibrateZero();
  Serial.println("Zero was calibrated");
}

void loop() {
  unsigned long currentMillis = millis();
  if (abs(currentMillis - previousMillis) > INTERVAL)
  {
          previousMillis = currentMillis;
          Serial.print("Requesting CO2 concentration...");
          co2ppm=-999;
          co2ppm = readCO2();
          Serial.println("  PPM = " + String(co2ppm));
          //if(calibrated) { Serial.println("Zero was calibrated."); }
  }
}

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#43 Post by Barb232 » 28 Mar 2018, 20:31

i will do this tomorrow, thank you

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#44 Post by TD-er » 28 Mar 2018, 20:45

Just be very careful with the calibration commands.
The 400ppm calibration should be done in the same environment (temp/humidity) as the room it is being operated in.
And make sure you do not run it more than once per minute or so.
I've ruined one of my sensors by running it too fast in succession and that sensor is totally useless now since the 0 ppm level is now above 400 ppm.

Just have a thorough look at the code of the plugin of ESPeasy, or the same code, but more compact, in Tasmota.

s3030150
Normal user
Posts: 20
Joined: 29 Nov 2017, 14:27

Re: MH-Z14 / MH-Z19 CO2 sensor

#45 Post by s3030150 » 28 Mar 2018, 20:47

the manufacturer says the sensor should be calibrated by calling calibration at least 20 minutes after operating the sensor in outdoor air, as far as I understood. why to calibrate it indoors?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#46 Post by TD-er » 28 Mar 2018, 20:53

s3030150 wrote: 28 Mar 2018, 20:47 the manufacturer says the sensor should be calibrated by calling calibration at least 20 minutes after operating the sensor in outdoor air, as far as I understood. why to calibrate it indoors?
The thing is that (at least here in Holland) the air outside is much colder and therefore higher relative humidity.
What they mean is that you should perform calibration in about 400 ppm CO2 concentration.
That's outside, when you're not among lots of people or in the city.
When you need to do recalibration, it is probably because the sensor did not experience well ventilated air in the last few days and then it is quite useless to do the calibration in the same room.

But you have to take into account the temperature and humidity and make sure no IR light enters the sensor (sunlight)

s3030150
Normal user
Posts: 20
Joined: 29 Nov 2017, 14:27

Re: MH-Z14 / MH-Z19 CO2 sensor

#47 Post by s3030150 » 28 Mar 2018, 21:05

That makes sense, thanks

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#48 Post by Barb232 » 29 Mar 2018, 09:02

Finally, it works.

i downloaded the document
http://www.winsen-sensor.com/d/files/in ... ver1_0.pdf

And i tried the method 8a (manual calibration)
I soldered a button between GND and HD and pressed the button for 7 seconds
waited 20 min with open window
Results: values 395 ppm
Lets wait and see
photo follows
using espeasy

Code: Select all

44042105 : MHZ19: PPM value: 395 Temp/S/U values: 21/0/0.00
44042105 : EVENT: co2sensor#PPM=395.00
44042107 : EVENT: co2sensor#Temperature=21.00
44042108 : EVENT: co2sensor#U=0.00
what is the meaning of U?

a few minutes later ...

Code: Select all

Log
285758 : EVENT: co2sensor#Temperature=21.00
285759 : EVENT: co2sensor#U=0.00
296021 : MHZ19: PPM value: 588 Temp/S/U values: 21/0/0.00
296022 : EVENT: co2sensor#PPM=588.00
296046 : EVENT: co2sensor#Temperature=21.00
296047 : EVENT: co2sensor#U=0.00
301398 : WD : Uptime 5 ConnectFailures 0 FreeMem 18664
306850 : MHZ19: PPM value: 540 Temp/S/U values: 21/0/0.00
306851 : EVENT: co2sensor#PPM=540.00
306875 : EVENT: co2sensor#Temperature=21.00
306875 : EVENT: co2sensor#U=0.00
316871 : MHZ19: PPM value: 497 Temp/S/U values: 21/0/0.00
316871 : EVENT: co2sensor#PPM=497.00
316895 : EVENT: co2sensor#Temperature=21.00
316896 : EVENT: co2sensor#U=0.00
327697 : MHZ19: PPM value: 459 Temp/S/U values: 21/0/0.00
327698 : EVENT: co2sensor#PPM=459.00
327725 : EVENT: co2sensor#Temperature=21.00
327726 : EVENT: co2sensor#U=0.00
331398 : WD : Uptime 6 ConnectFailures 0 FreeMem 18664
btw: i want to make a traffic light

red: ?
yellow: ?
green: ?

and how can i do that with a gpio LED rgb? rules

what value-ranges should i use?


/robin

s3030150
Normal user
Posts: 20
Joined: 29 Nov 2017, 14:27

Re: MH-Z14 / MH-Z19 CO2 sensor

#49 Post by s3030150 » 29 Mar 2018, 10:26

Not able to help you with espeasy since I'm not using it, but you need to keep the window open for half an hour and after that calibrate, otherwise you will calibrate to wrong value

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#50 Post by Barb232 » 29 Mar 2018, 10:28

yes, i did this

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#51 Post by TD-er » 29 Mar 2018, 19:33

I would say 400 - 700 ppm = green
700 - 1400 = orange
1400+ = red.

Barb232
Normal user
Posts: 40
Joined: 12 Mar 2016, 16:40
Location: Earth
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#52 Post by Barb232 » 29 Mar 2018, 19:35

thats are my practical results, too.
Thank you

I wrote a short blog Post in my Blog, works fine.

https://blog.moneybag.de/fhem-luftquali ... asy-wemos/
Screenshot 2018-03-29 21.22.53.JPG
Screenshot 2018-03-29 21.22.53.JPG (38.1 KiB) Viewed 17338 times

Erik82
New user
Posts: 2
Joined: 16 Apr 2018, 14:12

Re: MH-Z14 / MH-Z19 CO2 sensor

#53 Post by Erik82 » 16 Apr 2018, 14:24

I recently received my MH-Z14a sensor, I want to use it to send CO2 values to my home automation system via MQTT.

When I got it, I first hooked it up to a arduino nano and the PWM example form this site: http://domoticx.com/arduino-co2-sensor-mh-z14/
It seemed to work, The red light was flashing every few seconds, and I got some plausible values.

I now want to do the same with on the ESP8266 ESP-12. When I use the same sketch, I got some odd values and the red light was not flashing. I thing the problem is that my ESP circuit is working on 3.3v, while the sensor requires 5v.
To overcome that problem, I tried using one of these as power supply for the sensor: http://www.mpja.com/images/30175-large.jpg , while keeping the 3.3v power supply for the ESP. Unfortunately the result stayed the same.

I then tried switching to UART instead of PWM, and used a simplified versiopn of this sketch to test it: https://github.com/bertrik/mhz19/blob/m ... 2meter.ino
Unfortunately, it seems that the command bool result = exchange_command(0x86, data, 3000); in that sketch always returns 0 for me.
Any idea where I'm going wrong?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: MH-Z14 / MH-Z19 CO2 sensor

#54 Post by TD-er » 16 Apr 2018, 23:14

Are you sure you set TX on the ESP to RX on the sensor and vice verse?
You could also try this sketch: (section with the UART implementation)
http://domoticx.com/arduino-co2-sensor-mh-z14/

Erik82
New user
Posts: 2
Joined: 16 Apr 2018, 14:12

Re: MH-Z14 / MH-Z19 CO2 sensor

#55 Post by Erik82 » 21 Apr 2018, 17:44

Thanks, it seems like that was actually the case, now that I switched the RX and TX wires, I am able to get some plausible output from the sensor.
Does anyone know by the way what type of the 7 pin connector is? it seems to be as JST connector, but not with the standard 2.54 pitch spacing.

Edit: Figured out that it's most likey a JST-SH connector with 1.0mm spacing.

I did get my MH-Z14a working with the calibration sample from s3030150. I combined it with some code to send the values with a ESP8266 over MQTT (I'm sending it to home assistant)
If anyone is interested: https://github.com/eriknl1982/esp8266_mh-z14a-mqtt

The only issue I'm now facing is that after a while (sometimes a few hours, sometimes a day) the sensor starts returning 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 as response. The only way to get back to normal values is by powering the sensor down and up again.
anyone else experiencing this?

sincze
Normal user
Posts: 38
Joined: 15 Jul 2016, 12:54

Re: MH-Z14 / MH-Z19 CO2 sensor

#56 Post by sincze » 18 Mar 2019, 20:09

Barb232 wrote: 29 Mar 2018, 09:02 Finally, it works.

i downloaded the document
http://www.winsen-sensor.com/d/files/in ... ver1_0.pdf

And i tried the method 8a (manual calibration)
I soldered a button between GND and HD and pressed the button for 7 seconds
waited 20 min with open window
Results: values 395 ppm
Lets wait and see
photo follows
using espeasy
.....

and how can i do that with a gpio LED rgb? rules

what value-ranges should i use?

/robin
You guy saved my life. It is now working.
I used a dupont cable to connect the 2 pins together for 7 seconds. :lol:
esp-co2-v2.JPG
esp-co2-v2.JPG (17.22 KiB) Viewed 14542 times

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests