Course Content
IoT Engineering Course using ESP32 with 12 Real-World Projects

📦Smart Home Automation System

Circuit Diagram & Complete GPIO Planning


🎯 Objective of This Lesson

Students will learn:

  • How to plan GPIO pins properly

  • How to distribute power safely

  • How to connect multiple sensors correctly

  • How to avoid common ESP32 mistakes

  • How to design a stable Smart Home hardware setup


🧩 Components Used

  • ESP32

  • DHT11 Temperature Sensor

  • Ultrasonic Sensor (HC-SR04)

  • MQ3 Gas Sensor

  • Servo Motor (Door Lock)

  • 2-Channel Relay Module (AC + Pump)

  • External 5V Power Supply


🧠 STEP 1 – GPIO Planning (Very Important)

We must avoid:

  • Boot pins

  • ADC conflicts

  • Input-only confusion

  • Power overload


📌 Final GPIO Planning Table

Device ESP32 Pin Type
DHT11 GPIO 4 Digital Input
Ultrasonic TRIG GPIO 5 Digital Output
Ultrasonic ECHO GPIO 18 Digital Input
MQ3 (Analog) GPIO 34 Analog Input
Servo (Door Lock) GPIO 13 PWM Output
AC Relay GPIO 26 Digital Output
Pump Relay GPIO 27 Digital Output

🧠 Why These Pins?

✅ GPIO 34

  • Input only

  • Perfect for analog (MQ3)

✅ GPIO 13

  • PWM supported

  • Safe for servo

✅ GPIO 26 & 27

  • Stable digital output

  • Good for relay modules

✅ GPIO 4, 5, 18

  • Safe general-purpose pins

  • No boot conflict


⚡ STEP 2 – Power Planning (Critical Section)

This project has multiple 5V devices.


🔋 Power Requirements

Device Voltage Notes
ESP32 5V (USB) Internal 3.3V logic
DHT11 3.3V or 5V Safe
Ultrasonic 5V Needs stable supply
MQ3 5V Heater element inside
Servo 5V High current device
Relay 5V Coil current

🚨 IMPORTANT RULE

❌ Do NOT power everything from ESP32 5V pin.

Servo + Relay + MQ3 together draw high current.


✅ Recommended Power Setup

Use:

👉 External 5V 2A Adapter

Power distribution:

5V Adapter

Breadboard Power Rail

Servo
Relay Module
MQ3
Ultrasonic

ESP32 powered separately via USB.

⚠ Connect ALL GNDs together.

Common ground is mandatory.


🧠 STEP 3 – Individual Component Wiring


🔹 1️⃣ DHT11 Connection

DHT11 Pin ESP32
VCC 3.3V
GND GND
DATA GPIO 4

🔹 2️⃣ Ultrasonic Sensor

Ultrasonic ESP32
VCC 5V
GND GND
TRIG GPIO 5
ECHO GPIO 18

⚠ Optional: Use voltage divider for ECHO (safer).


🔹 3️⃣ MQ3 Gas Sensor

MQ3 ESP32
VCC 5V
GND GND
AO GPIO 34

🔹 4️⃣ Servo Motor (Door Lock)

Servo ESP32
Red External 5V
Brown GND
Orange GPIO 13

🔹 5️⃣ Relay Module

Relay ESP32
VCC 5V
GND GND
IN1 GPIO 26 (AC)
IN2 GPIO 27 (Pump)

🧠 STEP 4 – Circuit Layout Strategy

When placing on breadboard:

1️⃣ Keep power rails clean
2️⃣ Separate high-current devices
3️⃣ Avoid loose jumper wires
4️⃣ Keep servo wires short
5️⃣ Mount ultrasonic properly


🔒 STEP 5 – Safety Considerations

⚠ Never connect real AC directly during testing.
Use bulb for simulation.

⚠ Keep gas testing controlled.
⚠ Ensure pump dry-run protection.
⚠ Check relay isolation.


🧠 STEP 6 – Block Diagram (Conceptual)

DHT11 → 
Ultrasonic →
MQ3 →        ESP32 → Relay (AC)
PIR → Relay (Pump)
Servo →

Blynk Cloud

🎯 Common Mistakes to Avoid

  • Using GPIO 0, 2, 15 incorrectly

  • Forgetting common ground

  • Powering servo from ESP32 5V

  • Using delay() in final code

  • Not testing individually


🎓 Learning Outcomes

After this lesson, students will:

  • Understand GPIO planning

  • Learn safe power distribution

  • Design multi-device circuits

  • Avoid hardware failures

  • Think like embedded engineers

Scroll to Top