System Architecture

Block Diagram

Kitchen Analyzer sensor inputs into the ESP32 and the I2C display output PIR sensor MQ-2 gas DHT22 Status LED ESP32 LOLIN32 MCU GPIO 34: PIR, EXT0 wake, analog in GPIO 32: MQ-2 analog out, ADC1_CH4 GPIO 13: DHT22 1-Wire, bidirectional GPIO 22: status LED, digital out I2C: GPIO 17 SDA, GPIO 19 SCL I2C 16x2 I2C LCD Address 0x27, PCF8574 I/O expander
Every wake-up reads the sensors, refreshes the display and goes back to sleep, which is what makes the battery last.

Operational State Machine

  1. DEEP SLEEP: CPU and peripherals are unpowered. RTC controller listens on GPIO 34 (ext0 high level).
  2. WAKE & INITIALIZE: PIR detects movement. MCU boots, configures I2C, initializes LCD backlight, calibrates MQ-2 sensor, and queries DHT22.
  3. ACTIVE SENSING LOOP: Every 1,000 ms, sensor values are read, formatted, and written to the 16x2 LCD. The 20-second countdown timer resets upon motion.
  4. TIMEOUT & SLEEP PREPARATION: If no motion is detected for 20 seconds, LCD backlight is turned off, EXT0 interrupt is armed, and deep sleep is entered.