Same-day dispatch before 2 PM · Free delivery over ₹999 · GST invoices Get the appPrices incl. GST
Geekobot
Snap & SendNEWGeeko AIWhere's myOrder
Log in
Products
  • Projects
    • Component guidesHow parts work, with code you can run
    • Learning pathsFrom your first LED to your first robot
    • Workshops & eventsOnline sessions for makers and classes
    • ElectrolarkFree guided builds, simulator and certificates
    • Students & teachersStudent discount and classroom help
    • CommunityShare builds and ask other makers
    • CalculatorsOhm's law, LED resistor, 555 and 100+ more
    • Circuit builderWire parts and run the circuit, powered by Electrolark
    • Geeko AIAsk what to buy or how to wire it
    • Snap & SendPhotograph a part or list, we find it
    • Part finderAnswer a few questions, get the right part
    • Compatibility checkWill these two parts work together?
    • Compare partsSpecs side by side
    • Business & bulk ordersGST invoices, credit and volume prices
    • Request a quotationSend your list, get a quote
    • Classroom kitsPer-student kits and lab bundles
    • Gift cardsFor students, teams and events
  • Atal Tinkering Lab
BOM to cart
Geekobot

Components, kits and know-how for makers, students, engineers, labs and businesses across India.

Ask Geeko AIOrders, parts and projects, any timeEmail supportReply within 1 working dayGet the Geekobot appAdd it to your home screen, free

Follow us

Shop

  • Boards & SBCs
  • Sensors & Modules
  • IoT & Wireless
  • Drone & FPV
  • 3D Printing
  • Filaments & Resins
  • Motors & Drivers
  • Power & Batteries
  • Semiconductors
  • Passive
  • Displays & LEDs
  • Switches & Relays
  • Wires & Cables
  • Prototyping
  • Tools & Test
  • Robotics
  • STEM Kits
  • Atal Tinkering Lab
  • Mechanical Parts
  • Audio

Orders

  • Track your order
  • Help & support
  • Shipping and delivery
  • Refunds and cancellation
  • Contact us

Learn

  • Projects
  • Geeko AI project assistant
  • Learning paths
  • Guides
  • Calculators
  • Electrolark: free guided builds

Part tools

  • Part finder
  • Compare parts
  • Will it work with my board?

Institutions

  • Classroom kits
  • Atal Tinkering Lab
  • Students & teachers
  • Workshops & Events

Business

  • Business & education
  • Request a quotation
  • BOM bulk upload
  • Quick order by SKU

Company

  • About Geekobot
  • Community
  • Gift cards
  • Terms & conditions
  • Privacy policy
  • Product directory
  • Sitemap

© 2026 Geekobot, a trade name of OLatus Systems Private Limited. All rights reserved.

20, 1st Floor, Neeladri Complex, 10th Cross, Sampige Rd, 2nd Main, Malleshwaram, Bengaluru, Karnataka 560003 · GSTIN 29AACCO0462F1ZM

+91 91810 15607 · connect@geekobot.in · Monday to Saturday, 10 AM to 2 PM IST

UPI · CARDS · NETBANKING · GST INVOICES

ShopProjectsGeeko AIGuides
Compare 0 parts →
Log in

Shop by category

