Source: https://mokxi.com/gas-sensor-simulator
Updated: 2026-11-11

Simulator

# A gas sensor simulator: an MQ-2 leak alarm on an Arduino

Mokxi is a free online MQ-2 gas sensor simulator that runs in your browser, with nothing to install and no account needed. An MQ-2 gas sensor on A0 of an Arduino Uno, with a traffic light module, a buzzer and an LCD. Drag the gas level up and the reading climbs until the alarm sounds, after the 20 second warm-up every MQ sensor needs.

Start building free or follow the MQ-2 tutorial

- 505 parts on the bench
- 45 boards running now
- 1.00x real time, on every board

Click to open it in the editor

The sensor warms up for 20 seconds first. Then click the circuit to open it in the editor and drag the MQ-2’s slider up: past a reading of 100 the red lamp lights and the buzzer sounds.

## What you can do here

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

- Set the gas concentration from clean air up to 10,000 ppm
- Watch the warm-up: readings that start high and fall for 20 seconds
- Read the analog level on the serial monitor and the LCD
- Trip an alarm with a buzzer and a red lamp
- See hysteresis stop the alarm chattering at the threshold
- Change the threshold in the sketch and run it again

## What the running circuit shows

A warm-up, a threshold and an alarm that does not chatter.

Press Run and the reading starts in the hundreds and falls while the sketch reports that the sensor is warming up. An MQ-2 has a heater inside, and until it is hot the output means nothing, so the sketch ignores the first 20 seconds. Skip that wait in your own sketch and the alarm goes off every time you power on.

In clean air the reading settles at 11 and the monitor prints “clean gas level 11”. Drag the slider to 500 ppm and it reads 90, still clean. At 800 ppm it reads 109 and the line becomes “GAS LEAK! gas level 109”, with the red lamp and the buzzer on. At 5000 ppm it reads 226.

The alarm starts at 100 and does not stop until the reading is back under 80. That gap is hysteresis. Without it, a reading hovering between 99 and 101 would switch the buzzer on and off over and over.

## How the MQ-2 is modeled

The curve, the heater and the slow recovery.

The model follows the MQ-2’s sensitivity curve for the concentration you set, the heater’s warm-up, and the way the sensor responds: it takes about 2 seconds to react to gas arriving and about 8 seconds to recover when the gas clears. So the reading lags the slider, as it would lag a real leak.

What it leaves out: humidity, which shifts a real sensor’s reading, and the difference between gases. A real MQ-2 answers to LPG, smoke, alcohol and others and cannot tell them apart. The number is a level, not a calibrated ppm. Treat this circuit as a way to get the logic right, and never trust a hobby sensor as a safety device.

The MQ-2 tutorial: wiring, code and calibration Analog pins and ADC resolution The buzzer simulator The LCD simulator

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

Find inspiration

## Open a project and press Run.

Every one runs in the editor exactly as it is drawn, ready to change.

ESP32-C3 Simon ESP32-C3 Hexapod robot Arduino Uno Desk buddy robot ESP32-C3 ESP32 DHT22 weather web server ESP32 Fire fighting robot Arduino Uno Hello, breadboard No board

See every project

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.”

C Chloe Engineering 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!”

J Jay Model builder Featured 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.”

N Nusret Robot 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 my MQ-2 read high when I first power it?

Its heater is still cold. The reading starts high and falls as it warms, which takes about 20 seconds here. Wait before you trust it, as the sketch in this circuit does.

What does the MQ-2 analog value mean?

It is a voltage that rises with gas concentration, read as a count from 0 to 1023. In this circuit clean air reads 11, 800 ppm reads 109 and 5000 ppm reads 226. It is not ppm; turning it into ppm takes the datasheet curve and a calibration.

How do I stop a gas alarm switching on and off at the threshold?

Use two thresholds. This sketch starts the alarm at a reading of 100 and only clears it under 80, so a reading that wobbles around 100 cannot toggle the buzzer.

Do I need an account at all?

No. The editor, the templates, the gallery, the compiler and Run all work without signing in. Your browser keeps your work as you go. An account saves your projects online, so they follow you to any computer. It also gives you a link to share.

Which boards are supported?

Forty-five, all on the free plan. Arduino: the Uno R3, Uno R4 Minima and Uno R4 WiFi, Nano, Nano ESP32, Nano RP2040 Connect, Mega 2560, Leonardo, Micro, the Pro Mini in its 5 V and 3.3 V builds, and the SparkFun Pro Micro. ESP32: the classic DevKit V1, the ESP32-S3, the ESP32-C3 and C6 DevKits, the Espressif DevKitC V4, the Freenove ESP32-WROVER, the Wemos LOLIN32 Lite, the Wemos D1 R32, the Cheap Yellow Display, the TTGO T-Display, the ESP32-C3 SuperMini and the Seeed XIAO ESP32-C3, C6 and S3. ESP8266: the NodeMCU, the Wemos D1 mini and the ESP-01S. Also the Raspberry Pi Pico and Pico W, the Seeed XIAO RP2040, the Waveshare RP2040-Zero, the Seeed XIAO SAMD21, the WCH CH32V003, the STM32F411 Black Pill, the STM32 Nucleo-F411RE and the STM32F103 Blue Pill, the BBC micro:bit V2, and the ATtiny85 and the ATmega328P in its 16 MHz and 8 MHz builds, which plug straight into the breadboard as bare chips. Your own code compiles in the browser for all of them. Then the Raspberry Pi 4, Pi 5 and Zero 2 W computers, which run your Python with gpiozero and RPi.GPIO, with nothing to compile. Each board page lists what it can and can’t do. For example, the WiFi boards have pretend WiFi, not a real radio, and the page says so.

Is my sketch really compiled in the browser?

