MiCS-5524, MQ-3 gas sensors and Circuit Playground Express.

Hanwei/Winsen and SGX Sensortech produce a range of sensors for gas detection and measurement. This project demonstrates how to use the MQ-3 and MiCS-5524 sensors. These are based on a heated, metal oxide semiconductor which varies in resistance in the presence of a gas or vapour that can be oxidised - this includes some hydrocarbons, alcohols, ammonia and carbon monoxide. This change of sensor resistance can easily be determined from an on-board potential divider circuit producing a voltage. That voltage can be measured on an analogue (ADC) input.

Flammable liquids, vapours and gases can be dangerous especially odourless one. It is best to keep samples small and keep liquids away from ignition sources in sealed containers.

In this project a Circuit Playground Express (CPX) board is used, but any board with two analogue inputs could be used.

This project requires some very simple soldering to attach 4 header pins to the MiCS-5524 breakout board.


1 x Circuit Playground Express
A great sensor-packed development board with seven analog inputs and support for many languages.
1 x Adafruit MiCS5524 CO, Alcohol and VOC Gas Sensor Breakout
A relatively low power, 5V metal oxide gas sensor breakout board with enable line. Header pins need soldering.
1 x MQ-3 Gas Sensor Module
A common, 5V metal oxide gas sensor module. Available from many suppliers. Pinout order likely to vary.
1 x Half-size breadboard
Breadboard for sensors. Use the full size if you want to progress to using many sensors simultaneously.
1 x Small Alligator Clip to Male Jumper Wire Bundle - 6 pieces
Three alligator (crocodile) clips to connect to pads on CPX.
1 x Through-Hole Resistors 1k ohm 5% 1/4W
One 1K resistor. Two 470 ohm in series or two 2.2k in parallel would work well as a substitute.

Gas Sensor Types

There are a variety of gas sensors which vary in their:

  • sensing technique,
  • sensitivity,
  • ability to discriminate between gases (cross sensitivity),
  • power consumption (due to heater / light source),
  • susceptibility to reversible ill effects and permanent ones (poisoning),
  • degradation over time and prescribed lifetime.

Some sensors use a heating element which heats the sensor and a tiny volume of air to a very high temperature - these will use a metal wire gauze (mesh) for the same reason as the Davy lamp (Wikipedia).

Metal Oxide Semiconductor

These use a heated, ceramic bead impregnated with metal oxide (often tin dioxide) as a variable resistor. Broadly speaking, the resistance drops in the presence of gases which can be oxidised.

The MQ series are popular with hobbyists in the Arduino community. There's an interesting look inside an MQ-2 on Learn the Working of a Gas Sensor.


These have two heated elements, one which catalyses oxidation of gases and one which doesn't to act as a reference resistance. A catalyst is defined as something which is not consumed in the reaction but traditional designs for catalytic sensors can age in unfortunate ways according to Figaro Engineering.

Electrochemical (battery)

These are essentially a battery where a gas is required to complete the chemical reaction to produce a tiny current. These may or may not be heated depending on the type/sensitivity. These are likely to have a time or exposure limited life.

This is a sensor from a commercial, domestic carbon monoxide (CO) detector which has reached its enforced end-of-life. Note: "CAUTION ACID" written on the sensor indicating a property of its cell chemistry, probably sulphuric acid.

Another common example is the small button battery based on the zinc-air cell used in hearing aids. These look like normal button cells but have an extra tab which is removed at installation time to expose the cell to the oxygen in the air.

Non-dispersive Infrared

These determine the gas based on absorption at a particular wavelength and are sometimes referred to as Non-dispersive Infrared (NDIR) sensors.

See DFRobot's Analog Infrared CO2 Sensor For Arduino for an example. This looks like it's based on sensor on the Winsen MH-714A gas sensor module which has a strong resemblance to the Telaire T6613/T6615 CO2 sensor modules.


