Simulator

A CO2 sensor simulator: an MH-Z19B on an Arduino Uno, running in your browser

Mokxi is a free online CO2 sensor simulator that runs in your browser, with nothing to install and no account needed. An MH-Z19B infrared CO2 sensor wired to an Arduino Uno: GND to GND, VIN to 5V, TX to pin 2 and RX to pin 3, read over SoftwareSerial with the MHZ19 library. The sketch prints the CO2 in ppm and the temperature, and changes its advice as the air gets worse.

  • 526parts on the bench
  • 46boards running now
  • 1.00xreal time, on every board
Arduino Uno: MH-Z19B CO2 monitorlive0.000 s 0.00x
Click to open it in the editor
Click the circuit to open it in the editor, then drag the CO2 slider on the sensor and watch the advice change. You can also set the temperature and pick a range of 2000, 5000 or 10000 ppm.

What you can do here

In the circuit above, or in the editor it opens.

  • Read the CO2 in ppm from an MH-Z19B
  • Drag the CO2 slider and watch the advice change
  • Set the temperature the sensor reports
  • Pick a range of 2000, 5000 or 10000 ppm
  • Pull the 5V wire and see the sketch report no answer
  • Follow the sketch line by line in the editor

What the running circuit shows

One line of serial output, with honest advice attached.

The circuit opens beside these words as it is drawn, and the sketch starts talking right away. At the default settings the serial monitor prints “MH-Z19B CO2 monitor” and then “CO2 650 ppm, 25 C, fresh”. Fresh means you can relax.

Now drag the CO2 slider to 1500 ppm and the same sketch turns blunt. The serial monitor prints “MH-Z19B CO2 monitor” and then “CO2 1500 ppm, 25 C, air the room now”. The sketch bands the readings itself: under 800 is fresh, under 1000 is getting stuffy, under 1500 wants a window open, and above that the room needs airing now.

Wiring matters here, and the simulator shows it. If the sensor has no 5V wire, the sketch prints “No answer from the MH-Z19B: check TX, RX and 5 V” and no ppm line at all. Reconnect VIN to 5V and the readings come back.

How the CO2 sensor is modeled

The serial commands and outputs follow the Winsen manual, with a few shortcuts.

The MH-Z19B is an infrared NDIR sensor that answers a nine byte read command at 9600 baud, and the model gets the command frames, the check byte, the read answer, the PWM cycle and formula, the Vo scale, the 7 second HD calibration and the 4.5 V minimum supply right, all from the Winsen manual V1.3. The zero and span calibrations move the readings the way they do on the real sensor, and the range setting holds the serial reading, the PWM and Vo alike.

What it does not model: the real sensor needs 3 minutes to warm up and up to 2 minutes to follow a change in the air, and it carries a 50 ppm plus 5 percent error. Here the reading follows the slider at once and exactly, with none of that.

How it works

Three steps from a blank tab to a running circuit.

  1. Open the editor

    It runs in your browser tab. Nothing to install, and you need no account to start.

    Your first project
  2. Wire it and write the code

    Drag parts onto a breadboard, run each wire from pin to pin, and write the sketch beside it.

    Wiring
  3. Press Run

    Your sketch compiles in the tab and runs on a model of the chip, with the Serial Monitor beside it.

    Run and serial
Reviews

What makers say about Mokxi.

“The AI checker helps check and correct my circuits, and it has way more components than Tinkercad. As a student I really appreciate the tool.”

ChloeEngineering student

“I’d been looking for a real online electronic simulator that was intuitive and complete when I found Mokxi. I was able to quickly import a Fritzing file and my Arduino sketch and start testing. Mokxi has all of the makings for the best online Arduino simulator I have been able to find!”

JayModel builderFeatured in his DioramaOS post

“I’m using Mokxi to develop and simulate an STM32-based four-wheel-drive robot car before building the actual hardware. It allows me to experiment with DC motor control, PWM, RPM measurement using photointerrupters, and different acceleration, braking, and reversing strategies, helping me understand and refine the system before implementing it in real life.”

NusretRobot car builder, Hamburg

Share your story

FAQ

Questions, answered.

Is it free?

Yes. The circuit on this page, every part in it and the editor it opens in are on the free plan, with no card.

Do I need an account?

No. The circuit runs the moment the page does, and the editor opens without one. A free account is only for saving a project to the cloud and sharing it by link.

Why does the sketch say fresh air is about 420 ppm?

That is the level of CO2 in fresh outdoor air. A closed room full of people climbs past 1000 ppm, which is when a window wants opening.

Why is automatic baseline correction off in the sketch?

It treats the lowest reading of each day as 400 ppm. That is right for an office aired every night and wrong for a greenhouse or a bedroom, so the sketch turns it off with autoCalibration(false).

What does the MHZ19 library do here?

It sends the nine byte read command on SoftwareSerial at 9600 baud and checks the answer. The errorCode field says whether a good one came back, and the sketch prints a warning instead of a reading when it did not.

More simulators

Each one opens on a circuit that is already running.

Watch the air change

Open the circuit, drag the CO2 slider and watch the advice change. Nothing to install, and no account needed.