Built-in project · Arduino Uno R3

Alcohol, hydrogen, ozone and ammonia on A0 to A3, on an Arduino Uno

An MQ-3, MQ-8, MQ-131 and MQ-137 on A0 to A3, printed once a second. Ozone reads lower, not higher: it raises the MQ-131’s resistance. The whole build, an Arduino Uno and 4 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $59. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • Gas sensors change resistance
  • A heater needs warm up time
  • Different gases move the reading different ways
  • Reading four analog pins
  • Difficulty: Beginner
  • Time: About 15 minutes
  • Board: Arduino Uno R3
  • Parts: 6

How it works

Four MQ gas sensors share one breadboard: an MQ-3 for alcohol on A0, an MQ-8 for hydrogen on A1, an MQ-131 for ozone on A2 and an MQ-137 for ammonia on A3. Each module has a small heater and shows the gas level on its AO pin.

The MQ-3, MQ-8 and MQ-137 read higher with more gas. The MQ-131 reads lower for more ozone, because ozone is an oxidizing gas and raises the element's resistance, while the others lower it.

Once a second the sketch prints all four readings on a line. The readings start off at first while the heaters warm up, so wait for them to settle.

Parts list

6 parts, plus the jumper wires. They retail for about $59; on Mokxi they're free.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
Alcohol sensor, MQ-3 pin GNDArduino Uno R3 pin GND
Hydrogen sensor, MQ-8 pin GNDArduino Uno R3 pin GND
Ozone sensor, MQ-131 pin GNDArduino Uno R3 pin GND
Ammonia sensor, MQ-137 pin GNDArduino Uno R3 pin GND
Alcohol sensor, MQ-3 pin VCCArduino Uno R3 pin 5V
Hydrogen sensor, MQ-8 pin VCCArduino Uno R3 pin 5V
Ozone sensor, MQ-131 pin VCCArduino Uno R3 pin 5V
Ammonia sensor, MQ-137 pin VCCArduino Uno R3 pin 5V
Alcohol sensor, MQ-3 pin AOArduino Uno R3 pin A0
Hydrogen sensor, MQ-8 pin AOArduino Uno R3 pin A1
Ozone sensor, MQ-131 pin AOArduino Uno R3 pin A2
Ammonia sensor, MQ-137 pin AOArduino Uno R3 pin A3

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Alcohol, hydrogen, ozone and ammonia: an MQ-3, MQ-8, MQ-131 and MQ-137 on
// A0 to A3.
//
//   MQ-3 AO -> A0   MQ-8 AO -> A1   MQ-131 AO -> A2   MQ-137 AO -> A3
//   every VCC -> 5V   every GND -> GND
//
// The MQ-3, MQ-8 and MQ-137 read higher for more gas. The MQ-131 reads LOWER
// for more ozone: ozone is an oxidizing gas and raises the element's
// resistance, where the others lower it. Each reads off at first, while its
// heater warms up: wait for the numbers to settle.
//
// Drag any sensor's gas level up.

void setup() {
  Serial.begin(9600);
  Serial.println("Mokxi Uno: MQ-3, MQ-8, MQ-131 and MQ-137 on A0 to A3");
}

void loop() {
  Serial.print("alcohol ");
  Serial.print(analogRead(A0));
  Serial.print("  H2 ");
  Serial.print(analogRead(A1));
  Serial.print("  O3 ");
  Serial.print(analogRead(A2));
  Serial.print("  NH3 ");
  Serial.println(analogRead(A3));
  delay(1000);
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

Starts the serial port at 9600 and prints a line naming the four sensors and their pins.

void setup() {
  Serial.begin(9600);
  Serial.println("Mokxi Uno: MQ-3, MQ-8, MQ-131 and MQ-137 on A0 to A3");
}

loop sketch.ino

Reads A0 to A3 with analogRead and prints them with the labels alcohol, H2, O3 and NH3 on one line. Then it waits one second.

void loop() {
  Serial.print("alcohol ");
  Serial.print(analogRead(A0));
  Serial.print("  H2 ");
  Serial.print(analogRead(A1));
  Serial.print("  O3 ");
  Serial.print(analogRead(A2));
  Serial.print("  NH3 ");
  Serial.println(analogRead(A3));
  delay(1000);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The numbers jump around at first This project
    The heaters need time to warm up. Wait for the numbers to settle.
  • Ozone seems backward This project
    That is correct. The MQ-131 reads lower when there is more ozone.
  • The reading is high and drifts after power up. Alcohol sensor
    The heater needs a warm-up time. Wait several minutes, and preheat a new sensor for 24 hours, before trusting any value.
  • The sensor works poorly or the board browns out. Alcohol sensor
    The heater needs about 150 mA at 5 V. Power it from a solid 5 V supply and join ground to the board.
  • Readings are high and drifting right after power on. Hydrogen sensor
    The heater needs time to warm up. Wait a few minutes at least, and a long burn in for a new sensor. It needs a steady 5 V and draws about 150 mA.
  • Numbers do not look like real ppm values. Hydrogen sensor
    The analog output is only a relative level. Turning it into ppm needs calibration in clean air and known gas. Humidity and other gases such as alcohol also change the reading.
  • The reading is high at first and then drops. Ozone sensor
    Metal oxide sensors need a warm up and burn in. Let the heater run for minutes, and for a new sensor, many hours, before trusting readings. Use the readings after warming.
  • The gas value does not match real ppb. Ozone sensor
    The analog value only gives a relative level. For real units, calibrate with a known gas in clean air and use the datasheet curve. Temperature and humidity also change the reading.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.