Miners working underground are often at risk from both poisonous and explosive gases. Canaries were the traditional solution to detecting poisonous gases. For some history, see Smithsonian Magazine: The Story of the Real Canary in the Coal Mine.

More information

Connect the Sensor Boards

Breadboard with gas sensors powered by 4 NiMH batteries + sample on cotton bud.


The MiCS-5524 board comes with some header pins which need attaching by soldering for use on a breadboard. The pins are best inserted into the breadboard before soldering to ensure they are located properly. The board should be positioned at ninety degrees to the pins during soldering. See Adafruit MPRLS Ported Pressure Breakout for a similar soldering example.

Power Supply

The sensor boards are designed for use with a 5V supply. The CPX board has a VOUT pad which for USB powering is connected to the USB 5V line. This looks ideal but the heaters on gas sensors draw more current than logic circuits and this complicates powering the sensors as it can lead to voltage drops. As an example, the CPX VOUT (rated at maximum 500mA) connected to a desktop computer measures:

  • Desktop USB = 4.93V
  • CPX VOUT  = 4.79V (unloaded)
  • CPX VOUT = 4.58V (loaded with two sensors at 134mA)

A voltage 8% below the recommended 5.0V will also reduce the current. Power is the product of voltage and current and is therefore reduced by more, in this case by 15.4%. The heater's resistance will change a little with power variation due to change in temperature making an accurate calculation a little more complicated.

A decrease in voltage would normally decrease the voltage from a potential divider based output proportionally. However, in this case the lower temperature from the heater appears to have a greater effect and observably increases the analogue output in clean air at 4.6V supply voltage.

The power options are:

  • USB / CPX VOUT - easy to use, limited to 500mA, likely to suffer from considerable voltage drop and will struggle with more high current sensors like MQ ones.
  • Switch-mode power supply - cheap ones may add considerable high frequency noise which could add noise to analogue input (including via ground line).
  • Linear power supply - noise (ripple) will be low frequency and easy to compensate for. 
  • Batteries - very low noise but voltage will decrease a little as batteries discharge.

For more detail, see Power Supplies.

Connecting everything

The connectivity is fairly simple. The breadboard needs 5V power, the two gas sensor modules have an analogue output which benefits from being reduced to keep it below the CPX 3.3V maximum input. This can be achieved with a potential divider. For both these gas sensor boards, this is already implemented on-board with a "load resistor" (Rl). This on-board resistor can be supplemented with an external resistor connected to ground which is effectively in parallel and will reduce the effective resistance.

  • MiCS-5524 - add 10k resistor from analogue output to ground.
  • MQ-3 - add 1k resistor from analogue output to ground. Two 470 ohm resistors in series or two 2k2 resistors in parallel would be appropriate substitutes if a 1k is not available.
Circuit Playground Express connected to MiCS-5524 and MQ-3 boards. If four batteries are used they MUST be rechargeable to produce correct voltage.
If four batteries are used then they MUST be rechargeable (NiMH) ones to produce 5V rather than 6V produced by non-rechargeable batteries.

For gas testing a fully-charged set of four NiMH AA batteries was used in a battery pack. The battery pack's connector was adapted for breadboard use with two header pins.

The breadboard used was a slight variant with a break in the power lines half way along - the diagram shows two wires connecting this break which can provide a convenient place to measure the current. These wires would be redundant on the more typical 830 breadboard.

The MQ sensor boards often differ particularly with pin ordering - always check pin labels.

Enable line

The astute reader will spot an extra component in the photo not present in the diagram. An IRLB8721 (MOSFET) transistor has been added to allow the power to be controlled for the MQ-3. The implementation creates an enable line to allow the sensor to be turned on and off by a logic signal and is intended for further investigation of MQ sensors.

This is similar to the Adafruit MiCS-5524 breakout board although that differs in having a NOT enable line - this is indicated by the line above the En - the board is enabled when the pin is connected to ground (or left disconnected).


If you are new to CircuitPython, see Welcome to CircuitPython!

