ESP8266 WiFi Smart Plug Using NodeMCU

We have already discussed some ESP8266 NodeMCU based projects in previous. Now we are going to build a so-called popular WiFi Smart Plug using the Blynk application. In Home Automation System in our daily life, we all love to control our devices using just one device or main controller. WiFi Smart Plug is one such device that helps us to do that very easily. It allows you to control almost every wired device like table fan, lights, AC, etc. In my case, I have long wanted to make such WiFi Smart Plug that would be able to switch my AC on/off.

Many of that WiFi Smart Plugs are available on today’s market, but these smart plugs are pretty expensive to buy. So making your own WiFi Smart Plug like “Sonoff” is more interesting and quite easy. Also, it is easy to control, just plug it into any existing socket and on the other hand plug any electronic device into the smart plug. Then just keep the main switch of the existing socket always on and control devices from your smartphone directly.

What is WiFi Smart Plug?

A WiFi Smart Plug is like a power-point adapter. It fits between your power socket and the appliance you wish to plug in. Most of the smart plugs communicate (any Wi-Fi network) to a central control hub. Then, the hub uses your Wi-Fi to send information to an app on your smartphone.

Principle Behind the WiFi Smart Plug

The principle behind this WiFi Smart Plug is to turn on and off of devices from your smartphone or any other controlling device. It’s very simple, just plug it into a socket and turn the power on. Now plug any devices or lamp into the WiFi socket. That’s it. Now the AC power from the main socket gives the power to the WiFi Smart Plug. By the user’s command from the android app, it turns on and off the following devices.

Project

Wifi smart plug
WiFi Smart Plug

Circuit Diagram

wifi smart plug
WiFi Smart Plug Circuit Diagram

Components Required

  • ESP8266 WiFi Module (ESP-01/NodeMCU)
  • 5V Relay Module
  • 5V AC to DC Hi-Link Converter
  • 3 Pin Multiplug for Enclosure
  • Any WiFi Router/Mobile Hotspot Connection
  • Vero board
  • Wire
  • AC Source

Pin Description Used in This Circuit

  • VCC: Power supply pin of ESP8266 which can be supplied with 3.3V DC.
  • GND: Ground reference pin of ESP8266 for ground supply to the circuit.
  • RST: It is used to reset the module and it is an active LOW pin.
  • GPIO16: For enabling reset pin.
  • GPIO5: For output of relay module.

How to Program NodeMCU Using Arduino IDE?

To use the Arduino IDE software to program the NodeMCU, we need to first install the appropriate board into the IDE software. For this copy the following link (http://arduino.esp8266.com/stable/package_esp8266com_index.json) and paste it into the blank box as shown in the picture.

First, click Preferences in the File menu and enter the copied link in the Additional Board Manager URLs part. Then press OK.

Next, find the ESP8266 option in Boards>boards manager from the Tools menu. Then install the ESP8266 board. After successful installation, we can compile code in IDE software.

Blynk Application Setup for WiFi Smart Plug

We are going to use the Blynk app as our IoT server to enable devices to communicate with the cloud server. Install new Blynk IoT application from smartphone and login or sign up to the app. After open click on the Settings icon from the upper right corner and click Add Template and name it.

Then open this and click again on another type of settings icon from the upper right corner. We can see the template id and we need to copy it for coding purposes. From there choose desired Data Stream button and select the mode for the Switch option. That’s it.

Now back once and click on the triple bar icon from the right upper corner. From there choose the Button icon. Then click on this button icon and set the Data Stream value to zero and mode to Switch.

After that, back to the home screen and click on Add New Device. After the WiFi scan, the available devices will be shown there. Then select the device and control it through this app.

Benefits of WiFi Smart Plug

  • A smart plug can turn any of your existing appliances and electrical devices into smart objects that can communicate with other smart products in your home.
  • Using the smartphone app, you can turn appliances on and off remotely anywhere in the world and even check to see if you left an appliance running after you’ve left your home.
  • You can also monitor how much energy an appliance used directly from your smartphone. Smart plugs will even notify you if a device suddenly starts using unusual amounts of energy.
  • Burglars often target homes which is empty. WiFi Smart Plugs can be used to improve home security by turning lights and appliances on and off while you’re on vacation. Burglar will think you are home while you are far from home.
  • Using a smart plug, you can control your devices also with voice commands like Google Assistant, Alexa, Siri, etc.

NodeMCU Code

For compiling code, we first need some library files that are all included in this link Blynk Library Files. Just download it and paste it all with the main NodeMCU code. That’s it.

3 thoughts on “ESP8266 WiFi Smart Plug Using NodeMCU”

Leave a Comment