MH-Z19B

by brentscheerlinck in Circuits > Arduino

101 Views, 0 Favorites, 0 Comments

MH-Z19B

MH-Z19-MH-Z19B-Mh-Z19C-MH-Z19C-Infrarood-CO2-Sensor-Voor-Co-2-Monitor-Kooldioxide.jpg

It meassures the CO2 concentration

Supplies

MH-Z19-MH-Z19B-Mh-Z19C-MH-Z19C-Infrarood-CO2-Sensor-Voor-Co-2-Monitor-Kooldioxide.jpg
c408d0d27666dea73ec2abac5c8bcb263361d355.jpg
image.jpg
unnamed.jpg

Used materials:

  • 3 jumper wires.
  • Arduino-board UNO 65139 ATMega328.
  • USB for Arduino.
  • MH-Z19B sensor.
  • Computer or laptop.
  • Arduino Editor to import the code (https://create.arduino.cc/editor).

CONNECT THE WIRES

MH-Z19 CO2 Sensor Arduino Uno

VCC ================================ ⇒ 5V

GND ================================ ⇒ GND

PWM ================================ ⇒ D10

RX ================================== ⇒ A0

TX ================================== ⇒ A1


Programming

Screenshot 2022-01-31 15.52.35.png
Screenshot 2022-01-31 15.52.45.png

#include <SoftwareSerial.h>

SoftwareSerial mySerial(A0, A1); // RX, TX

byte cmd[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};

char response[9];

#define pwmPin 10

int prevVal = LOW;

long th, tl, h, l, ppm, ppm2 = 0.0;

void setup() {

    Serial.begin(9600);

    mySerial.begin(9600);

    pinMode(pwmPin, INPUT);

}

void loop(){

    mySerial.write(cmd,9);

    mySerial.readBytes(response, 9);

    int responseHigh = (int) response[2];

    int responseLow = (int) response[3];

    ppm = (256*responseHigh)+responseLow;

    //CO2 via pwm

    do {

        th = pulseIn(pwmPin, HIGH, 1004000) / 1000.0;

        tl = 1004 - th;

        ppm2 = 2000 * (th-2)/(th+tl-4);

    } while (ppm2 < 0.0);

    Serial.println(ppm);

    Serial.println(ppm2);

    Serial.println("-----------");

    delay(5000);

}



Save and Upload

Screenshot 2022-01-27 13.07.35.png
Screenshot 2022-01-27 13.10.03.png
Screenshot 2022-01-27 13.11.23.png
  1. Press the save button
  2. Press upload
  3. Press on monitor and see the results