Shop all components
  • Boards & SBCs1,910 products
    • Alternative Single Board Computers
    • Arduino Ecosystem
    • FPGA & Logic Boards
    • Microcontroller & Wireless Boards
    View all
  • Sensors & Modules4,701 products
    • Biomedical & Heart Rate
    • Current, Voltage & Power
    • Force, Weight & Pressure
    • Gas, Weather & Environmental
    View all
  • IoT & Wireless2,314 products
    • RF Modules
    • RFID & NFC
    • Antennas & RF Accessories
    • Cameras & Smart Vision
    View all
  • Drone & FPV3,558 products
    • Flight Control & Navigation
    • FPV Video & Optics
    • Frames & Structural Parts
    • Motors & Propulsion
    View all
  • 3D Printing2,204 products
    • 3D Printers
    • 3D Scanners & Digitizers
    • Laser Engravers & Cutters
    • Material Management & Upgrades
    View all
  • Filaments & Resins1,472 products
    • Filaments
    • Photopolymer Resins
    View all
  • Motors & Drivers463 products
    • BLDC Motor Drivers
    • DC & Geared Motors
    • DC Motor Drivers
    • Linear Actuators & Solenoids
    View all
  • Power & Batteries557 products
    • Battery Holders & Connectors
    • Breadboard Power
    • Chargers & BMS
    • DC-DC Converters
    View all
  • Semiconductors295 products
    • Diodes & Rectifiers
    • Interface & RF Encoder ICs
    • Logic ICs (74xx)
    • Logic ICs (CD4000)
    View all
  • Passive67 products
    • Capacitors
    • Circuit Protection
    • Crystals & Oscillators
    • Inductors
    View all
  • Displays & LEDs572 products
    • 7-Segment & Dot Matrix
    • Addressable LEDs
    • Character LCDs
    • Graphic LCDs
    View all
  • Switches & Relays184 products
    • Keypads & Touch
    • Push Buttons & Tactile
    • Relay Modules
    • Relays
    View all
  • Wires & Cables233 products
    • Board-to-Wire Connectors
    • Crimp & Splice
    • Headers & Dupont
    • Heat Shrink & Sleeving
    View all
  • Prototyping101 products
    • Breadboards
    • Interface Modules
    • PCBs & Perfboards
    View all
  • Tools & Test717 products
    • Bench Power Supplies
    • Hand Tools
    • Measuring Tools
    • Meters & Testers
    View all
  • Robotics180 products
    • Humanoid & Legged Robots
    • Robot Chassis & Platforms
    • Robotic Arms & Grippers
    • Wheels & Casters
    View all
  • STEM Kits268 products
    • Arduino Learning Kits
    • Coding & IoT Kits
    • Early Coding (Ages 3-8)
    • Invention Kits
    View all
  • Atal Tinkering Lab196 products
    • Package 1: Electronics, Robotics, IoT and Sensors
    • Package 2: Rapid Prototyping Tools
    • Package 3: Mechanical, Electrical and Measurement Tools
    • Package 4: Power Supply, Accessories and Safety Equipment
    View all
  • Mechanical Parts212 products
    • Bearings
    • Brackets & Mounts
    • Couplers
    • Fasteners & Standoffs
    View all
  • Audio109 products
    • Amplifier Modules
    • Buzzers & Sirens
    • Speakers
    View all
  1. Home
  2. ›Guides
  3. ›Sensors
  4. ›MH-Z19 CO2 Sensor

Component guide · Intermediate · 3 min read

MH-Z19 CO2 Sensor

Pinout, Wiring and Code

By Geekobot Learning Team · Updated 29 Oct 2026

I'm using
Wiring, code and the Run it panels follow your board.
On this page
Short answerWhat the MH-Z19 isMH-Z19 pinoutWiring the MH-Z19Example codeSetup and tuningWhat you needAlternatives and when to choose themTry itCommon mistakesFAQsParts and next steps
Short answer

The MH-Z19 from Winsen is an NDIR (infrared) CO2 sensor that measures real carbon dioxide from 400 to 5,000 ppm. It runs from 5 V and sends readings over 3.3 V UART at 9600 baud, or as a PWM signal. Use it for classroom and office CO2 monitors that show when a room needs fresh air.

Key specs at a glance

Measures
CO2, 0 to 5,000 ppm (400 to 5,000 ppm useful)
Accuracy
±(50 ppm + 5 % of reading)
Method
NDIR (non-dispersive infrared)
Supply
4.5 to 5.5 V, about 20 mA average, 150 mA peak
Interface
UART 9600 baud (3.3 V logic), PWM output
Warm-up
3 minutes
01

