diy esp32 smart plug

DIY ESP32 Smart Plug: Control Your Home Effortlessly

By Michael Smith
AD

Transform your home into a smart haven with the ESP32, a low-cost, yet powerful microcontroller that is revolutionizing home automation. One of the easiest ways to get started is by creating a DIY smart plug, allowing you to control your appliances remotely and automate tasks with ease. In this guide, we'll dive into the world of the ESP32, explore its use cases, and step you through creating your own DIY smart plug.

The ESP32 is a game-changer in the IoT (Internet of Things) realm, offering dual-core processing power, built-in Wi-Fi and Bluetooth, and a wealth of GPIO (General Purpose Input/Output) pins for DIY projects. With its low cost and extensive capabilities, it's no wonder the ESP32 is the backbone of countless smart home projects, including our DIY smart plug.

Understanding the ESP32 and DIY Smart Plugs

At its core, a smart plug is a device that enables you to control your appliances remotely via a smartphone app or voice commands. By pairing an ESP32 with a USB power relay and connecting it to your home network, you can create a fully functional, customizable DIY smart plug.

AD
The 10 Best ESP32 Smart Home Projects
The 10 Best ESP32 Smart Home Projects
Simulate ESP32 Projects in VS Code with Wokwi (Beginner Guide!)
Simulate ESP32 Projects in VS Code with Wokwi (Beginner Guide!)
📲 Get Live Sensor Readings from Your ESP32 via Telegram!
📲 Get Live Sensor Readings from Your ESP32 via Telegram!

Before we dive into the build process, let's explore the key components of your DIY smart plug and understand their roles.

The ESP32

The ESP32 is the brain of your DIY smart plug, handling all the processing tasks and connecting to your home's Wi-Fi network. It supports multiple protocols, including MQTT, CoAP, and HTTP, making it highly versatile for different automation platforms like Home Assistant, IFTTT, or NodeRED.

10 ESP32 Skills Every Maker Should Learn
10 ESP32 Skills Every Maker Should Learn
GitHub - danpeig/ESP32EnergyMonitor: Multiple phase DIY energy consumption monitor using ESP32 and ESPHome
GitHub - danpeig/ESP32EnergyMonitor: Multiple phase DIY energy consumption monitor using ESP32 and ESPHome
ESP32 Smart Home System With Alexa App & Manual Switches
ESP32 Smart Home System With Alexa App & Manual Switches

With its built-in Wi-Fi and Bluetooth, the ESP32 can create its own access point or connect to an existing network. For our DIY smart plug, we'll utilize its Wi-Fi capabilities to connect to your home router and integrate it with your smart home ecosystem.

USB Power Relay

The USB power relay is the enabling factor that allows you to control your appliances from anywhere. When the ESP32 sends a command, the relay switches the power flow, turning your connected device on or off. In our DIY smart plug, we'll use the popular SRD-05WD relay module for ease of use and compatibility.

AD

With just two pins (VCC and GND), this relay can be easily controlled by the ESP32. Plus, it's compact, making it perfect for space-constrained projects like our DIY smart plug.

🌐 ESP32 + IFTTT = Smart Home Magic! ✨
🌐 ESP32 + IFTTT = Smart Home Magic! ✨
ESP8266 EcoPlug Wifi Smart Outlet MQTT Mod for Less Than $15
ESP8266 EcoPlug Wifi Smart Outlet MQTT Mod for Less Than $15
How to Smarten a Plugboard With ESP32
How to Smarten a Plugboard With ESP32
an electronic device is shown in this poster, with instructions on how to use it
an electronic device is shown in this poster, with instructions on how to use it
🌐 ESP32 Static IP Address – Assign a Fixed IP in Arduino IDE!
🌐 ESP32 Static IP Address – Assign a Fixed IP in Arduino IDE!
DIY Home Energy Monitor with ESP32, CT Sensor (SCT-013), and EmonLib
DIY Home Energy Monitor with ESP32, CT Sensor (SCT-013), and EmonLib

Building Your DIY ESP32 Smart Plug

Now that you're familiar with the key components, let's assemble your DIY smart plug. This section will guide you through the hardware and software setup, step by step.

Before you begin, gather the required components:

AD
  • ESP32 development board (e.g., ESP32-WROOM-32 or ESP32-DevKitC)
  • SRD-05WD USB power relay module
  • Jumper wires (male to female)
  • USB cable for power and programming
  • Micro USB power adapter (for the relay)

