Carbon monoxide (CO) guard (hobby)

An MQ-7 sensor with a buzzer and display for a garage, boiler room or generator shed. A hobby add-on, not a certified CO alarm.

Safety Board: ESP32 DevKit V1 (WROOM-32) Level: ●●○ ⏱ 1–2 h

⚠ Caution

A hobby gas sensor is not a certified alarm and does not replace a real gas or smoke detector.

A hobby sensor with an unusual heater

According to the datasheet the MQ-7 should have its heater switched between a high and a low voltage, in a cycle of a minute or two. Most modules just give it a constant 5 V, and then the reading is less meaningful. If you want to do it right, control the heater with PWM and a transistor and read the sensor at the end of the low phase.

What it can and cannot do

It responds to alcohol, hydrogen and other gases too, so a hand sanitiser can raise an alarm. Calibrate in clean air and let the sensor burn in for a day. CO is slightly lighter than air and mixes with it, so mount at about head height, not on the floor.

  • Use it in the garage, the boiler room and next to the generator as an extra signal.
  • The real protection is a certified CO alarm that meets EN 50291, placed outside the bedroom door.
  • A buzzer and a display make it useful offline; a message makes it useful when you are away.

Components

  • ESP32 DevKit V1 (30 pin, WROOM-32)
  • MQ-7 carbon monoxide (CO) sensor module
  • Active buzzer module 5V
  • OLED 0.96" 128x64 I2C SSD1306
  • Resistor kit 1/4W (1k, 2k, 4.7k, 10k, 22k, 100k)

Wiring

Module Module pin ESP32 pin Note
MQ-7 VCC / GND 5V / GND warm-up 3 minutes, burn in 24-48 h when new
MQ-7 AO analog GPIO34 via 10 kΩ / 20 kΩ divider AO can reach 5 V
Buzzer + signal GPIO25
OLED SDA / SCL I2C GPIO21 / GPIO22 optional display

Code

#include <WiFi.h>

const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";

bool connectWiFi(uint32_t timeoutMs = 20000) {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  uint32_t t0 = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - t0 < timeoutMs) {
    delay(250);
    Serial.print(".");
  }
  Serial.println();
  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
    return true;
  }
  return false;
}
#include <WiFiClientSecure.h>
#include <HTTPClient.h>

const char* TG_TOKEN = "123456:ABC-YOUR-BOT-TOKEN";   // from @BotFather
const char* TG_CHAT  = "YOUR_CHAT_ID";

// Keep the text free of double quotes and line breaks (it is inserted into JSON).
bool telegramSend(const String& text) {
  if (WiFi.status() != WL_CONNECTED) return false;
  WiFiClientSecure client;
  client.setInsecure();   // simple; pin the certificate for production
  HTTPClient http;
  String url = String("https://api.telegram.org/bot") + TG_TOKEN + "/sendMessage";
  if (!http.begin(client, url)) return false;
  http.addHeader("Content-Type", "application/json");
  String body = String("{"chat_id":"") + TG_CHAT + "","text":"" + text + ""}";
  int code = http.POST(body);
  http.end();
  return code == 200;
}
const int PIN_CO = 34, PIN_BUZ = 25;
const int ALARM_DELTA = 500;           // set after watching clean-air values for a day
int baseline = 0; bool alarm = false; uint32_t lastMsg = 0;

int readCo() { long s = 0; for (int i = 0; i < 16; i++) { s += analogRead(PIN_CO); delay(5); } return s / 16; }

void setup() {
  Serial.begin(115200); pinMode(PIN_BUZ, OUTPUT); analogReadResolution(12);
  connectWiFi();
  delay(180000);                       // warm-up
  baseline = readCo();
}
void loop() {
  int v = readCo(); bool a = v - baseline > ALARM_DELTA;
  digitalWrite(PIN_BUZ, a ? HIGH : LOW);
  if (a && (!alarm || millis() - lastMsg > 600000)) { telegramSend("WARNING: possible carbon monoxide. Ventilate and leave the room"); lastMsg = millis(); }
  alarm = a;
  if (!a && v < baseline) baseline = (baseline * 99 + v) / 100;   // slow drift tracking
  Serial.println(v);
  delay(2000);
}

Build tips

  • Burn the new sensor in for 24-48 hours and watch the clean-air value before setting ALARM_DELTA.
  • MQ-7 is meant to be heat-cycled; this simple version trades accuracy for simplicity. Install a certified detector too.

What you need

Buy the parts kit · Estimated total: $10.50

ESP32 DevKit V1 (30 pin, WROOM-32) × 1
$4.00
Buy at AliExpress Buy at Amazon.com
MQ-7 carbon monoxide (CO) sensor module × 1
$2.00
Buy at AliExpress Buy at Amazon.com
Active buzzer module 5V × 1
$0.50
Buy at AliExpress Buy at Amazon.com
OLED 0.96" 128x64 I2C SSD1306 × 1
$2.50
Buy at AliExpress Buy at Amazon.com
Resistor kit 1/4W (1k, 2k, 4.7k, 10k, 22k, 100k) × 1
$1.50
Buy at AliExpress Buy at Amazon.com
🇺🇦 Ukraine🌍 Other countries

Ukraine: we buy and sell these parts ourselves, order them on this site.

Some links are affiliate links: we may earn a commission at no extra cost to you.

Related ideas

⚠ Caution

A hobby gas sensor is not a certified alarm and does not replace a real gas or smoke detector.

Gas / smoke alarm (hobby)

MQ-2 sensor with a buzzer and a web page. A hobby add-on, not a certified detector.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 1–2 h
Pick parts / kit

Freezer / fridge alarm

A DS18B20 probe inside the freezer; a buzzer and a message if the temperature rises or the door stays open.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●○○ Beginner
  • Build time 1–2 h
Pick parts / kit

Water tank level sensor

A waterproof ultrasonic JSN-SR04T measures the level in a tank or well and reports percent.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 1–2 h
Pick parts / kit

← All module ideas →

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.