In this ESP32 project, I have explained how to make a practical IoT project using ESP32 and sensors with the New Blynk Automation.
With this IoT-based project, you can set the timer and control the relays automatically with sensor readings in the Blynk IoT app.
If there is no internet, still you can also control 4 home appliances with the IR remote and manual switches.
The ESP32 will automatically connect with with Blynk cloud if the WiFi is available. Then you can control the relays from anywhere in the world through the internet and monitor the real-time feedback in Blynk IoT App.
I have used all the FREE tools for this ESP32 home automation project using Blynk IoT.
So if you follow all the steps, you can easily make this Smart Home System with ESP32 and Blynk app.
Required Components for the ESP32 IoT projects
- ESP32 DevKIT V1 Amazon
- 4-channel 5V SPDT Relay Module Amazon
- DHT11 Sensor Amazon
- TSOP1838 IR Receiver (with metallic case) Amazon
- Switches or Pushbuttons Amazon
- Any IR Remote
Circuit of the IoT Project using ESP32
The circuit is very simple, I have used D23, D22, D21 & D19 GPIO to control the 4-channel relay module.
And the GPIO D13, D12, D14 & D27 connected with switches to control the relay module manually.
I have used the INPUT_PULLUP function in Arduino IDE instead of using the pull-up resistors with each push button.
As per the source code, when the control pins of the relay module receive a LOW signal the relay will turn on and the relay will turn off for the HIGH signal in the control pin.
IR remote receiver (TSOP1838) connected with D35. And the DHT11 sensor connected with RX2 (GPIO16).
If you want to use the pushbuttons instead of latched switches, then just connect the pushbuttons instead of the latched switches across GPIO pins and GND.
I have used a 5V 5Amp mobile charger to supply the circuit.
Please take proper safety precautions while connecting the AC appliances.
Tutorial video on IoT project using ESP32 & Blynk
In the Internet of things tutorial video, I have covered the following steps in detail.
- Control appliances with Google Assistant Blynk & IR Remote
- Controlling relays with DHT11 Sensor and Timer using Blynk Automation.
- Circuit of the ESP32 IoT Home Automation projects.
- How to set up Blynk IoT cloud for ESP32.
- Source Code for the Blynk ESP32 IoT project.
- How to add Automations in Blynk IoT (Timer and Sensor ).
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
Create Blynk Template
During creating the template, I have selected ESP32 as hardware and connection type as WiFi.
Create Datastreams in Blynk cloud
For demonstration, I have created 4 Datastreams (V1 to V4) to control 4 relays, 1 Datastream (V5) to turn off all the relays and 2 Datastreams (V6 & V7) to get the DHT11 sensor readings.
Define Datastreams for Automations
Next, you have to define which Datastreams will be available in Automation actions and conditions.
Only Virtual Pin, Enumerable and Location Datastreams are supported.
Create Web Dashboard
After that, click and drag Switch widgets according to the number of relays and 2 level widgets for DHT11 sensors.
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.
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 IRremote Library (3.6.1). Click Here to download the IRremote library.
- Then install the AceButton library. Click Here to download the AceButton library.
Source Codes for Blynk IoT Projects with ESP32
Click on the following buttons to download the source codes for this ESP32 project.
First, you have to upload the Code for Getting HEX codes to ESP32 and connect the IR receiver with GPIO D35.
After that, open the serial monitor, and select the Baud Rate at 9600.
Now, you have to press all the remote buttons (one by one) which you want to use to control the relays.
Now, save all the HEX codes. You have to update the main code with these HEX codes. For this IoT project, you need 5 HEX codes.
Modify the main code for this IoT based project
In code, you have to update only the BLYNK_TEMPLATE_ID, BLYNK_DEVICE_NAME, Auth Token, WiFi Credentials and HEX codes of IR remote as shown in the video.
After doing these changes, go to Tools and select the board as “DOIT ESP32 DEVKIT V1” and the proper PORT in Arduino IDE.
Then click on the upload button to program the ESP32 board.
PCB for this ESP32 Home Automation system
To make the circuit compact, I have designed a PCB for this ESP32 IoT project.
If you want, you can also use this PCB to make the circuit compact and give the project a professional look. This PCB can be used for any ESP32 Home Automation project.
Add Automation to the Blynk Project
In the tutorial video, I have explained all the steps to create Automation in the Blynk IoT application.
In this automation project, I have controlled the 3rd relay with the DHT11 temperature reading and scheduled the turn ON and turn OFF for the 4th relay with timer.
After watching the tutorial video, you can easily define the automation as per your requirements.
Control relays with the Blynk IoT, IR Remote & Switch
You can control appliances with the New Blynk IoT app from anywhere in the world through the internet.
If the ESP32 is connected with WiFi, then you can also monitor the real-time feedback and room temperature in the Blynk IoT app.
You can use any IR remote to control the appliances.
First, get the HEX codes of unused IR Remote buttons, then update the HEX codes in the code.
If the Wi-Fi is not connected, still you can control relays with the IR remote.
You can also control the appliances from manual switches or pushbuttons.
If the ESP32 is connected to Wi-Fi then it will send real-time feedback to the Blynk IoT server.
Add Google Assistant with Blynk using IFTTT
You can also add Google Assistant with Blynk cloud using IFTTT. In the following article, I have explained all the steps to connect Blynk with Google Assistant using the FREE IFTTT account.
URL syntax to send web requests in New Blynk IoT platform
The server region could be found in the right bottom corner of the web interface in the Blynk account.
In the server address, the first 4 characters are the Server Region.
Following are the server addresses for different regions.
- fra1.blynk.cloud – Frankfurt
- lon1.blynk.cloud – London
- ny3.blynk.cloud – New York
- sgp1.blynk.cloud – Singapore
- blr1.blynk.cloud – Bangalore
I have used the following Blynk URLs to send web requests from IFTTT to update the Datastreams values in the Blynk server.
I hope you like this Smart home IoT projects idea with ESP32 and Blynk app.
Click Here for more such ESP32 projects.
Please do share your feedback on this IoT project. Thank you for your time.