SMART LAB · Circuit

How every sensor connects to the ESP32

Wiring diagram

ESP32 DevKit (30-pin) seen from above: antenna at the top, USB at the bottom. Every sensor's VCC, GND and signal wire is shown.

antenna ESP32 DevKit V1 USB EN VP VN G34 G35 G32 G33 G25 G26 G27 G14 G12 G13 GND VIN G23 G22 TX RX G21 G19 G18 G5 TX2 RX2 G4 G2 G15 GND 3V3 3V3 rail GND rail IR B inside the door VCC OUT GND IR A outside the door VCC OUT GND DHT22 temp & humidity VCC DATA GND Flame flame sensor VCC D0 GND MQ-2 gas / smoke VCC AO GND Buzzer + − VIN 5 V GND 10k 20k Power (+) Ground Signal (colour per sensor) Joined wires Wires that cross without a dot are not connected.
← Swipe to see the whole diagram →

Flame sensor

Sensor pinESP32
VCC3V3
GNDGND
D0 (digital out)G15
A0not used
Use D0, not A0. The module's D0 LED lights when it sees a flame. Turn its blue screw to set the distance.

MQ-2 gas / smoke

Sensor pinESP32
VCCVIN (5 V)
GNDGND
AO (analog out)divider → G34
DOnot used
MQ-2 AO ── 10 kΩ ──┬── G34
                   │
                 20 kΩ
                   │
                  GND
AO can reach 5 V; G34 accepts 3.3 V at most. The divider brings it down safely. Clean air reads about 260; the alarm triggers at 800. Allow 2 minutes of warm-up.

IR sensors (people counter)

Sensor pinIR A (outside)IR B (inside)
VCC3V33V3
GNDGNDGND
OUTG18G19
  OUTSIDE  │  door  │  INSIDE
   [IR A]  │ ─────► │  [IR B]

 A then B (within 1.5 s) = entry
 B then A (within 1.5 s) = exit
Mount them 10–15 cm apart at waist height, pointing across the doorway. Adjust each blue screw so the LED lights only when someone passes.

DHT22 temperature & humidity

Sensor pinESP32
+ / VCC3V3
OUT / DATA / SG4
− / GNDGND
Wire by the labels printed on the module, since pin order differs between brands. A bare 4-pin DHT22 also needs a 10 kΩ resistor from DATA to 3V3.

Buzzer

Buzzer pinESP32
+ (long leg)G25
−GND
Use an active buzzer (it beeps by itself on 3–5 V). For a louder buzzer, drive it through an NPN transistor (2N2222 / S8050) with a 1 kΩ base resistor.
Never use G0, G2 or G12 for the buzzer: they control how the ESP32 boots.

Power & ground

RailFeeds
VIN 5 V (from USB)MQ-2 heater
3V3DHT22, flame, IR A, IR B
GNDEvery sensor and the buzzer
All grounds must be connected together. Use a short, good-quality USB data cable; the MQ-2 heater draws about 150 mA, and a weak cable causes USB dropouts.
The fan runs separately from its own 12 V adapter.

Pin summary

Matches the pin definitions in the firmware.

ESP32 pinConnected toTypeIn code
G4DHT22 DATADigitalDHT_PIN
G15Flame sensor D0Digital inputFLAME_PIN
G18IR A OUT (outside)Digital inputIR_A_PIN
G19IR B OUT (inside)Digital inputIR_B_PIN
G25Buzzer +Digital outputBUZZER_PIN
G34MQ-2 AO (via divider)Analog inputMQ2_AO_PIN
SMART LAB · Dashboard · Code · GitHub