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.

PCB Design

For removing messy wiring and give a clean look, I designed a PCB prototype for this project. It is also helpful for troubleshooting that runs great without any errors. To design this PCB board, I used EasyEDA as it is too easy to use. For ordering PCB for this, I prefer PCBWay.

Gerber file for WiFi Smart Plug Gerber.

PCB View

WiFi Smart Plug 2D
2D View
WiFi Smart Plug 3D
3D View

Order PCB From PCBWay

PCBs are the neatest and professional-looking among the assembled circuit types. Any electronics circuit that needs to be professional looking uses PCB boards. But soldering is still required on the copper area on the PCB. In the early 1900s, the only way to make circuits for electrical or electronic components was by wiring them point to point on a chassis. These chassis were either pan or sheet. These methods made circuits very fragile and large or bulky, and expensive.

There are so many forums or communities for electronics online in today’s technical world, and one of the famous ones for PCB manufacturing is the PCBWay. PCBWay is a place that brings manufacturers and customers together. They have more than a decade of experience in this field of fabrication and prototyping and assembling of PCBs. PCBWay have proved their focus to their customers’ needs in terms of cost-effectiveness, delivery, and quality. And this can be proved by their outstanding customer reviews. Not only has this PCBWay provided a platform for students and electronic hobbyists to display their projects to the community but also give sponsorships if their work is attractive. Check out the large pool of sponsored projects here.

How PCB Manufacturing Process Done in PCBWay

Standard quality for any product needs to be maintained using some parameters. PCBWay gives that opportunity by quality control in designing and manufacturing. At first, they ensure accuracy, clarity, validity of the PCB files that we sent to them.

Then all the boards will go through the most stringent tests other than the basic visual check. They adopt most of the testing and inspecting equipment used in the industry, such as Flying Probe Tester, X-Ray Inspection Machine, Automated Optical Inspection (AOI) Machine. PCBWay are having 50+ new engineers on the daily basis around the world using PCBs for their work, who trust for their reliable quality. They produce high-quality pink, orange, grey, even transparent solder mask. Moreover, according to people needs, they can also provide Black core PCB. Check it out for a High-Quality PCB solder mask. There are some pictures below of the new colours of solder musks.

Features of PCBWay

PCB Prototyping & Manufacturing: PCBWay produces FR-4 and Aluminum boards and advanced PCBs like Rogers, HDI, Flexible and Rigid-Flex boards, at a very reasonable price. Just check this Instant Quote to order premium PCBs for your hobby projects.

PCB Assembly: It not only offers PCB Prototyping but also offers PCB Assembly service. You can order a full PCB board with attached components by uploading your file. SMT & THT assembly starts from only 30$ including free stencil and worldwide shipping. The components can be sourced and provided by PCBWay, or by clients themselves.

Open Source Community: It not only offers PCB Prototype & Assembly service but also gives opportunities to students for sponsorships. I think this is so great. They feature their projects on the website also.

3D Printing & CNC: It also produces Rapid Prototyping like 3D printing, CNC Machining, Sheet Metal Fabrication, and Injection Molding. The quality of the product is too premium and reliable. And also the best part is that you will receive your order within a minimum of 3 days.

Services: PCBWay offers great servicing of their products. It takes only 3 to 15 days according to courier service to deliver your products. Also, it has a live support facility. Whenever you have any problems, you can always reach a live customer service person to respond to your emails or messages. They have the “Return and Refund” principle, for every unusable board caused by PCBWay, they will rebuild and refund the order soon.

Guide for Ordering PCB From PCBWay

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 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 a 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 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