Yes. A real compiler (clang, built for the web) runs in your browser. It downloads once, and your browser keeps a copy. After that, every build happens on your own computer. There is no build server and no waiting in line, so there are no build minutes to run out of.

Which browsers work?

Any up-to-date Chrome, Edge, Firefox or Safari, on a computer, a phone or a tablet. They all support WebAssembly, which Mokxi needs, and they have for years.

Does it work on a phone?

Yes. The editor works with touch, the buttons are big enough to tap, and the layout fits a small screen. The simulation runs on the phone itself.

Can I try Pro before I pay?

Yes. Every account can try Pro free for 7 days, once. It takes a card, nothing is charged for those days, and if you cancel before they end you pay nothing. It starts when you choose it.

Can I cancel anytime?

Yes, in one press from your account page. Your plan runs to the end of what you paid for.

Do you offer refunds?

Yes, once per account. Write to us within 14 days of a payment and we refund all of it. Lifetime Pro is refunded in full within 14 days of buying it.

Is there a student discount?

Yes. Students get Pro at half price with a school email.

Do students need accounts?

No. The simulator works signed out, so your class starts from one link with nothing to sign up for. An account only adds cloud saving and sharing, and a student can make one later, or never.

Does it work on a Chromebook?

Yes. Everything runs on the machine in front of the student, so a Chromebook works as well as a lab PC.

What does it cost for a class?

Nothing, if your students only need to open and run circuits: the whole simulator is on the free plan. The class tools (a roster, starter projects, auto-graded checks, the gradebook) come with Pro and Classroom. Classroom is $9.99 a student a year, from 5 students, so at least $49.95 for the year. Your own seat is free, and from 50 students each one costs less. Your students get Pro’s room while they are in your classes. Pay by card, invoice or purchase order. Pro on its own runs classes for up to 10 students in all. To try the class tools with real students first, start the free 30-day trial from your class page: one class of up to 20 students, no card.

Is student work private?

Yes. A student’s projects in a class are always private: they cannot be opened by link or put in the gallery. One exception, and only for reading: a teacher may open, and never write, a project owned by somebody in a class they teach, which is what a card on the class wall does. What we store about a student, who processes it, how a school has it deleted, and how we handle COPPA consent for students under 13 and FERPA as a school official are all on the student data privacy page at /privacy/students.

Is Mokxi AI free?

Every signed-in account gets questions every day: 5 on a free account, 50 on the Pro trial, 100 on Pro and the other paid plans, and 25 on Lifetime Pro.

Does Mokxi AI work with ESP32 and Raspberry Pi Pico sketches?

Yes. It knows which board the project is on and answers for that board, from an Uno to an ESP32, an ESP8266, a Pico or an STM32.

Can Mokxi AI change my code without asking?

No. It proposes a change as a card. Accept is yours, and only appears once the changed code compiles; Ctrl+Z undoes it.

What does Mokxi AI send with a question?

Your project text, the matching help articles and the last six messages of the chat, never your name or account. "What is sent" shows exactly what went.

What’s new

## Latest arrivals in Mokxi.

New November 1, 2026 A PCB view beside the breadboard The canvas More menu has a PCB view, next to the Schematic: your circuit as a printed circuit board, every part as its footprint, placed for you, with an Uno project laid out as an Uno shield. New November 1, 2026 See your circuit as a schematic Pro and the Pro trial now have a Schematic view in the canvas More menu: the circuit on your breadboard drawn with standard symbols beside it, kept up to date as you build. New November 1, 2026 Eight projects people search for by name Eight new built-in projects run on an Arduino Uno in the browser: a fire fighting robot that steers to a flame and sprays it, a car driven by the tilt of your hand over nRF24L01 radios, an ultrasonic water tank level controller with a pump, a bidirectional visitor counter that lights the room, a smart blind stick, an automatic pet feeder on a DS3231 schedule, MAX7219 scrolling text with MD_Parola, and a temperature logger that writes a CSV to an SD card.

See everything new

## More simulators

Each one opens on a circuit that is already running.

Online circuit simulator Arduino simulator Breadboard simulator ESP32 simulator Op-amp simulator Logic gate simulator LED circuit simulator Servo simulator LCD simulator OLED simulator NeoPixel simulator 7 segment display simulator LED matrix simulator Stepper motor simulator Motor driver simulator Ultrasonic sensor simulator Rectifier simulator Digital circuit simulator Potentiometer simulator PWM simulator Relay simulator Shift register simulator DHT11 simulator RFID simulator Accelerometer simulator RGB LED simulator Buzzer simulator MOSFET simulator Circuit simulator for kids Flip-flop simulator Multiplexer simulator Full adder simulator I2C simulator UART simulator Thermistor simulator PIR sensor simulator Oscilloscope simulator Multimeter simulator DC motor simulator Traffic light simulator Diode simulator Capacitor simulator Series and parallel circuit simulator Wheatstone bridge simulator Voltage regulator simulator Soil moisture sensor simulator Zener diode simulator Solar panel simulator AC circuit simulator Thevenin simulator Decoder simulator Encoder simulator PID simulator Robot arm simulator Load cell simulator IR sensor simulator LM35 simulator HC-05 Bluetooth simulator nRF24L01 simulator Function generator simulator Buck converter simulator TFT display simulator Keypad simulator GPS module simulator GSM module simulator Joystick simulator LDR simulator DS18B20 simulator ACS712 current sensor simulator Water level sensor simulator Touch sensor simulator LoRa simulator Line follower simulator Robot car simulator Transformer simulator Heart rate sensor simulator Fingerprint sensor simulator Sound sensor simulator

## Set off the alarm

Open the circuit, wait out the warm-up and drag the gas level up. Nothing to install, and no account needed.

Start building free Open the editor
