Table of Contents
Overview
In this NodeMCU ESP8266 project, I demonstrated how to build a home automation system using the NodeMCU app and Blynk. With this IoT project, you can control four home appliances from a smartphone. If WiFi is not available, you can control the lighting manually.
Required Hardware Components
Hardware
- NodeMCU
- Relay
- Voltage Regulator IC
- Female DC Power Jack
- Female Header
Software:
- Code Composer Studio
Bill of Materials
What is NodeMcu8266
NodeMcu8266 is a development board based on the esp8266 wifi module. NodeMcu8266 is an open-source device that is primarily used to manufacture IoT devices.
It can be programmed using the Arduino IDE and the coding structure is still similar to Arduino, but the ArduinoIDE does not come with ESP compatible boards pre-installed, so you need to add/import the board’s attachments to the IDE before programming and its very easy to do ESP series boards were not initially developed for compatibility with the Arduino IDE, so in the Arduino IDE, each pin on the NodeMCU corresponds to a different IDE’s GPIO pin. Here is the pin mapping for the NodeMCU GPIO pins. In Coding, you can directly write the NodeMCu digital pins as D1, D2, D3… or the corresponding GPIO PIN.
Steps to import ESP panel libraries:
Specification:
ESP8266 based development kit includes GPIO, PWM, IIC, 1-Wire and ADC on one board. Boost your development in the fastest way in combination with NodeMCU firmware
- Wi-Fi Module – ESP-12E module similar to ESP-12 module but with 6 extra GPIOs.
- USB – micro USB port for power, programming and debugging
- Headers – 2x 2.54mm 15-pin header with access to GPIOs, SPI, UART, ADC, and power pins
- Misc – Reset and Flash buttons
- Power – 5V via micro USB port
- Dimensions – 49 x 24.5 x 13mm
Shortcode
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Click on the Ok button.
Go to ‘Tools and Board’, from the drop-down menu select ‘ Board Manager’.
- When you select the ESP8266 package then a ‘Install button’ will appea, click on it.this file file is around 160mb in size and will take some time to download.
- After Completion, you will be able to find the different boards of ESP series in Arduino IDE and Installation is complete.
Circuit Diagram & Connection
A circuit diagram for Blynk controlled home automation using ESP8266 is given below. With this circuit diagram, you can assemble the circuit on a breadboard using a 4 channel relay and a NodeMCU board.
Setting up Blynk Application
Now let’s get to know the Blynk app. In this project, all the controls are implemented by the Blynk application. Blynk is a platform with IOS and Android applications to control Arduino, Raspberry Pi and the like through the Internet. It is a digital control panel where you can create a graphical interface for your project by simply dragging and dropping tools.
Download Blynk App on your smartphone through Play Store. Create an account and then click New Project.
You can download the Blynk app from the Playstore if you are an Android user. You can also install the Blynk app on IOS from the App Store.
Now let’s set up the Blynk app for an IoT home automation project. First, open the app and create a new account with your email ID. Then click “New Project”.
Now you can follow the images below for a complete setup guide.
You can download the Blynk app from the Playstore if you are an Android user. You can also install the Blynk app on IOS from the App Store.
Now let’s set up the Blynk app for an IoT home automation project. First, open the app and create a new account with your email ID. Then click “New Project”.
Now you can follow the images below for a complete setup guide.
Create a project in Blynk App
Now, add 4 buttons from the Widget box as we are using 4 channel relay
From the top, when you click “Email Everyone”, an authentication code will be sent to your email address. This code is very important because it is required in the program/code. So open your email id and check the token.
Click on button -> change its name -> change PIN to digital pin say D3 depending upon your connection. Repeat process for 4 relays. I am using D1 for relay 1, D2 for relay 2, D3 for relay 3 and D4 for relay 4.
Source Code/Program
Here is the Blynk based home automation code, you can copy and paste the code into your Arduino IDE. But before that, you need to add the Blynk library to the Arduino IDE.
https://github.com/blynkkk/blynk-library
Final Code
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "c5lRcTsZ2GwLyRtQ098wzuVdFz__sbXx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = Devilal;
char pass[] = Home@123;
int Fan_1 = 12; // D6 pin
int Light_1 = 14; // D2 pin
int Bed_Light_1 = 4; // D1 pin
int TV_1 = 5; // D5 pin
void setup()
{
// Debug console
Serial.begin(115200);
pinMode(Fan_1,OUTPUT);
pinMode(Light_1,OUTPUT);
pinMode(Bed_Light_1,OUTPUT);
pinMode(TV_1,OUTPUT);
digitalWrite(Fan_1, HIGH);
digitalWrite(Light_1, HIGH);
digitalWrite(Bed_Light_1, HIGH);
digitalWrite(TV_1, HIGH);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
- Note: many people saying we are getting ESP8266WiFi.h unable to find ESP8266WiFi.h file
after uploading the file also facing sam issue because you selected the wrong board - ESP8266WiFi.h library file support for ESP8266 NODEMCU Board not for ESP32_ Wroom_32