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

Build an ESP32 Smart Home Hub: MQTT, Sensors & DIY Automation

Learn how to build an ESP32 smart home hub for DIY home automation. Connect motion, door and temperature sensors, publish readings over MQTT, create a dashboard, and design simple IF/THEN rules for low-voltage outputs and alerts.

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.

ESP32 home automation: how this project works

An ESP32 is a Wi-Fi-enabled microcontroller that can read electronic sensors and control low-voltage outputs. In this build, it reads temperature, motion and door status, then sends messages to an MQTT broker. A dashboard can subscribe to those messages and display the readings. Automation rules decide when to send alerts or switch a demonstration load.

1. Sense

A DHT22 reads temperature and humidity; a PIR detects motion; a door contact reports open or closed.

2. Communicate

MQTT carries short messages between the ESP32, a broker and your dashboard. The broker is a separate service, not a feature automatically provided by the ESP32.

3. Automate

Define clear rules for alerts and low-voltage outputs. A dashboard and phone notifications require additional software and configuration.

Before you begin: This article is a system overview and wiring guide, not a complete downloadable firmware package. The IF/THEN example below is pseudocode, not code you can upload directly to the Arduino IDE.

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. Add one sensor at a time and test it before connecting the next module. This makes wiring mistakes much easier to diagnose.

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 demonstration loads only. Do not wire household mains electricity to a breadboard or beginner relay setup. Check the voltage and current ratings of each module and use appropriate protection.
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

ESP32 smart home and MQTT video tutorials

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.

Open on YouTube

Open on YouTube

Open on YouTube

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.

⚡ Browse ESP32 Starter Kits

Share this tutorial