hey all, i'm a student of odisee in gent. we're trying to make a working CO2 meter with sensor MHZ19b. we're lighting it up via Uart. the clamps are connected to a 5Vdc and GRD Vin. The Uart is connected to pin rx10 and tx 11. now when printing out the PPM value it stabilizes constantly between 400 PPM and 403PPM also in rooms where at least 1000 PPM is present. What could be the problem?
// Quinten Permentier 2020-2021
// This is a program that reads the value of sensor mhz19b inside. do this
//we in two ways. dirty uart reading. For this read out we exclude
// tx to 11 and rx to 10. a second option is to work with pwm signials. here we conclude
// Callibration: this is done by connecting the HD pin of the sensor to the grnd for 7 seconds.
// low level.
// there is a second way of callibration where we take the zero point
// Here we select the following blocks in the program 0xFF,0x01,0x87,0x00,0x00,0x00,0x00,0x00,0x00,0x79.
Translated with www.DeepL.com/Translator (free version)
#include <SoftwareSerial.h>
SoftwareSerial co2Serial(11, 10); // bepalen op welke pin MH-Z19 RX TX wordt uitgelzen
float ppmPwmRead;
byte commandoPPM[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79}; //request
//byte commandoPPM[9] = {0xFF, 0x01, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79}; //reset MCU
//byte commandoPPM[9] = {0xFF, 0x01, 0x9B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79}; //returns Sensor range
byte response[9]; // arry voor het ontvangen van een antwoord
/*float PPM_PWM (float thLocal){
float tlLocal;
float PpmPwmLocal;
tlLocal= 1004-thLocal;
PpmPwmLocal = 2000*(thLocal-2)/(thLocal+(tlLocal-4));
return PpmPwmLocal;
}
byte getCheckSum(char *packet) {
byte i;
unsigned char checksum = 0;
for (i = 1; i < 8; i++) {
checksum += packet[i];
}
checksum = 0xff - checksum;
checksum += 1;
return checksum;
}
*/
void setup() {
Serial.begin(9600);
co2Serial.begin(9600);
}
void loop() {
//byte commandoPPM[9] = {0xFF, 0x01, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79}; //returns firmware level
/*ppmPwmRead = pulseIn(PWM_PIN, HIGH);
Serial.print ("de ppm met pwm waarde is ");
Serial.print (ppmPwmRead);
Serial.println(" PPM");
Serial.println(analogRead(A3));
*/
co2Serial.write(commandoPPM,9);
/*Serial.print ("byte 2 ");
Serial.println (commandoPPM[2]);
Serial.print ("byte 3 ");
Serial.println (commandoPPM[3]);*/
memset(response,0,9); // resetten wat in response zat
co2Serial.readBytes(response,9);
Serial.print ("high 2 ");
Serial.println (response[2]);
Serial.print ("low 3 ");
Serial.println (response[3]);
byte hoog = response[2];
byte laag = response[3];
float ppmWaarde = hoog*256+laag;
Serial.println(ppmWaarde);
float ppmsom = 0;
float ppmgem = 0;
for (int i = 0; i <= 100; i++) {
ppmWaarde = hoog*256+laag;
ppmsom = ppmWaarde+ppmsom;
}
ppmgem = ppmsom/100;
Serial.println(ppmgem);
delay(1000);
//Serial.println(pwm_value);
}
mhz19b_met_functie.ino (2.56 KB)