The simple code below intended for the CPX board reads multiple samples from every pin and then averages them before printing them to serial console. It takes approximately 1 second to read 370 samples for all eight pins plus a little additional time to do the maths, format output and send it to the serial console. The values printed are: a timestamp at start of the sampling period, another timestamp at the end, and then the averaged values for pins A0 to A7. The timestamps are the number of seconds from when the CPX board was powered up.

The first line on the terminal screenshot below shows values read between 352.076888 and 353.057003 seconds with A1 4421.45 and A2 18889.9. The unconnected pins have values around 29000. These values are raw values and can be converted to a voltage by dividing by 65536 and multiplying by the reference voltage which is 3.3V in the library code. For this example, the values would be 223mV and 951mV, respectively,

The output is in Python tuple format and can be graphed directly by Mu editor. For this project the terminal output was captured to a file and then graphed using the R language.

Download: file
import time

import board
from analogio import AnalogIn

# All eight pins on CPX board
pins = [ AnalogIn(board.A0),
         AnalogIn(board.A7) ]     

numpins = len(pins)

# 370 is about 1 second for 8 pins on CPX
samples = 370

# Print two relative timestamps in seconds plus an
# unweighted average of many samples for each pin in
# python tuple style which can be read direclty and
# graphed by the Mu editor - values are raw (0-65535)
while True:
    total = [0] * numpins
    t1 = time.monotonic()
    for repeat in range(samples):
        values = [pin.value for pin in pins]
        total = [sum(x) for x in zip(total, values)]
    t2 = time.monotonic()
    avgs = list(map(lambda x: x / samples, total))
    print("({:f},{:f},".format(t1,t2) +
          ",".join(str(avg) for avg in avgs) + ")")

Adafruit recommends copying this file to the board using the target filename code.py on the Circuit Playground Express.

Sensor Burn-in

Hanwei/Winsen recommend a 24 hour "burn-in" period of use before the sensor is used for real applications. SGX Sensortech also recommend this in their documentation FAQ.

The two sensors were run alongside each other with the CPX board measuring the analogue output voltage during the first 15 hour run and second 17 hour run. The power for these runs was provided by the USB powered CPX VOUT. This means the boards were only running at 4.6V rather than the recommended 5.0V (+/- 0.1V).

The analogue output voltage measurement was direct from the sensors without additional external resistors which puts the CPX board more at risk of over (3.3V) voltage on the inputs but this was interactively monitored during the start of the runs. The graphs show the sensors tend to spike for a second or two at start-up. Additional load resistors were added for the subsequent gas tests to lower the voltage to a suitable level.

Something happens at 184 minutes which both sensors pick up, this was probably something environmental like a nearby window being closed. The sensors do appear to be very sensitive to cool draughts.


The downward spikes on MiCS-5524 plot are when the voltage is being checked with a cheap multimeter!


The MQ-3 reaches a stable value in less time on the second phase of the burn-in period. The MiCS-5524 reaches stability far quicker in both runs.


The noise becomes more visible on graphs with a narrower range on y axis. It's remarkably low at around +/- 1mV on MiCS-5524 output to CPX input.

Testing Gases

Sr. X - The Itching. Photograph by Kevin Walters.
Flammable liquids, vapours and gases can be dangerous especially odourless one. It is best to keep samples small and keep liquids away from ignition sources in sealed containers.

The general method was to introduce liquid samples on a soaked, solid-stem cotton bud about 5cm from the sensors for 90 seconds and then remove the sample for 90 seconds and then remove the bowl for 30 seconds to let air circulate and refresh. The breadboard was covered with an upturned glass bowl to reduce the effect of draughts but with a 3cm gap on one side to facilitate adding and removing the samples. Gases were injected from a plastic syringe at the edge of the bowl towards the sensor.

All liquids were at room temperature. The ambient temperature during measurement varied between 24.7 and 25.0 degrees celsius. Temperature and humidity do have a small effect on sensor output. Some more advanced sensors have built-in temperature compensation.

Some prior casual testing revealed the sensors are sensitive to airflow particularly cold draughts.

