Home Automation using ESP32 Blynk Bluetooth IR

Home Automation using ESP32 Blynk Bluetooth IR

Make IoT-based home automation using ESP32 Blynk + Bluetooth + IR remote + Manual control relays using FREE tools (Circuit + Source Code)

In this IoT project, I have explained how to make IoT-based home automation using ESP32 Blynk, Bluetooth, and IR remote to control relays.

With this ESP32 project, you can also control appliances without internet from the Bluetooth app, IR remote, and manual switches.

The ESP32 will automatically connect with the Blynk IoT 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 on the Blynk IoT App.

Here, I have not used any external Bluetooth module, so the circuit is very simple.

I have used all the FREE tools for this ESP32 Blynk project.

So if you follow all the steps, you can easily make this ESP32 home automation system.

Required Components:

  • ESP32 DevKIT V1 Amazon
  • 4-channel 5V SPDT (Active LOW) Relay Module
  • TSOP1838 IR Receiver (with metallic case) Amazon
  • Switches
  • Any IR Remote

Circuit of the ESP32 Blynk IoT Project

Circuit of the ESP32 Alexa IoT Project

In the circuit, I have not used any external Bluetooth module, so the circuit is very simple.

I have used D23, D22, D21 & D19 GPIO to control the 4-channel relay module.

GPIO D13, D12, D14 & D27 are connected with switches.

IR remote receiver (TSOP1838) connected with D35.

For the 8 relays, please refer to the following circuit.

Circuit of the IoT projects using ESP32 with switch
ESP32 IoT projects with Switch (Latched)

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.

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 Blynk ESP32 IoT Project

In the Internet of Things tutorial video, I have covered the following steps in detail.

  • Circuit of ESP32 IoT-based home automation system.
  • How to set up Blynk IoT cloud and mobile app for the ESP32 project.
  • Explained the source code for the ESP32 Bluetooth project.
  • Steps to connect the Bluetooth app with the ESP32.

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

While creating the template, I selected ESP32 as the hardware and the connection type as WiFi.

Create Datastreams in Blynk Cloud

blynk datastreams p1

In the template, I have created 4 Datastreams (V1 to V4) to control 4 relays.

Create Web Dashboard

Create Web Dashboard

After that, click and drag 4 Switch widgets and select the related Datastreams for each widget.

Then click on “Save” to save the template.

Add Device in Blynk Cloud using Template

You can refer to the following article to add a device to the Blynk cloud.

Add Device in Blynk Cloud from Template

PCB for this ESP32 Home Automation system

To make the circuit compact, I have designed a PCB for this ESP32 Alexa IoT project.

PCB for ESP32 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.

You can order any custom-designed PCBs from PCBWay at very reasonable prices.

PCBWay

You can also explore different PCB projects from their Open-source community pcbway.com/project/.

PCBWay contest

PCBWay Design Contest has always encouraged participants to engage in open-source and innovative projects, aiming to inspire more individuals to become a member of the electronics community.

PCBWay contest timeline


In the contest, you have the opportunity to enter a wide range of submissions related to electronic design, spanning FPGA, IoT projects, wearables, embedded electronics, and also encompassing mechanical design, product design, or 3D design.

For more details please click here.

Program ESP32 with Arduino IDE

For this IoT-based home automation project, I have used the Arduino IDE to program ESP32.

First update the Preferences –> Aditional boards Manager URLs: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json

  • Then install the ESP32 board from the Board Manager or Click Here to download the ESP32 board.
  • Download the required libraries from the following links:

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 115200.

Now, you have to press all the remote buttons (one by one) that 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. You need 6 HEX codes for this ESP32 project.

Code for this ESP32 Blynk Project

In the main sketch, you have to update only the BLYNK_TEMPLATE_ID, BLYNK_DEVICE_NAME, and Auth Token.

/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_AUTH_TOKEN ""

Enter the WiFi Credentials.

// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

Update the HEX code of the IR Remote buttons (as shown in the tutorial video).

//Update the HEX code of IR Remote buttons 0x<HEX CODE>
#define IR_Button_1   0x1FEE01F
#define IR_Button_2   0x1FE10EF
#define IR_Button_3   0x1FE906F
#define IR_Button_4   0x1FE50AF
#define IR_All_On     0x1FE807F
#define IR_All_Off    0x1FE48B7

In the code, I have used Preferences.h library to remember the last states of all the GPIO connected with relays. Please refer to the following article on the ESP32 Preferences library.

After doing these changes, go to Tools and select the board as “ESP32 Dev Module”, Partition Scheme as “Huge APP (3MB…)” and the proper PORT in Arduino IDE.

Then click on the upload button to program the ESP32 board.

Setup Blynk IoT Mobile Dashboard

After programming, set up the Blynk mobile dashboard. Please refer to the tutorial video.

Connect ESP32 with Bluetooth App

I have made a Bluetooth app in MIT app inventor for this IoT-based home automation project.

Bluetooth app v1 blocks

I have explained the steps to connect the ESP32 with the Bluetooth app in the tutorial video.

Control Relays with Blynk IoT & Bluetooth App

Control Relays with Blynk IoT & Bluetooth App

Now you can control the appliances from the Blynk IoT app through the internet.

If the WiFi is not available, you can control the relays from Bluetooth, IR remote, and manual switch.

control relays with IR remote

I hope you like this IoT-based home automation system idea with ESP32 and Blynk IoT app.

Click Here for more such ESP32 projects.

Please do share your feedback on this IoT project. Thank you for your time.