How to make a Full Home Automation System with the New Blynk app

How to make a Full Home Automation System with the New Blynk app

Hello and welcome back. In this tutorial, we will learn How to make a Full Home Automation system using the Nodemcu board and the New Blynk app. This system includes Temperature and Humidity monitoring system, GAS level monitoring system, Security system, water level monitoring system, and home appliances controlling system. For that, I used the DHT11 sensor, PIR sensor, MQ2 sensor, Ultrasonic sensor, and 2 channel relay module. Also, we can monitor these data on the LCD display, smartphone, or computer. For that, I used the Blynk new Update and if you want to do it using the old Blynk app, please use this link. You can use this link for how to set up the new Blynk app step by step. Ok, let’s go ahead.

DHT11 sensor

Through this sensor, we can get the temperature and humidity values. Also, if you want to get more accurate values, please use the DHT22 sensor.

More Info — Click me

MQ-2 sensor

Through this sensor, we can get the LP Gas, Smoke, Hydrogen, Propane, Methane, and Carbon monoxide. The LP Gas sensing values are used in this tutorial.

More info — Click me

PIR sensor

We can use this sensor for detecting motions. I think this sensor is most suitable for this task. Because, It has a better sensing range, lower cost, and is more effective.

More info — Click me

Ultrasonic sensor

We can use this sensor for mainly measuring distance. Therefore, we can get the water level in the water tank. But I recommended, please use a waterproof ultrasonic sensor. You can use it for a long time.

More info — Click me

Relay module

I used a two-channel relay module for this system. It depends on your appliance in the home. We can buy them 1-channel, 2-channel, 4-channel, 6-channel, 8-channel, and 16-channel in the market.

More info — Click me

OK, let’s do this project step by step. The required components are given below.

Step 1

Firstly, identify these components.

Step 2

Secondly, attach these components to the breadboard as you like.

Step 3

Thirdly, connect these components to the Nodemcu board. For that, use the circuit diagram below.

How to make a Full Home Automation System with the New Blynk app

Step 4

OK, the circuit is done. Now let’s set up the Blynk app web dashboard. For that, first you have to create an account on the Blynk platform.

  • Then, sign in to your account and create a new template as you like.
  • Next, click the “datastreams” tab and create the datastreams one by one. These are described below.
  • Name -> Security / PIN -> V0 / MIN ->0 / MAX -> 1
  • Name -> GAS value / PIN -> V1 / MIN ->0 / MAX -> 100
  • Name -> Temperature / PIN -> V2 / MIN ->0 / MAX -> 100
  • Name -> Humidity / PIN -> V3 / MIN ->0 / MAX -> 100
  • Name -> Water level / PIN -> V4 / MIN ->0 / MAX -> 50(It depends on the height of your water tank)
  • Name -> Relay One / PIN -> V5 / MIN ->0 / MAX -> 1
  • Name -> Relay Two / PIN -> V6 / MIN ->0 / MAX -> 1
  • Now, click on the “Web Dashboard” tab and drag and drop the three Buttons and four Gauges to the interface. Next, click the gear wheel icons one by one in the widgets and select the datastreams. Finally, customize these widgets as you like and save them.
  • Next, click the search icon and create a new device. For that, select the template you created earlier.

OK, the Blynk web app is ready for us.

Step 5

Now, let’s set up the Blynk mobile dashboard. For that, first download and install the Blynk app on your phone.

  • Next, click the template you created earlier. After, click the “Setup dashboard” button and add the three Buttons and four Gauges to the dashboard. And then customize these widgets as you like.
  • Now, click the one-by-one widget and select the datastreams. For that, use the pictures below.

OK, the Blynk mobile app is ready.

Step 6

Now, connect the Nodemcu board to the computer, and let’s create the program for this project. It’s as follows.

/*Full home automation with the New Blynk app
   https://srituhobby.com
*/
//Include the library files
#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

//Initialize the LCD display
LiquidCrystal_I2C lcd(0x27, 16, 2);