The graphs show the ratio of the resistance of the sensor with no sample (Ro) vs the the resistance of the sensor with sample (Rs). The data sheets show the reciprocal of this value. The y scale is logarithmic and kept constant across all graphs.

The power supply varied gradually from 5.10V to 4.86V as the batteries discharged. The value per test was used in the calculation of Ro/Rs.

Gas sensors require calibration against reference samples for accurate ppm measurement.
Animated gif showing all test results.

See results for the full set of graphs.

Board Comparison



Power (mA)

Indep. heater power

Enable control

Digital output

Pre-heat (seconds)

Burn-in time (hours)

Board Cost (USD)

Adafruit MiCS-5524

13x20 mm








MQ-3 Module

20x32 mm








The pre-heat time was measured from graphs from sensor power on to when the first reading was within +/- 5% of the steady state value. The MiCS-5524 undershoots initially and then quickly recovers ahead of the MQ-3.

The lower power of the Adafruit MiCS-5524 makes it easier to use and less taxing on power supply/batteries. The enable feature could also be useful for power saving if continuous measurement is not required.

The MiCS-5524 is roughly twice as sensitive in terms of Ro/Rs compared to the MQ-3 for alcohol and gasoline (petrol) but care needs to be taken with very high ppm samples as output will fluctuate.

The SGX MiCS FAQ and SGX General FAQs have entries on airflow:

Does airflow have an influence on the measurement?

Yes. Direct airflow on the sensor surface will change the conductivity of the sensor by altering the heated layer temperature. That is why SGX Sensortech recommends placing the sensor behind a Teflon membrane in most applications. The Teflon membrane allows diffusion of the gases, while reducing the influence of the air speed.

Does the gas need to be flowing across the Metal Oxide Semiconductor sensor?

Stable sensor performance relies in part to diffusion control. A minimum gas flow is required to replace gas reacted by the sensor.

Going Further

Ideas for Areas to Explore

  • Compare the MiCS-5524 with the i2c Sensirion SGP30 and AMS CCS811.
  • Monitor alcohol fermentation processes.
  • Add a sensor to a mobile robot to seek out or map gases.
  • Investigate other MQ sensors to determine their ability to distinguish between different flammable gases. Compare with others like Figaro.
  • Detect local graffiti artists using aerosol paints by sampling outdoor air.
  • Test other household products like nail polish remover (ketones), antifreeze (diols), vinegar (carboxylic acid) and old fashioned smelling salts (ammonia).
  • Investigate different power supplies to look for effects of power supply related noise and possible compensation techniques for low frequency noise. An extra analogue input (with appropriate voltage scaling to 3.3V) could be used to monitor/check 5V power.
  • Check behaviour of sensors with low power supply voltage. The analogue output appears to go up substantially, presumably due to the lower heater temperature.
  • Explore other "sensors". A zinc-air battery may be viable for oxygen detection, see The World's Cheapest Oxygen Sensor.
  • Build an "electronic nose" (olfaction) using an array of different sensors, see Michael Madsen's very thorough, cheap electronic nose research.

Related Projects

Further Reading

Adafruit SGP30 Air Quality Sensor Breakout - VOC and eCO2

Breathe easy with the SGP30 Multi-Pixel Gas Sensor, a fully integrated MOX gas sensor. This is a very fine air quality sensor from the sensor experts...

Adafruit CCS811 Air Quality Sensor Breakout - VOC and eCO2

Breathe easy - we finally have an I2C VOC/eCO2 sensor in the Adafruit shop! Add air quality monitoring to your project and with an Adafruit CCS811 Air Quality...

Adjustable breadboard power supply kit

This kit is for making your own breadboard-friendly very low dropout adjustable power supply. A good power supply is essential to electronic projects. While there are many existing...
Safety critical carbon monoxide (CO) detection and alarms are best left to commercial appliances from reputable suppliers.
This guide was first published on Oct 28, 2018. It was last updated on Oct 28, 2018.