The ioT-based home automation system is revolutionising day by day according to our needs. Everywhere in technical industries are using artificial intelligence for their work to be easy. As the term “home automation” or “automated home” suggested, it may mean two meanings for everyone. Some readers think it is on/off devices such as time clocks controlling a lamp as smart home automation. Others would consider home automation a managing service that can monitor events in the home and make adjustments when necessary. Others thought it is a high-end system where a virtual assistant handles all of the automation work alone. None of these views would be wrong.
However the purpose of this article, home automation is to make it easy for the do-it-yourself by employing computer software that will become artificial intelligence to manage controllable tasks through the system. The projects in this article will allow an operator to operate a high-end smart home automation system. There are millions of households in the world using some level of partially to fully integrated home automation features.
We often use our voice to control our phones, so why not use it to control the entire home? Today this is not impossible, even easy, to control on/off devices such as lights, temperature, and appliances using single touch, voice and remote
controls. On the one hand, these on/off smart home automation devices save effort and energy. But on the other hand, adjustments are inconvenient and require the user to be present and knowledgeable enough to make the changes.
Implementing 21st-century, smart home automation with the projects described in this article can eliminate a majority of the negative issues associated with on/off remote control devices. It brings full automation and increased levels of control for all the fixtures, equipment, and appliances in the home.
Must Read Home Automation System Using Cayenne Platform
What is Smart Home Automation System?
In addition, to control electronic devices, the concept of “Smart Home Automation” is further enhanced. Home automation is a hardware network that works to communicate everyday devices with one another through internet service (IoT). It connects all devices with a common single central controlling unit which depends on the user input. These devices have a wifi system to interface with smartphones or tablets whether users are at home or anywhere in the world.
Concept of Internet of Things (IoT)
When talking about smart home automation systems, the so-called name Internet of Things (IoT) comes. The concept of IoT associates was to set up a zone around all your devices to establish a secure network connection.
From the name suggested, it is clear that all the devices with IoT enabled are connected via the same network remotely. It works by a secure cloud server where users can operate every device connected to that from anywhere. This gives us not only better control but also offers comfort and security in our daily life.
It sends notifications and emails 24/7 through a cloud server to notify us when unwanted activity happens. IoT spreads its value to industrial sectors beyond smart home automation.
Project
We will show you a smart home automation system with LDR, temperature, and humidity features in this build. Also, it has an external push-button and touches switch features. This system works via Blynk software which is easy to control.
About The Parts of Smart Home Automation
This project includes two main parts. First is hardware, which allows us to control over sensors and actuators of the smart home automation system. The second is the server, which manages, controls and monitors the user’s home.
An IoT system is built up with basic sensors, actuators, embedded systems, networks, user interface and data storage. These are discussed in detail below.
Sensors
There are three types of sensors that we use to build this system using Blynk software. The first one is the DHT11 sensor which can sense temperature and humidity both. The second one is LDR which controls the automatic on/off features of the system. And the third sensor is a touch sensor, which is used to control the actuators manually via touch.
Actuators
The 5V two-channel relay module is used here as an actuator. Basically, the output pins that are directly connected to the relay input are called actuators. Electrical loads like AC lights, fans etc are connected to the common and normally open terminals of the relays. This relay module is controlled by the Blynk app through smartphones.
Embedded System
Every smart home automation device needs a proper embedded system that can handle the whole process. ESP8266 NodeMCU plays the role here as an embedded controller. It is programmable by Arduino IDE software. The NodeMCU controls digital and Analog data from the receiver and transmits this via a web server. At the same time, its process commands are given by sensors and actuators.
Network
To link all the devices with the embedded system, we need a proper network to communicate with each other.
User Interface
For sending data from the receiver to the transmitter, we need a user interface to control devices from anywhere. In this project, we introduce the Blynk platform to make this smart home automation system. It is too simple to use. It also provides non-programmable buttons to save our time and effort from programming.
Data Storage
The data storage used here is also provided by the Blynk cloud platform. Big data storage is basically huge data that is collected from all devices. This type of data always varies from device to device. Being a cloud server, the data speed is very high.
Circuit Diagram
Components Required
- ESP8266 NodeMCU
- DHT11 Humidity Sensor
- LDR Sensor
- Touch Sensor (x3)
- 5V Relay (x2)
- 817 Opto Coupler (x2)
- BC547 NPN Transistor (x2)
- Push Button (x3)
- Red LED (x2)
- Green LED (x2)
- 1N4007 PN Diode (x2)
- Screw Terminal (x2)
- 330Ω Resistor (x2)
- 1KΩ Resistor (2)
- Wires
Software Required for Smart Home Automation
Communication between devices and the Blynk IoT platform will be established when there is a network connection present.
To upload code to ESP8266 NodeMCU, we need Arduino IDE software.
- First, open the Arduino IDE software
- Go to File and select Preferences and paste the link “https://arduino.esp8266.com/stable/package_esp8266com_index.json” in Additional Board Manager URLs to add the ESP8266 board. Open Boards Manager from the Tools menu and type ESP8266 to install the ESP8266 platform.
- For programming the ESP8266 module, one unique identity is required from the Blynk software. That is Auth code. After connecting to a network this ID help to communicate the device with it.
- Connecting to the local WiFi network requires WiFi SSID and password.
- Before compiling and loading the code to this module, we have to install the Adafruit Sensor Library, Blynk Library, DHT11 Library, and OLED Library.
To add these libraries to Arduino IDE, go to Sketch – Include Library – Add .zip Library – locate and install files.
Preparing Smart Home Automation Dashboard Using Blynk
Open the official Blynk app and create an account for yourself. After creating a new project, you will get the Auth token via your email.
Copy this Auth token and paste it into the appropriate fields of the Arduino ESP8266 code. After that, upload the Arduino IDE code to the NodeMCU and wait for connecting with the device on the network.
The next page will show a blank space to add buttons for the system. Tap on the blank space and choose the button option and add this. Again click on this and choose a virtual pin and select the desired pin which you include in your Arduino code. Then click OK and press back.
Continue with the same process as the other one. After that choose the gauge button for temperature and humidity and choose their virtual pins. Finally, get back to the homepage and click on the play button on the upper right side. You can control then your devices through this Blynk app.
Working Principle of Smart Home Automation System
The ESP8266-based smart home automation system is built around wifi module ESP8266, LDR, DHT11 sensor, three touch sensors, OLED display and two relays.
This circuit has two sensor parts. The first part is an Analog input to measure light intensity through the LDR sensor. The second part is digital input to read values of temperature and humidity through the DHT11 humidity sensor. For measuring a wide range of temperatures and humidity, you can use DHT22 as the replacement for DHT11.
We need a 5V DC supply to power up this circuit, as it needs to drive relays. Then we have to power the ESP8266 NodeMCU also. ESP8266 NodeMCU V1.0 has 11 GPIO pins and one ADC pin with a 10-bit resolution. In the figure, we explain the pin configuration of ESP8266. This module has a 3.3V inbuilt voltage regulator. It also has a CP2102-based USB to serial converter that gives an easy interface with the PC for loading Arduino code to the module.
The LDR sensor is used here to sense the light intensity around it. It can control lights switching on or off by light intensity. This is connected to the A0 pin of the ESP8266 NodeMCU to read Analog voltage based on ambient light. It can be manually changed via the CMOD push button on the system.
DHT11 sensor is used here to read temperature and humidity through digital input pin SD3. The given data is split into temperature and humidity by DHT11 through the same input pin. Digital pins D5 and D6 are connected to the inputs of the relay which act as actuators. These pins control the AC devices through the app. Three touch sensors are connected via three push buttons and then connected to digital pins D0, D7, and D8 respectively. When the system is gone offline, then these will work as normal switches. So we could use this smart home automation project with both online and offline modes.
Last we need to connect the OLED display with the system through the I2C pins of the NodeMCU and OLED display. This OLED display is optional.
NodeMCU Code
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | //ESP8266 Based Smart Home Automation System Using Blynk #define BLYNK_PRINT Serial #include <BlynkSimpleEsp8266.h> #include <DHT.h> #include <SH1106Wire.h> void checkPhysicalButton(); int toggleState_1 = 0; int pushButton1State = LOW; int toggleState_2 = 0; int pushButton2State = LOW; float temperature1 = 0; float humidity1 = 0; int ldrVal; int switchMode = 0; //Set values for Auto Control Mode const float maxTemp = 34.10; const float minTemp = 33.8; const int maxLight = 1000; const int minLight = 200; #define AUTH "4w8iA4UCRADMzqEt60NoviM3Ntno0oHP" // You should get Auth Token in the Blynk App. #define WIFI_SSID "CyBorg" //Enter Wifi Name #define WIFI_PASS "Tanmoy#Wifi@8481" //Enter wifi Password #define PUSH_BUTTON_CMODE 15 //D8 #define LDR_PIN A0 //A0 #define DHTPIN 10 //SD3 pin connected with DHT #define RELAY_PIN_1 14 //D5 #define RELAY_PIN_2 12 //D6 #define PUSH_BUTTON_1 16 //D0 #define PUSH_BUTTON_2 13 //D7 #define VPIN_BUTTON_1 V1 #define VPIN_BUTTON_2 V2 #define VPIN_BUTTON_C V3 #define VPIN_HUMIDITY V5 #define VPIN_TEMPERATURE V6 // Declaration for an SH1106 display connected to I2C (SDA, SCL pins) SH1106Wire display(0x3c, D2, D1); // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321 //#define DHTTYPE DHT21 // DHT 21, AM2301 DHT dht(DHTPIN, DHTTYPE); BlynkTimer timer; void changeMode(){ delay(200); if (switchMode == 0){ switchMode = 1; } else if (switchMode == 1) { switchMode = 0; } display.clear(); display.setFont(ArialMT_Plain_24); display.drawString(10, 5, "Set Mode: "); display.setFont(ArialMT_Plain_24); display.drawString(20, 35, String(modeDecode(switchMode))); display.display(); delay(500); Blynk.virtualWrite(VPIN_BUTTON_C, switchMode); //display.clear(); } void relayOnOff(int relay){ switch(relay){ case 1: if(toggleState_1 == 0){ digitalWrite(RELAY_PIN_1, HIGH); // turn on relay 1 toggleState_1 = 1; } else{ digitalWrite(RELAY_PIN_1, LOW); // turn off relay 1 toggleState_1 = 0; } delay(100); break; case 2: if(toggleState_2 == 0){ digitalWrite(RELAY_PIN_2, HIGH); // turn on relay 2 toggleState_2 = 1; } else{ digitalWrite(RELAY_PIN_2, LOW); // turn off relay 2 toggleState_2 = 0; } delay(100); break; default : break; } } String modeDecode(int count){ if (count == 0){ return " Manual "; } else if (count == 1){ return " Auto "; } } void displayData(){ display.clear(); display.setFont(ArialMT_Plain_24); display.drawString(20, 0, String(temperature1) + " 'C"); display.drawString(20, 25, String(humidity1) + " %"); display.setFont(ArialMT_Plain_16); display.drawString(10, 48, "Mode -> "); display.drawString(68, 48, String(modeDecode(switchMode))); display.display(); Serial.print(F("Temperature: ")); Serial.print(temperature1); Serial.print(" "); Serial.print(F("humidity: ")); Serial.print(humidity1); Serial.print(" "); Serial.println(ldrVal); Serial.println(""); } void readSensor(){ ldrVal = analogRead(LDR_PIN); float h = dht.readHumidity(); float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit 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. // Please don't send more that 10 values per second. Blynk.virtualWrite(VPIN_HUMIDITY, humidity1); Blynk.virtualWrite(VPIN_TEMPERATURE, temperature1); } BLYNK_CONNECTED() { // Request the latest state from the server Blynk.syncVirtual(VPIN_BUTTON_1); Blynk.syncVirtual(VPIN_BUTTON_2); Blynk.syncVirtual(VPIN_BUTTON_C); } // When App button is pushed - switch the state BLYNK_WRITE(VPIN_BUTTON_1) { toggleState_1 = param.asInt(); digitalWrite(RELAY_PIN_1, toggleState_1); } BLYNK_WRITE(VPIN_BUTTON_2) { toggleState_2 = param.asInt(); digitalWrite(RELAY_PIN_2, toggleState_2); } BLYNK_WRITE(VPIN_BUTTON_C) { switchMode = param.asInt(); } void checkPhysicalButton() { if (digitalRead(PUSH_BUTTON_1) == HIGH) { relayOnOff(1); // Update Button Widget Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1); } if (digitalRead(PUSH_BUTTON_2) == HIGH) { relayOnOff(2); // Update Button Widget Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2); } } void setup() { Serial.begin(9600); // Initialising the UI will init the display too. display.init(); display.flipScreenVertically(); display.setFont(ArialMT_Plain_16); display.setTextAlignment(TEXT_ALIGN_LEFT); delay(1000); display.setColor(WHITE); display.clear(); pinMode(RELAY_PIN_1, OUTPUT); pinMode(PUSH_BUTTON_1, INPUT); digitalWrite(RELAY_PIN_1, toggleState_1); pinMode(RELAY_PIN_2, OUTPUT); pinMode(PUSH_BUTTON_2, INPUT); digitalWrite(RELAY_PIN_2, toggleState_2); Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS); // Setup a function to be called every 500 ms timer.setInterval(500L, checkPhysicalButton); dht.begin(); // Setup a function to be called every second timer.setInterval(1000L, sendSensor); // Setup a function to be called every 2 second timer.setInterval(2000L, displayData); } void loop() { if (digitalRead(PUSH_BUTTON_CMODE) == HIGH){ changeMode(); } else{ if(switchMode == 1){ //if Auto Mode //DHT11 control Relay 1 if(temperature1 > maxTemp){ if(toggleState_1 == 0){ digitalWrite(RELAY_PIN_1, HIGH); // turn ON relay 1 toggleState_1 = 1; // Update Button Widget Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1); } } else if (temperature1 < minTemp){ if(toggleState_1 == 1){ digitalWrite(RELAY_PIN_1, LOW); // turn OFF relay 1 toggleState_1 = 0; // Update Button Widget Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1); } } //LDR control Relay 2 if( ldrVal < minLight){ if(toggleState_2 == 0){ digitalWrite(RELAY_PIN_2, HIGH); // turn ON relay 2 toggleState_2 = 1; // Update Button Widget Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2); } } else if (ldrVal > maxLight){ if(toggleState_2 == 1){ digitalWrite(RELAY_PIN_2, LOW); // turn OFF relay 2 toggleState_2 = 0; // Update Button Widget Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2); } } } timer.run(); Blynk.run(); } } |