tutorialspinouttools
Sensors · ESP32-C3

MQ-7 on OLED: Carbon Monoxide (CO)

Free ESP32 & Arduino tutorial · wiring, code & parts · gokul.builds

Overview & Wiring

What it is: The MQ-7 detects carbon monoxide (CO), the invisible, odourless gas from incomplete combustion. Useful for garage, boiler and stove safety projects. How it works: The MQ-7 is designed to be cycled between a high (5V) and low (1.4V) heater voltage for best accuracy, but for a simple relative indicator you can run it at 5V and read AO as an analog level. This sketch shows a relative 0–100 CO level plus raw ADC. Wiring: MQ-7 AO -> GPIO0 MQ-7 VCC -> 5V MQ-7 GND -> GND OLED VCC=3V3, GND=GND, SDA=GPIO4, SCL=GPIO5 VOLTAGE WARNING: divide AO down to under 3.3V for the ESP32-C3 ADC. Libraries: only "Adafruit SSD1306" and "Adafruit GFX Library". On screen / Serial: relative CO level (0–100) and raw ADC. Gotchas: For accurate CO ppm you must implement the high/low heater cycle and calibrate — beyond this intro. Do not rely on a hobby MQ-7 as a life-safety CO alarm; buy a certified detector for that.

Circuit Diagram

MQ-7 on OLED: Carbon Monoxide (CO) wiring diagram for ESP32-C3

Parts You Need

ESP32-C3 SuperMiniBuy →
0.96" SSD1306 OLEDBuy →

Source Code (Arduino / ESP32)

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display(128, 64, &Wire, -1);

#define MQ 0

void setup() {
  Serial.begin(115200);
  Wire.begin(4, 5);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}

void loop() {
  int raw = analogRead(MQ);
  int level = map(raw, 0, 4095, 0, 100);

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("MQ-7 CO");
  display.setTextSize(3);
  display.setCursor(0, 18);
  display.printf("%d", level);
  display.setTextSize(1);
  display.setCursor(0, 52); display.printf("raw %d", raw);
  display.display();

  Serial.printf("CO level: %d  (raw %d)\n", level, raw);
  delay(400);
}
Browse all tutorials ESP32-C3 pinout Calculators