Automatic exhaust fan that turns on for smoke (Arduino Nano, MQ-2 and a relay)

A frying pan starts to smoke. An MQ-2 gas and smoke sensor notices it, a relay clicks and a 12 V fan pulls the smoke away. When the air is clear again the fan stops.

  • 6 parts
  • 6 wiring steps
  • Arduino code
  • 12 V supply

Quick answer

The short version. Every pin is in the full wiring below.

What you need

  • Arduino Nano
  • MQ-2 gas and smoke sensor module
  • 1-channel 5 V relay module
  • 12 V DC fan, 80 mm, about 75 mA
  • 5 V 2 A supply for the Arduino side
  • 12 V supply for the fan

How to wire it

  1. 5V to the Nano's 5V pin, the MQ-2's VCC and the relay module's VCC.
  2. MQ-2 AO to Nano A0.
  3. Nano D8 to relay IN.
  4. 12 V plus to the relay's COM.
  5. The 5 V side and the 12 V side share no wire.
  6. The picture shows the sensor side of the MQ-2 module.

Before you power it: Everything runs on 5 V and 12 V. Never switch a mains fan with this build. The MQ-2 is not a smoke alarm, so never rely on it to warn you of a fire; fit a certified smoke detector. Keep the sensor's hot heater away from anything that burns.

A purple Automatic Exhaust Fan title above a 1-channel relay module, an Arduino Nano, a 12V DC supply, a 5V 2A supply, a blue MQ-2 gas sensor module and an 80 mm 12V fan, all wired with red, black, blue and orange wires. At the bottom a frying pan on a hot plate printed Wirecora sends smoke up toward the sensor
The circuit as wired in the Short. Every wire end is a real pin; the netlist was checked before the video went out.

Parts list

  • Arduino Nano
  • MQ-2 gas and smoke sensor module (pins VCC, GND, DO, AO; the Short uses VCC, GND and AO; its heater draws about 160 mA)
  • 1-channel 5 V relay module, low-level trigger, header VCC, GND, IN, terminals NO, COM, NC, contacts 10 A at 30 V DC
  • 12 V DC fan, 80 mm, about 75 mA (red lead plus, black lead minus)
  • 5 V 2 A supply for the Arduino side (about 0.26 A in use)
  • 12 V supply for the fan

Wiring, step by step

  1. 5V to the Nano's 5V pin, the MQ-2's VCC and the relay module's VCC. GND to the Nano's GND, the MQ-2's GND and the relay module's GND.
  2. MQ-2 AO to Nano A0. DO is not connected.
  3. Nano D8 to relay IN.
  4. 12 V plus to the relay's COM. Relay NO to the fan's red lead. The fan's black lead to 12 V minus. NC is unused.
  5. The 5 V side and the 12 V side share no wire. Only the relay contacts join the fan to its supply.
  6. The picture shows the sensor side of the MQ-2 module. On a real board the pin names are on the back, so wire by name, not by position.

How it works

  1. The sketch reads A0. Above 400 it pulls D8 LOW, and a low-level-trigger relay module turns on at LOW. Below 300 the fan goes off. The gap between 300 and 400 stops chattering.
  2. The relay's COM to NO contact joins the fan to 12 V. The fan takes about 75 mA, a small part of the contacts' 10 A rating.
  3. The heater takes 5 V / 31 ohm = about 161 mA and the relay module about 75 mA, so the 5 V side uses about 0.26 A of its 2 A.
  4. The relay input draws about 2 to 4 mA from the Nano pin, well under the 20 mA limit.
  5. No diode is needed across a small brushless fan, because the fan has its own driver chip. The relay coil's flyback diode is on the module.
  6. On a high-level-trigger relay module, swap HIGH and LOW in the sketch.

The code: smoke_exhaust_fan.ino

The Arduino code for this circuit is in the Wirecora Discord, in the channel #arduino-code (owner’s choice, 14 October 2026: the code lives where you can ask about it). It is a plain .ino file you can download there.

The sketch the Short was animated from; it has not been run on a real board yet. The relay module is low-level trigger: LOW = fan on. For a high-level-trigger module swap HIGH and LOW. Pin 8 is set HIGH before pinMode so the relay does not click at power-up.

Get the code in #arduino-code

What the video simplifies

  • The smoke, the reading and the 6 second cycle are a model. A real MQ-2 needs minutes of warm-up, and over 48 hours when new. It reads high while cold and reacts over seconds. The value 400 is a demo threshold.
  • It also reacts to LPG, alcohol and hydrogen, and it is no certified smoke alarm.
  • The fan speeds up and stops faster than a real one, the blades are drawn slower than real, and the parts are larger than the pan.
  • A real sensor sits higher, beside the hood and away from heat, steam and grease. A real exhaust fan is mounted in a wall.
  • Fixed from the viral original: a safe 12 V fan on its own supply in place of the 230 V mains fan.
  • This circuit was checked by simulation and datasheets, not built.

You found this by searching. Here's the whole path.

  1. Read how it works
  2. See it work
  3. Build it
  4. Show it
Next: see it work

Thirty seconds of video shows the circuit doing its job.

Then build it

Everything runs on 5 V and 12 V. Never switch a mains fan with this build. The MQ-2 is not a smoke alarm, so never rely on it to warn you of a fire; fit a certified smoke detector. Keep the sensor's hot heater away from anything that burns.

Then show it

Built it, or stuck halfway? Post a photo in the Wirecora Discord. Questions get an answer every day.