ESP32 Blynk IoT Project

ESP32 Blynk IoT Project with Fan Dimmer & Bluetooth

Make ESP32 Blynk IoT + Bluetooth + IR Remote + Manual Switch control relays with Fan Dimmer circuit explained with Circuit and Source Code.

In this ESP32 project, I have explained how to make a practical IoT-based home automation system with a fan dimmer using ESP32 Blynk IoT and Bluetooth.

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

ESP32 Blynk IoT Project

The ESP32 will automatically connect with the Blynk IoT cloud if the WiFi is available. Then you can control the lights and fan speed 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 project using Blynk IoT.

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

Required Components for the ESP32 IoT project

Required Components for IoT project
  • ESP32 DevKIT V1 Amazon
  • 8-channel 5V SPDT Relay Module Amazon
  • HC-05 Bluetooth Module
  • TSOP1838 IR Receiver (with metallic case) Amazon
  • Switches
  • Any IR Remote
  • 4-step Fan Regulator OR (2.2uf & 3.3uf 250V Capacitor, 2.2-ohm 1/2W Resistors, 220k 1/4W Resistors, and 4-step selector switch)

Circuit of the ESP32 Blynk IoT Project

Circuit of the ESP32 Blynk IoT Project

The circuit is very simple, I have used D23, D22, D21 & D19 GPIO to control the first 4 relays.

GPIO D13, D12, D14 & D27 are connected with switches, and GPIO D33, D32, D15 & D4 are connected with a 4-step selector switch 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.

The TX pin of the Bluetooth or BLE module is connected to the RX2 (GPIO16) pin of ESP32 for serial communication.

**I have not used the inbuilt Bluetooth of ESP32 as the total size of the sketch is bigger that ESP32 flash memory.

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.

  • Set up Blynk IoT cloud for ESP32 project.
  • Control fan speed through Blynk IoT and Bluetooth app.
  • Circuit of the ESP32 IoT home automation system.
  • Explained the source code of the Blynk ESP32 IoT project.

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 selected ESP32 as the hardware and the connection type as WiFi.

Create Datastreams in Blynk Cloud

Create Datastreams in Blynk Cloud

In the template, I have created 5 Datastreams (V1 to V5) to control 4 relays and 1 fan, 1 Datastream (V6) to control fan speed, and 1 Datastream (V7) to turn off all the relays.

Create Web Dashboard

Create Web Dashboard

After that, click and drag 5 Switch widgets, and 1 Slider widget, 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 Blynk IoT project.

If you want to buy this complete project (Rs: 3399/), then please send an email to [email protected] with your address.
(Including pre-programmed ESP32, DHT11 sensor, IR receiver, 1 selector Switch, IR remote)

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.

About PCBWay and their services

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

This image has an empty alt attribute; its file name is PCBWay-750x161-Banner.jpg

PCBWay not only produces FR-4 and Aluminum boards but also advanced PCBs like Rogers, HDI, and Flexible and Rigid-Flex boards, at very affordable prices.
For the online instant quote page please visit –

You can also explore different PCB projects from their Open-source community

For more details please visit the following articles.
Why PCBway

Required components for the PCB

Required components for the PCB

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:,

  • 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) 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. You need 9 HEX codes for this ESP32 project.

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

/* Fill-in your Template ID (only if using Blynk.Cloud) */

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_Button_5   0x1FED827
#define IR_Fan_Up     0x1FE609F
#define IR_Fan_Down   0x1FEA05F
#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 “DOIT ESP32 DEVKIT V1” and the proper PORT in Arduino IDE.

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

Setup Blynk IoT Mobile Dashboard

Setup Blynk 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.

Connect ESP32 with Bluetooth app

I have explained the steps to connect the ESP32 with Bluetooth app in the tutorial video. You also control fan speed with this Bluetooth app.

Connect Appliances and switches with the PCB

Connect Appliances and switches

Please refer to the above circuit diagram to connect all the AC appliances and switches with the PCB.

Please take proper safety precautions while connecting the AC appl

Control Fan Speed with Blynk IoT and Bluetooth App

Control the speed of the ceiling fan from anywhere in the world from the Blynk IoT App. If the WiFi is connected, you can also monitor the real-time feedback in the Blynk.

Control Fan Speed with IR Remote & Selector Switch

You can use any IR remote to control the fan speed. I have used 2 buttons to increase and decrease the fan speed from the IR remote.

You can also use a selector switch to control the fan speed manually if the WiFi is not connected.

Control relays with Blynk IoT, Bluetooth, IR Remote & Switch

ESP32 Blynk IoT Project
Control Fan speed with Blynk app

You can control appliances with the New Blynk IoT app from anywhere in the world through the internet.

If the ESP32 is connected to WiFi, then you can also monitor the real-time feedback in the Blynk IoT app.

Control relays with IR Remote
Control relays with IR Remote

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.

Control relays with Bluetooth
Control relays with Bluetooth

You can also connect the ESP32 with Bluetooth and control the appliances with Bluetooth App.

If the ESP32 is connected to Wi-Fi then it will send real-time feedback to the Blynk IoT server.

Control relays with switches
Control relays with switches

You can also control the appliances with manual switches.

If the ESP32 is connected to Wi-Fi then it will send real-time feedback to the Blynk IoT server.

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.