char auth[] = "";//Enter your Auth token
char ssid[] = "";//Enter your WIFI name
char pass[] = "";//Enter your WIFI password

DHT dht(D3, DHT11); //(sensor pin,sensor type)
BlynkTimer timer;
bool pirbutton = 0;

// Define component pins
#define Buzzer D0
#define MQ2 A0
#define trig D4
#define echo D5
#define PIR D6
#define relay1 D7
#define relay2 D8

//Get buttons values
BLYNK_WRITE(V0) {
  pirbutton = param.asInt();
}

void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  pinMode(Buzzer, OUTPUT);
  pinMode(PIR, INPUT);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  dht.begin();

  lcd.setCursor(0, 0);
  lcd.print("Home Automation");
  lcd.setCursor(4, 1);
  lcd.print("System");
  delay(4000);
  lcd.clear();

//Call the functions
  timer.setInterval(100L, gassensor);
  timer.setInterval(100L, DHT11sensor);
  timer.setInterval(100L, pirsensor);
  timer.setInterval(100L, ultrasonic);
}

//Get the MQ2 sensor values
void gassensor() {
  int value = analogRead(MQ2);
  Serial.println(value);
  value = map(value, 0, 1024, 0, 100);
  if (value <= 55) {
    digitalWrite(Buzzer, LOW);
  } else if (value > 55) {
    Blynk.notify("Warning! Gas leak detected");
    digitalWrite(Buzzer, HIGH);
  }
  Blynk.virtualWrite(V1, value);
  lcd.setCursor(0, 0);
  lcd.print("G:");
  lcd.print(" ");
  lcd.print(value);

}

//Get the DHT11 sensor values
void DHT11sensor() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Blynk.virtualWrite(V2, t);
  Blynk.virtualWrite(V3, h);

  lcd.setCursor(8, 0);
  lcd.print("T:");
  lcd.print(t);

  lcd.setCursor(0, 1);
  lcd.print("H:");
  lcd.print(h);

}

//Get the PIR sensor values
void pirsensor() {
  bool value = digitalRead(PIR);
  if (pirbutton == 1) {
    if (value == 0) {
      digitalWrite(Buzzer, LOW);
    } else if (value == 1) {
      Blynk.notify("Warning! Please check your security system");
      digitalWrite(Buzzer, HIGH);
    }
  }
}

//Get the ultrasonic sensor values
void ultrasonic() {
  digitalWrite(trig, LOW);
  delayMicroseconds(4);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  long t = pulseIn(echo, HIGH);
  long cm = t / 29 / 2;
  Blynk.virtualWrite(V4, cm);

  lcd.setCursor(8, 1);
  lcd.print("W:");
  lcd.print(cm);
  lcd.print("  ");
}

//Get buttons values
BLYNK_WRITE(V5) {
 bool RelayOne = param.asInt();
  if (RelayOne == 1) {
    digitalWrite(relay1, LOW);
  } else {
    digitalWrite(relay1, HIGH);
  }
}

//Get buttons values
BLYNK_WRITE(V6) {
 bool RelayTwo = param.asInt();
  if (RelayTwo == 1) {
    digitalWrite(relay2, LOW);
  } else {
    digitalWrite(relay2, HIGH);
  }
}

void loop() {
  Blynk.run();//Run the Blynk library
  timer.run();//Run the Blynk timer
}
  • Next, copy and paste the Blynk Auth Token and include the WIFI connection details. (The Blynk Auth token includes the Blynk Web Dashboard. For that, click on the “Device Info” tab)
  • Now, select board and port. After, upload this code to the Nodemcu board.

Step 7

Finally, remove the USB cable and connect the 5v external power supply. You must remember it. Because the USB power is not enough for the LCD display and relay module.

Step 8

Now, you can test this project. The full video guide is below. So, see you in the next project.

How to make a Full Home Automation System with the New Blynk app

Similar Posts

8 Comments

  1. And where will we connect the LCD ? You have mentioned LCD but not connected it in hardware so kindly guide me about it.

Leave a Reply

Your email address will not be published.