We come up with another Home Automation project with a temperature-sensing ability. In this project, we are going to build an ESP32 Home Automation System with the latest Blynk 2.0 and ESP32 development board. This time you can control upto four load appliances with the manual switches and Blynk app from anywhere in the world through the internet connection. You can see real-time feedback on the Blynk app or through your monitor. When you have no internet or WiFi connection, you can just use it manually.
Circuit Diagram

Components Required
- ESP32 Development Board
- TSOP1838 IR Sensor
- LDR (Light Dependent Resistor)
- DHT11 Temperature & Humidity Sensor
- 5V Hi-Link AC-DC Converter
- 5V Relay (x4) / 4-Channel Relay Module
- Green LED (x4)
- Red LED (x4)
- 10 KOhm Resistor
- 100 Ohm Resistor (x8)
- 1 KOhm Resistor (x4)
- IN4007 PN Diode (x4)
- BC547 NPN Transistor (x4)
- Push Switch (x4)
- Veroboard
About Parts
ESP32 Development Board

It is a low-cost, minimal-power system on a microcontroller with integrated Wi-Fi and Bluetooth facility. ESP32 is created and developed by Espressif Systems, a Shanghai-based Chinese company, and it is manufactured by TSMC using its 40nm chip technology. In this project, we can use ESP8266 NodeMCU but there is only one analog pin that comes with it. And ESP32 have so many analog pins. So according to our needs (Voltage and Current), we choose ESP32 in spite of ESP8266 NodeMCU.
DHT11 Temperature & Humidity Sensor

It is a very accurate and low-cost temperature sensor that can measure both real-time temperature and humidity of surroundings. The supply voltage of this sensor is +5V.
TSOP1838 IR Sensor

This is a type of IR receiver which has an inbuilt amplifier. It acts as a switch and converter. TSOP1838 has three pins, which are GND, VSS, and Output. Its operating frequency is 38 KHz. TSOP1838 is a modified version of TSOP1738, so you can use both of them.
Circuit Connection for ESP32 Home Automation System
The circuit connection of this project is very simple. We used D23, D22, D21 and D19 GPIO pins to control (ON/OFF) the relay module. Also connect D13, D12, D14 and D27 GPIO pins with the switches to control this esp32 home automation system manually.
The TSOP1838 IR receiver is connected with pin D35. We connect the DHT11 temperature & humidity sensor to the RX2 or pin16 of the ESP32. The LDR is connected to pin D34.
In this project, we use the INPUT_PULLUP function in Arduino IDE in the place of pull-up resistors with every switch. The supply voltage is +5V for this circuit.
PCB Design
For removing messy wiring and giving a clean look, I designed a PCB prototype for this project. It is also helpful for troubleshooting that runs great without any errors. To design this PCB board, I used EasyEDA as it is too easy to use. For ordering PCB for this, I prefer PCBWay.
Gerber file for ESP32 Home Automation System Gerber.
PCB View


