ESP32 AI smart home hub hero image
WolfieWeb GodMode01 Advanced IoT Tutorial

Build an AI Smart Home Hub with ESP32

Turn an ESP32 into a practical smart-home brain that reads sensors, publishes MQTT messages, controls relay outputs, updates a dashboard, and triggers phone alerts using simple IF/THEN automation rules.

What you are building

This is not another tiny blinking LED project. You are building a real IoT control system: sensors feed the ESP32, the ESP32 publishes events, a dashboard displays status, and automation rules decide what happens next.

Core build: DHT22 temperature/humidity, PIR motion, magnetic door sensor, light sensor logic, OLED status screen, buzzer warning output, and relay control for a low-voltage smart light or fan demo.

Parts needed

Controller

ESP32 Dev Board, USB cable, breadboard, jumper wires, and a stable USB power source.

Sensors

DHT22, PIR motion sensor, magnetic reed/door sensor, optional LDR light sensor, and resistors.

Outputs

OLED display, low-voltage relay module, buzzer, LED/smart light demo load, and optional ESP32-CAM node.

Step 1

Wire the ESP32 smart-home hub

Start with clean power rails, then connect one module at a time. Do not connect every sensor at once and then wonder why the project is dead. That is how beginners bury themselves.

ModuleESP32 PinPurpose
DHT22GPIO 4Temperature and humidity data
PIR MotionGPIO 27Motion detection
Relay INGPIO 5Low-voltage light/fan control
Door SensorGPIO 14Open/closed state
OLED SDA/SCLGPIO 21 / GPIO 22I2C display status
BuzzerGPIO 26Local warning output
Safety: Use low-voltage DC loads while learning relay wiring. Do not switch wall power unless you understand isolation, enclosures, fuse protection, and local electrical rules.
Step 2

Test hardware before adding the network

First confirm the DHT22 readings in the serial monitor. Then test the PIR. Then test the relay with a safe LED or low-voltage lamp. Only after that should you add MQTT, dashboard tiles, and phone alerts.

Hardware first Network second Automation last
Step 3

Add MQTT network flow

The ESP32 should publish sensor states to an MQTT broker. The dashboard subscribes to those topics and shows the current home status. Phone alerts trigger when motion, heat, or door events cross your rule limits.

  • home/motion — PIR status
  • home/temp — DHT22 temperature and humidity
  • home/door — open/closed state
  • home/relay/set — relay command from dashboard
  • home/alert — phone alert events
Dashboard

Build the dashboard like a control panel

Your dashboard should show motion, temperature, humidity, door state, light level, relay state, and alert history. Keep the buttons large and obvious. A dashboard that looks cool but confuses the reader is not helping them.

Step 4

Create the automation rules engine

This is where the project becomes advanced. The ESP32 watches conditions and reacts. The logic stays simple enough for a reader to understand, but powerful enough to feel like a real smart-home system.

// Example rule logic
IF motion_detected AND room_is_dark
THEN turn_on_light_relay

IF temperature > 80F
THEN turn_on_fan_relay AND send_alert

IF door_open AND system_armed
THEN sound_buzzer AND publish home/alert
Advanced Behavior

Make the home react intelligently

Motion can trigger light. Temperature can trigger a fan relay. A door event can trigger a phone alert. This is the difference between a connected gadget and a connected system.

Build gallery

Video lightbox section

These video cards open in a lightbox so the reader stays on your page. If YouTube blocks an embed, each card also includes a direct “Open on YouTube” fallback link.

Reader takeaway

When this project is finished, the reader understands more than wiring. They understand how an IoT system thinks: sensors create events, MQTT moves messages, dashboards show state, and automation rules trigger action.

⚡ Shop ESP32 Starter Kits

Share this tutorial