In this article, I have explained how to make an IoT project using ESP32 NodeMCU networks with the new Blynk IoT platform. With this Internet of Things project, you can control all the home appliances from different rooms with the same Blynk IoT cloud account and manual switches. If there is no WiFi available then you can control the relay module manually with switches.
So you can connect multiple NodeMCUs or ESP32s with the same Blynk account to control all the appliances of your home and office.
With this home automation project, you can also monitor the real-time status of each switch in the Blynk app.
If Wi-Fi is available the ESP32 or NodeMCU will automatically connect with the Wi-Fi.
Required Components for this IoT-based Project
For each room you need the following components:
- NodeMCU or ESP32
- 4-channel Relay Module (5V)
- Switches or Pushbuttons
If you use ESP32 then you can use either 4-channel or 8-channel relay module.
Circuits of the IoT Project with Blynk
As you can use multiple microcontrollers, so I have shared all the circuits for NodeMCU or ESP32 control relays.
For all the circuits, I have used the INPUT_PULLUP function in Arduino IDE instead of using the pull-up resistors with each switch or button.
As per the source code, when the control pins of the relay module receive the LOW signal the respective relay will turn on and the relay will turn off for the HIGH signal in the control pin.
I have used a 5V 5Amp mobile charger to supply the circuits.
NodeMCU control Relays with PushButton
The circuit is very simple, I have used D1, D2, D5 & D6 GPIO to control the 4-channel relay module.
And the GPIO SD3, D3, D7 & RX connected with pushbuttons to control the relay module manually.
The board LED connected with the D0 pin will act as the WiFi indicator.
If you want to use latched switches for manual control, then just connect switches instead of push buttons.
The S2 switch, connected with the D3 pin, must be turned OFF during the booting process if you use NodeMCU with latched switches.
ESP32 control Relays with Switches
For this circuit, I have used D23, D22, D21 & D19 GPIO to control the 4-channel relay module.
And the GPIO D13, D12, D14 & D27 are connected with switches to control the relay module manually.
The board LED connected with the D2 pin will act as the WiFi indicator.
If you want to use pushbuttons for manual control, then just connect pushbuttons instead of switches across the GPIO pins and GND.
For the 8-channel relay module, I have used D23, D22, D21, D19, D18, D5, D25 & D26 GPIO to control the 8 relays.
And the GPIO D13, D12, D14, D27, D33, D32, D15 & D4 are connected with switches to control the relay module manually.
I have used the D2 (GPIO-2) pin as Wi-Fi indicator. (D2 pin connected with the blue LED, mounted on ESP32 board)
Please take proper safety precautions while working with high voltage.
Tutorial video on ESP32 NodeMCU Blynk Home Automation
In the IoT tutorial video, I have explained the following topics:
- Explained all the circuit diagrams for this IoT project.
- Setup Blynk cloud account for the multiple ESP8266 and ESP32 networks.
- Explained the source codes for the Blynk home automation system.
- Setup the Blynk IoT app for this internet of things project.
- Control high voltage appliances with Wi-Fi (Blynk IoT app).
Set up Blynk IoT Cloud for the IoT-based Project
You can refer to the following article to set up the new Blynk cloud account
Getting started with New Blynk 2.0 IoT platform
Create Blynk Template
During creating the template, I have selected ESP32 as hardware, but as we will use Virtual Pins to create Datastreams, so we can connect any microcontroller with this template.
Create Datastreams in Blynk cloud
For demonstration, I have created 8 Datastreams to control 8 relays. If you want to control 10 relays then create 10 Datastreams.
Create Web Dashboard
After that, click and drag Switch widgets according to the number of relays.
Then click on “Save“.
Add Device in Blynk Cloud using Template
You can refer to the following article to add a device in the Blynk cloud.
Add Device in Blynk Cloud from Template
Program NodeMCU & ESP32 with Arduino IDE
For this IoT-based home automation project, I have used the Arduino IDE to program NodeMCU.
First update the Preferences –> Aditional boards Manager URLs: https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Then install the ESP8266 board from the Board manager or Click Here to download the ESP8266 boards.
- Then install the ESP32 board from the Board manager or Click Here to download the ESP32 board.
- After that install the Blynk library. Click Here to download the Blynk library.
- Then install the AceButton library. Click Here to download the AceButton library.
Codes for Blynk Home Automation Project
As for this smart home you can use both ESP8266 and ESP32, so I have shared all the possible source codes.
Source codes NodeMCU ESP8266 and 4 Relays
Source codes ESP32 and 4 Relays
Source codes ESP32 and 8 Relays
After downloading, you have to enter the following details in the code.
- Update the Blynk Template ID and Auth Token.
#define BLYNK_TEMPLATE_ID "" #define BLYNK_DEVICE_NAME "" #define BLYNK_AUTH_TOKEN ""
- Then enter the WiFi Credentials (WiFi name & password)
// Your WiFi credentials. // Set password to "" for open networks. char ssid = ""; char pass = "";
- Update the Virtual Pins.
Here for the ESP32, I have used V1, V2, V3, V4 and for the NodeMCU, I have used V5, V6, V7, V8 virtual pin.
Then go to Tools and for NodeMCU select the board as “NodeMCU 1.0 ESP-12E” and for ESP32 select the board as “DOIT ESP32 DEVKIT V1“. Then select the proper PORT in Arduino IDE.
Then click on the upload button to program the NodeMCU or ESP32 board.
Important points to remember
- In the code, you have to change only the virtual pins according to the NodeMCU or ESP32 numbers.
- You can use different WiFi networks for each microcontroller, but the Blynk Template ID and the Authentication Token must be the same for all the NodeMCUs and ESP32.
- Don’t connect both microcontrollers with the laptop at the same time.
- If ESP32 keeps rebooting after the code is uploaded then use another power supply.
- To control the appliances from different mobiles, you have to log in to the same Blynk account from all the smartphones.
Set up Mobile Dashboard in Blynk IoT app
First Download and install the Blynk IoT App from Google Play Store or App Store.
Steps to configure Mobile dashboard in Blynk IoT app.
- Open the Blynk IoT app, and select the Template.
- Tap on the 3-dash icon.
- Add 8 Buttons from the widget Box.
- Tap on each Button widget, then select the Datastream, and the Mode will be “SWITCH“.
- Then exit from the EDIT mode.
- Blynk IoT app is ready to control the appliances.
Control Relays with Blynk App
Now, if the ESP32 or NodeMCU is connected to the WiFi, then you can control all appliances from anywhere in the world, and also monitor the relay-time feedback of each relay in the Blynk App.
Here, I have connected one NodeMCU and one ESP32 with the Blynk server. But as I mentioned, you can connect multiple NodeMCU and ESP32 as per your requirements.
Control Relays Manually from Switches
With this home automation system, you can always control the appliances manually with Switches or pushbuttons.
And if the NodeMCU and ESP32 are connected to WiFi, it will send real-time feedback to the Blynk server.
I hope you like this Smart house IoT projects idea with multiple NodeMCU ESP8266 and Blynk app.
Click Here for more such ESP32 projects.
Please do share your feedback on this IoT project. Thank you for your time.