What the MH-Z19 is

NDIR sensors shine infrared light through a small chamber. CO2 absorbs a specific infrared wavelength, so the less light reaches the detector, the more CO2 there is. Unlike VOC sensors, this measures CO2 itself, which is why it is the standard for ventilation monitoring.

Outdoor air is about 420 ppm. Well-ventilated rooms stay under about 800 ppm; above 1,000 to 1,500 ppm people start to feel drowsy and it is time to open a window.

02

MH-Z19 pinout

The pins on the MH-Z19 and what each one does.

PinFunction
Vin4.5 to 5.5 V supply
GNDGround
TXUART transmit (3.3 V)
RXUART receive (3.3 V)
PWMPWM output: high time encodes the CO2 level
HDZero calibration: pull low for 7 s in 400 ppm air (fresh outdoor air)
PinFunction
Vin
4.5 to 5.5 V supply
GND
Ground
TX
UART transmit (3.3 V)
RX
UART receive (3.3 V)
PWM
PWM output: high time encodes the CO2 level
HD
Zero calibration: pull low for 7 s in 400 ppm air (fresh outdoor air)
03

Wiring the MH-Z19

The sensor's RX is 3.3 V; a 1 kΩ / 2 kΩ divider from the Uno's TX keeps it safe. The ESP32 connects directly.

MH-Z19 pinArduino UnoESP32
Vin5V5V (VIN)
GNDGNDGND
TXD2 (SoftwareSerial RX)GPIO 16 (RX2)
RXD3 (SoftwareSerial TX) via 1k/2k dividerGPIO 17 (TX2)
Vin
Arduino Uno:
5V
ESP32:
5V (VIN)
GND
Arduino Uno:
GND
ESP32:
GND
TX
Arduino Uno:
D2 (SoftwareSerial RX)
ESP32:
GPIO 16 (RX2)
RX
Arduino Uno:
D3 (SoftwareSerial TX) via 1k/2k divider
ESP32:
GPIO 17 (TX2)
04

Example code

The response is 9 bytes: 0xFF, 0x86, CO2 high byte, CO2 low byte, then four other bytes and a checksum. Readings in the first 3 minutes after power-up are not valid.

Read CO2 over UART (Arduino Uno) · Arduino C++Verify & upload in Electrolark
#include <SoftwareSerial.h>
SoftwareSerial co2(2, 3);   // RX, TX
const byte READ[9] = {0xFF, 0x01, 0x86, 0, 0, 0, 0, 0, 0x79};

void setup() {
  Serial.begin(115200);
  co2.begin(9600);
}

void loop() {
  co2.write(READ, 9);
  byte r[9];
  if (co2.readBytes(r, 9) == 9 && r[0] == 0xFF && r[1] == 0x86) {
    byte sum = 0;
    for (int i = 1; i < 8; i++) sum += r[i];
    if ((byte)(0xFF - sum + 1) == r[8]) {
      int ppm = r[2] * 256 + r[3];
      Serial.print(ppm); Serial.println(" ppm CO2");
    }
  }
  delay(5000);
}
05

Setup and tuning

Automatic calibration (ABC)

the sensor assumes it sees fresh air (400 ppm) at least once every 24 hours. In rooms that never air out, turn ABC off with its command and calibrate manually outdoors.

Manual zero

take it outside for 20 minutes and pull HD low for 7 seconds.

Placement

at head height, away from windows, doors and people's breath.

Power

use a solid 5 V supply that handles the 150 mA lamp pulses.

06

What you need

Shop this list4 of 5 found in our store · ₹3,008

  • MH-Z19 infrared CO2 sensor module: the sensor this guide coversMH-Z19 Infrared CO2 Sensor Module – UART/PWM Output₹2,431Closest match, check the specs
  • ESP32-WROOM-32 38-pin development board: for Wi-Fi logging and dashboardsESP32-WROOM-32 38-Pin Development Board₹389
  • Uno R3 development board: the controller used in the wiring tableFind this part
  • 0.96 inch OLED display 128x64: to show readings without a computer0.96" OLED Display 128x64₹139Closest match, check the specs
  • Dupont jumper wires: for the connectionsDupont Jumper Wires (40 pcs)₹49Closest match, check the specs