Order PCB From PCBWay
There are so many forums or communities for electronics online in today’s technical world, and one of the famous ones for PCB manufacturing is PCBWay. PCBWay is a place that brings manufacturers and customers together. They have more than a decade of experience in this field of fabrication, prototyping and assembling PCBs. PCBWay has proved its focus on its customers’ needs in terms of cost-effectiveness, delivery, and quality.
How PCB Manufacturing Process Done in PCBWay
Standard quality for any product needs to be maintained using some parameters. PCBWay gives that opportunity through quality control in designing and manufacturing. At first, they ensure the accuracy, clarity, and validity of the PCB files that we sent to them.
Then all the boards will go through the most stringent tests other than the basic visual check. They adopt most of the testing and inspecting equipment used in the industry, such as Flying Probe Testers, X-Ray Inspection Machines, and Automated Optical Inspection (AOI) Machines. PCBWay are having 50+ new engineers on the daily basis around the world using PCBs for their work, who trust their reliable quality. They produce high-quality pink, orange, grey, and even transparent solder mask. Moreover, according to people’s needs, they can also provide Black core PCB. Check it out for a High-Quality PCB solder mask. There are some pictures below of the new colours of solder musks.
Features of PCBWay
PCB Prototyping & Manufacturing: PCBWay produces FR-4 and Aluminum boards and advanced PCBs like Rogers, HDI, and Flexible and Rigid-Flex boards, at a very reasonable price. Just check this Instant Quote to order premium PCBs for your hobby projects.
PCB Assembly: It not only offers PCB Prototyping but also offers PCB Assembly service. You can order a full PCB board with attached components by uploading your file. SMT & THT assembly starts from only 30$ including free stencil and worldwide shipping. The components can be sourced and provided by PCBWay, or by the clients themselves.
Open Source Community: It not only offers PCB Prototype & Assembly services but also gives opportunities to students for sponsorships. I think this is so great. They feature their projects on the website also.
3D Printing & CNC: It also produces Rapid Prototyping like 3D printing, CNC Machining, Sheet Metal Fabrication, and Injection Molding. The quality of the product is too premium and reliable. And also the best part is that you will receive your order within a minimum of 3 days.
PCBWay Store: More boutique gift modules are waiting for you to discover, giving your creativity wings. You can order all types of electronic equipment, components and many more with exciting offers. Go with the link and buy your needs, PCBWay Store.
Services: PCBWay offers great servicing of its products. It takes only 3 to 15 days according to the courier service to deliver your products. Also, it has a live support facility. Whenever you have any problems, you can always reach a live customer service person to respond to your emails or messages. They have the “Return and Refund” principle, for every unusable board caused by PCBWay, they will rebuild and refund the order soon.
Guide for Ordering PCB From PCBWay
How To Configure IR Remote With The Relays
- First, you have to upload the code to ESP32 using Arduino IDE and connect the IR receiver with GPIO pin D35.
- Then open the serial monitor and select Baud rate at 9600.
- Now start to press all the remote buttons one by one which you want to control the keys.
- Save all the HEX codes.
- Now you have to update the main code with the HEX codes. You need 4 HEX codes to control 4 relays.
Hex Code for IR Remote
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <IRremote.h> int IR_RECV_PIN = 35; IRrecv irrecv(IR_RECV_PIN); decode_results results; void setup() { Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver } void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, HEX); //print the HEX code irrecv.resume(); } } |
How to Configure Blynk 2.0 for ESP32 Home Automation System
From the below download file, you will get 9 files. Save all of them in a single folder. Now open the .ino file in the Arduino IDE, select ESP32 DEVKIT V1 board and compile the code.
In the code section, you do not need to enter WiFi credentials. You just need to update BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME. Then open the BlynkEdgent.h file and update the HEX codes in the ir_remote() function. You just need to copy and paste the HEX codes after 0x. Now go to tools and select the “ESP32 DEVKIT V1” board and “Port Address” from the Arduino IDE.
Working Principle of ESP32 Home Automation System
The working principle of this project is very easy. You can control appliances with Blynk IoT app from anywhere in the world. If the ESP32 is connected to WI-FI, you can monitor the real-time temperature in the Blynk app. You can control all the appliances using an IR remote also.
First, get the HEX codes of unused IR Remote buttons. Then update the HEX codes in the main code. When wifi is not connected you can control it with IR remote and manual switches.
The main work behind this project is when the control pins of the relay module receive the LOW signal the relay will turn on and when it receives HIGH it gets turned off.
Libraries for Compiling The Code
For compiling the code we also need the ESP32 board manager. Just click on File-Preferences-Paste the link in Additional Board Manager URLs-OK.
Link: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
Then install the ESP32 board from the board manager of the tools section.
Then install all the required libraries in Arduino IDE like Blynk library, IR remote library, and DHT library. At the time of installing the Blynk library, you have to install all the dependencies.
ESP32 Code for ESP32 Home Automation System
First, download this file and change it according to your IR hex codes and WiFi credentials and upload it to ESP32.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | #define BLYNK_TEMPLATE_ID "***********" #define BLYNK_DEVICE_NAME "***********" #define BLYNK_FIRMWARE_VERSION "0.1.0" #define BLYNK_PRINT Serial #include <DHT.h> #include <IRremote.h> #define IR_RECV_PIN 33 // D33 pin for IR receiver IRrecv irrecv(IR_RECV_PIN); decode_results results; #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321 //#define DHTTYPE DHT21 // DHT 21, AM2301 #define DHTPIN 16 //D16 pin connected with DHT #define LDR_PIN 32 //D32 pin connected with LDR #define RelayPin1 23 //D23 #define RelayPin2 22 //D22 #define RelayPin3 21 //D21 #define RelayPin4 19 //D19 #define SwitchPin1 13 //D13 #define SwitchPin2 12 //D12 #define SwitchPin3 14 //D14 #define SwitchPin4 27 //D27 #define Ledind 2 //D2 #define VPIN_BUTTON_1 V1 #define VPIN_BUTTON_2 V2 #define VPIN_BUTTON_3 V3 #define VPIN_BUTTON_4 V4 #define VPIN_BUTTON_C V5 #define VPIN_TEMPERATURE V6 #define VPIN_HUMIDITY V7 #define VPIN_LDR V8 //Relay State bool toggleState_1 = LOW; //Define integer to remember the toggle state for relay 1 bool toggleState_2 = LOW; //Define integer to remember the toggle state for relay 2 bool toggleState_3 = LOW; //Define integer to remember the toggle state for relay 3 bool toggleState_4 = LOW; //Define integer to remember the toggle state for relay 4 //Switch State bool SwitchState_1 = LOW; bool SwitchState_2 = LOW; bool SwitchState_3 = LOW; bool SwitchState_4 = LOW; float temperature1 = 0; float humidity1 = 0; int ldrVal; #include "BlynkEdgent.h" BlynkTimer timer2; DHT dht(DHTPIN, DHTTYPE); void readSensor() { ldrVal = map(analogRead(LDR_PIN), 0, 4095, 10, 0); float h = dht.readHumidity(); float t = dht.readTemperature(); //Read Temperature if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } else { humidity1 = h; temperature1 = t; } } void sendSensor() { readSensor(); // You can send any value at any time. // Don't send more that 10 values/second. Blynk.virtualWrite(VPIN_HUMIDITY, humidity1); Blynk.virtualWrite(VPIN_TEMPERATURE, temperature1); Blynk.virtualWrite(VPIN_LDR, ldrVal); } BLYNK_WRITE(VPIN_BUTTON_1) { toggleState_1 = param.asInt(); if(toggleState_1 == 1) { digitalWrite(RelayPin1, LOW); } else { digitalWrite(RelayPin1, HIGH); } } BLYNK_WRITE(VPIN_BUTTON_2) { toggleState_2 = param.asInt(); if(toggleState_2 == 1) { digitalWrite(RelayPin2, LOW); } else { digitalWrite(RelayPin2, HIGH); } } BLYNK_WRITE(VPIN_BUTTON_3) { toggleState_3 = param.asInt(); if(toggleState_3 == 1) { digitalWrite(RelayPin3, LOW); } else { digitalWrite(RelayPin3, HIGH); } } BLYNK_WRITE(VPIN_BUTTON_4) { toggleState_4 = param.asInt(); if(toggleState_4 == 1) { digitalWrite(RelayPin4, LOW); } else { digitalWrite(RelayPin4, HIGH); } } BLYNK_WRITE(VPIN_BUTTON_C) { all_SwitchOff(); } void all_SwitchOff() { toggleState_1 = 0; digitalWrite(RelayPin1, HIGH); Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1); delay(100); toggleState_2 = 0; digitalWrite(RelayPin2, HIGH); Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2); delay(100); toggleState_3 = 0; digitalWrite(RelayPin3, HIGH); Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3); delay(100); toggleState_4 = 0; digitalWrite(RelayPin4, HIGH); Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4); delay(100); Blynk.virtualWrite(VPIN_HUMIDITY, humidity1); Blynk.virtualWrite(VPIN_TEMPERATURE, temperature1); Blynk.virtualWrite(VPIN_LDR, ldrVal); } void setup() { Serial.begin(115200); pinMode(RelayPin1, OUTPUT); pinMode(RelayPin2, OUTPUT); pinMode(RelayPin3, OUTPUT); pinMode(RelayPin4, OUTPUT); pinMode(Ledind, OUTPUT); pinMode(SwitchPin1, INPUT_PULLUP); pinMode(SwitchPin2, INPUT_PULLUP); pinMode(SwitchPin3, INPUT_PULLUP); pinMode(SwitchPin4, INPUT_PULLUP); //During Starting all Relays should TURN OFF digitalWrite(RelayPin1, HIGH); digitalWrite(RelayPin2, HIGH); digitalWrite(RelayPin3, HIGH); digitalWrite(RelayPin4, HIGH); irrecv.enableIRIn(); //Enabling IR sensor BlynkEdgent.begin(); dht.begin(); // Setup a function to be called every 2 seconds timer2.setInterval(2000L, sendSensor); } void loop() { BlynkEdgent.run(); manual_control(); //Manual Switch Control ir_remote(); //IR remote Control timer2.run(); } |