Smart Home Automation With Humidity-Controlled Using Blynk

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 to 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 the artificial intelligence to manage controllable tasks through the system. The projects in this article will allow an operator to operate the 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 the 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 connecting 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 with 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

Smart Home Automation With Humidity Controlled Using Blynk

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 build up with basic sensors, actuators, embedded system, network, 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 that 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 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 devices need 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 transmit 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 receiver to 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 efforts 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

Smart Home Automation Using Blynk 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

Circuit Design Using PCB Software for Smart Home Automation

To make the circuit compact and give a professional look, I have designed the PCB after testing all the features of the smart home automation project using the ESP8266 wifi module on the breadboard. I will explain in detail how we can design and order PCB for our project.

Smart Home Automation Using Blynk PCB

For the Gerber file check out this link Smart Home Automation Using ESP8266 and Blynk.

Order PCB From PCBWay

I ordered the PCB prototype board from the PCBWay website. PCBWay is a Chinese-based PCB (printed circuit board) prototype, PCB assembly, SMD Stencil, and Flexible PCB manufacturer. They ship to more than 170 countries worldwide and process more than 2100 PCB orders a day. It feels like PCBWay gives an excellent price and customer service factor in one single serving. The quality of the PCB is awesome and its thickness is really great. What is also spectacular about PCBWay to me, as a maker and customer, is their service. From their friendly support staff to their intuitive, user-friendly website features, it all counts towards what makes PCBWay an ideal company and brand for any electronic hobbyists In this article, I will state that how can we order PCB from PCBWay with step by step guide.

Features of PCBWay

1. PCB prototyping and manufacturing

They produce FR-4 and Aluminum boards and advanced PCBs like Rogers, HDI, Flexible and Rigid-Flex boards, at a very reasonable price.

Visit the link for Instant Quote

Visit the link for Gerber file viewer

2. PCB assembly

SMT & THT assembly starts from only $30 with a free stencil and free worldwide shipping. The components can be sourced and provided by PCBWay, or by clients themselves.

3. Layout and design

Partnering with quality service providers to offer design services.

4. Open source community

Student sponsorship shared PCB projects and so on.

5. 3D Printing & CNC

On-demand Production and Rapid Prototyping in as Fast as 1 Day Leading the Digital Manufacturing Revolution.

Pcbway interface

Step 1: Go to the PCBWay website and sign up/sign in. Into the PCB Prototype tab, enter the dimensions of your PCB, the number of layers, and the number of PCBs you require. After that proceed by clicking on the ‘Quote Now’ button.

Pcbway interface 2

Step 2: You will be redirected to a page where to set a few additional parameters like the board type, layers, material for PCB, thickness, and more, most of them are selected by default, if you are opting for any specific parameters, you can edit it in here.

Pcbway interface 3

Step 3: The final step is to upload the Gerber file and proceed with the payment. To make sure the process is smooth, PCBWAY verifies if your Gerber file is valid before proceeding with the payment. This way, you can be sure that your PCB is fabrication friendly.

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 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.
  • To connect to the local WiFi network requires WiFi SSID and password.
  • Before compiling and load the code to this module, we have to install the Adafruit Sensor Library, Blynk Library, DHT11 Library, 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 desired pin which you include in your Arduino code. Then click OK and press back.

Continue with the same process with 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 temperature and humidity, you can use DHT22 as the replacement of 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 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 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 are 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 mode.

Last we need to connect the OLED display with the system through I2C pins of the NodeMCU and OLED display. This OLED display is optional.

Arduino Code

//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();
  }
}

Video Output

Leave a Comment