07

Alternatives and when to choose them

  • ✓SCD40 and SCD41: smaller, I2C, with temperature and humidity.
  • ✓CO2 sensors compared: MH-Z19, SCD40/41, SCD30 and S8.
  • ✓CCS811: estimates CO2 from VOCs, not a true CO2 sensor.
08

Try it: Uart baud rate error calculator

Change the values and the diagram and results update as you type.

09

Common mistakes to avoid

  • !Leaving ABC on in a room that never gets fresh air, so readings drift low.
  • !Feeding the RX pin with 5 V logic.
  • !Trusting readings in the first 3 minutes.
  • !Mounting it where people breathe on it directly.
10

Frequently asked questions

What range does the MH-Z19 measure?

0 to 5,000 ppm CO2 on the common version; the useful range starts at outdoor level, about 400 ppm.

Is the MH-Z19 a real CO2 sensor?

Yes, it is NDIR, measuring CO2 itself rather than estimating it from VOCs.

What baud rate does it use?

9600 baud, 8 data bits, no parity, 1 stop bit.

What is a good indoor CO2 level?

Under about 800 ppm is well ventilated; over 1,000 to 1,500 ppm means open a window.

Does it work with ESP32?

Yes, power it from 5 V and connect the 3.3 V UART pins directly.

Parts for this guide

  • MH-Z19 Infrared CO2 Sensor Module – UART/PWM Output
    ₹2,431View
  • ESP32-WROOM-32 38-Pin Development Board
    ₹389View
  • Uno R3 Development Board (No Cable)
    ₹359View
  • 0.96" OLED Display 128x64
    ₹139View
  • Dupont Jumper Wires (40 pcs)
    ₹49View
Shop Gas, Air Quality & CO2 Sensors

Calculators

Uart baud rate error calculator

Keep learning

ComparisonIntermediateCO2 SensorsCO2 sensors tell you when a room needs fresh air: outdoors is about 420 ppm, under 1000 ppm indoors is good and above 1500 ppm calls for ventilation.3 min read · SensorsBuying guideIntermediateAir Quality SensorsCompare particle, CO2 and VOC sensors for an air monitor: PMS5003 and SDS011, NDIR CO2 vs eCO2, wiring, warm-up, power and placement for honest readings.3 min read · SensorsConcept explainerBeginnerUART and Serial CommunicationA UART sends data one bit at a time over one wire with no shared clock, so both ends must agree on the speed, called the baud rate (9600 and 115200 are common).4 min read · Electronics FundamentalsComparisonIntermediateVOC and Indoor Air Quality SensorsVOC sensors detect a mix of organic gases from cleaners, paints and cooking and report a relative index rather than a precise gas amount.3 min read · Sensors

Sources

  • MH-Z19B intelligent infrared CO2 module user manual (Winsen)

Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

On this page
Short answerWhat the MH-Z19 isMH-Z19 pinoutWiring the MH-Z19Example codeSetup and tuningWhat you needAlternatives and when to choose themTry itCommon mistakesFAQsParts and next steps
Need a hand?Ask Geeko AI which part fits your project, or talk to the Geekobot team.Ask Geeko AIHelp & support

Parts for this guide (Arduino Uno)2 items · ₹2,635

MH-Z19 Infrared CO2 Sensor Module – UART/PWM Output · Uno R3 CH340G ATmega328p Compatible Development Board

Run itChange the inputs and watch the output

Ask for a reading every 5 s. Fresh outdoor air is about 420 ppm; a closed room with people can pass 1500.

Serial monitor115200 baud
777 ppm CO2

A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.

Ask the Community

Ask a question