Hardware Assembly

Connect the components using jumper wires as follows:

ESP32 Bluetooth + Manual Home automation - IotCircuitHub
ESP32 Bluetooth + Manual Home automation - IotCircuitHub
ESP32 Pinout Guide: GPIO, Buttons & Ports Explained
ESP32 Pinout Guide: GPIO, Buttons & Ports Explained
Plug It - Open Source Smart Plug
Plug It - Open Source Smart Plug
Smart Plug With Esp32/Esp8266 and Solid State Relays
Smart Plug With Esp32/Esp8266 and Solid State Relays
DAY 5 — ESP32 Explained | Wi-Fi & Bluetooth Microcontroller Notes
DAY 5 — ESP32 Explained | Wi-Fi & Bluetooth Microcontroller Notes
ESP8266 NodeMCU Blynk IoT DIY Smart Plug - IotCircuitHub
ESP8266 NodeMCU Blynk IoT DIY Smart Plug - IotCircuitHub
DIY Smart Energy Meter With ESP32 + Home Assistant
DIY Smart Energy Meter With ESP32 + Home Assistant
ESP32 Over-the-Air (OTA) Updates – Wireless Firmware Upload
ESP32 Over-the-Air (OTA) Updates – Wireless Firmware Upload
an electronic device with the words voice control with esp8366 and google assistant
an electronic device with the words voice control with esp8366 and google assistant
ESP32 Home Automation using ESP RainMaker
ESP32 Home Automation using ESP RainMaker
5 Must-Try ESP32 Projects for Beginners (2025 Edition)
5 Must-Try ESP32 Projects for Beginners (2025 Edition)
  • GND (ESP32) → GND (relay)
  • 3V3 (ESP32) → VCC (relay)
  • GPIO23 (ESP32) → IN (relay)

Once connected, ensure all components are correctly powered:

  • Connect the ESP32 to your computer via USB for programming.
  • Power the relay using a micro USB adapter.

Software Configuration

To control your DIY smart plug, you'll need to flash custom firmware onto the ESP32. We'll use the popular Espressif IDF (IoT Development Framework) and the Arduino platform for this process.

AD
  1. Install the Arduino IDE and add the ESP32 board package following the official guide: https://www.instructables.com/Arduino-ESP8266-The-Incomplete-Guide/
  2. Create a new sketch, and replace the code with the following (or use a pre-made sketch like the one found here: https://github.com�ေး�ੁ मालrouille/esp32-relay-control):
```cpp #include #include // Replace with your network credentials const char* ssid = "your_SSID"; const char* password = "your_password"; const int relayPin = 23; AsyncWebServer server(80); // Set GPIO23 as output void setup() { Serial.begin(115200); pinMode(relayPin, OUTPUT); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } Serial.println(WiFi.localIP()); server.on("/relay", HTTP_POST, [](AsyncWebServerRequest *request) { String action = request->getParam("action")->value(); digitalWrite(relayPin, action.toInt()); }); server.begin(); } void loop() { // put your main code here, to run repeatedly } ```

Replace `your_SSID` and `your_password` with your home network credentials, then flash the code onto your ESP32.

Controlling Your DIY Smart Plug

With the firmware flashed onto your ESP32, it's time to control your DIY smart plug. To do this, find the IP address of your ESP32 in the Arduino IDE's serial monitor or using a network scanning app like Fing.

Once you have the IP address, open a web browser and navigate to that address. You should see a simple interface with a button labeled "Relay." Clicking this button will toggle the connected device on or off.

Congratulations! You've just created a fully functional DIY smart plug using the ESP32. By integrating this project with a smart home hub like Home Assistant or using IFTTT applets, you can automate tasks, create routines, and control your appliances remotely.

Expanding Your Smart Home with ESP32

Now that you've dipped your toes into the world of DIY smart home projects with the ESP32, you might be eager to explore further. The possibilities are endless, ranging from creating smart light bulbs to building your own weather station. With the ESP32's extensive capabilities and low cost, your only limitation is your imagination.

To get started on your next project, consider exploring these resources:

As you embark on your next smart home adventure, remember that the DIY spirit is all about learning, tinkering, and experimenting. Embrace the process, and you'll soon unlock the full potential of the ESP32 in your quest to create the ultimate connected home.

Happy creating, and until next time, stay connected!

AD