Home Automation

Main Door Security System with keypad and MLX90614. LEDs are operated by 3 modes (manually + IR + Blynk) & a water level indicator system.

IntermediateFull instructions provided636
Home Automation

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×2
Arduino Nano R3
Arduino Nano R3
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
MLX90614
×1
Keypad (4x4)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
DHT22 temperature-humidity sensor
Adafruit DHT22 temperature-humidity sensor
×1
Graphic OLED, 128 x 64
Graphic OLED, 128 x 64
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
IR receiver (generic)
×1
IR Remote
×1
SPST Switch
×8
Resistor 10k ohm
Resistor 10k ohm
×8
High Bright Leds
Blue + White + Green (Placed in Rooms)
×7
5 mm LED: Red
5 mm LED: Red
×4
5 mm LED: Green
5 mm LED: Green
×5
9V battery (generic)
9V battery (generic)
It is better to use 12V lithium ion battery.
×1
Jumper wires (generic)
Jumper wires (generic)
Male to Male, Male to Female, Female to Male (As Required)
×1
Wires (Single Stand Wires)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Soldering Iron + Flux + Lead
Hot glue gun (generic)
Hot glue gun (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Schematics

Arduino Uno-1

Main Door System: Interfaced MLX90614, Keypad (4x4), LCD I2c (16x2), Servo Motor, DHT22 & OLED (128x64)

Arduino Uno-2

LEDs Controlling System:
1. Interfaced manual switches for manual mode operation.
2. Interfaced IR Receiver for IR mode operation.
3. Interfaced Node_Mcu for blynk mode operation. (IOT Application)

Arduino Nano

Water Level Indicator:
Interfaced Ultrasonic sensor & LEDs.

Code

Arduino Uno-1

Arduino
Main Door System
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include<Keypad.h>
#include<Servo.h>
#include<Wire.h>
#include<SparkFunMLX90614.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo myservo;
IRTherm therm;

#define LED_RED 11 //Main door Red_LED
#define LED_GREEN 12 //Main door Green_LED

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET    -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define DHTPIN 10
#define DHTTYPE DHT22
DHT dht(DHTPIN,DHTTYPE);

#define codeLength 5
char Code[codeLength]; //define code length
char pswd[codeLength]="A1B2"; //Change your password here 
byte keycount=0;
const byte ROWS=4;
const byte COLS=4;

char hexakeys[ROWS][COLS]={
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}};


byte rowPins[ROWS]={2,3,4,5};
byte colPins[COLS]={6,7,8,9};

Keypad customKeypad=Keypad(makeKeymap(hexakeys),rowPins,colPins,ROWS,COLS);

void setup() {
  Serial.begin(9600);
  Wire.begin();
  
  pinMode(LED_RED,OUTPUT);
  pinMode(LED_GREEN,OUTPUT);
  red();
  
  dht.begin();
  therm.begin();
  therm.setUnit(TEMP_F);
  myservo.attach(A0);       //attach servo motor to A0
  myservo.write(130);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start the OLED display
  display.clearDisplay();
  display.display();
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("HOME AUTOMATION"); 
}

void loop() { 
  char customkey=customKeypad.getKey();
  if(customkey){
    Code[keycount]=customkey;
    Serial.print(Code[keycount]);
    lcd.setCursor(keycount,1);
    lcd.print(Code[keycount]);
    keycount++;
  }
  door_system();
  DHT22_OLED();
}

void door_system(){
    if(keycount==codeLength-1){
    Serial.println(" ");
    lcd.print(" ");

    if(!strcmp(Code,pswd)){
      Serial.println("PASSWORD CORRECT");
      lcd.clear();
      lcd.setCursor(0,1);
      lcd.print("  WELCOME HOME  ");
      delay(1000);
      lcd.clear();
      if (therm.read()){                  // On success, read() will return 1, on fail 0.
        Serial.print("Object: " + String(therm.object(), 2));
        Serial.println("F");
        Serial.print("Ambient: " + String(therm.ambient(), 2));
        Serial.println("F");
        Serial.println();
        Serial.println(String(therm.object(), 2));
    
        if (therm.object()>=90 && therm.object()<=95){
          myservo.write(0);           //unlock
          green();
          delay(8000);
          myservo.write(130);        //auto lock the door after 8secs.
          red();
        }
      }
   }
    else{
      Serial.println("PASSWORD INCORRECT");
      myservo.write(130);
      red();
      lcd.clear();
      lcd.setCursor(0,1);
      lcd.print("  NOT ALLOWED  ");
      delay(1000);
      lcd.clear();
    }
  deleteCount();
 }
}

void DHT22_OLED(){
  float h= dht.readHumidity();
  float t= dht.readTemperature(); 
  display.clearDisplay();
  display.setTextSize(1);                    
  display.setTextColor(WHITE);             
  display.setCursor(0,4);                
  display.println("TEMP"); 
  
  display.setTextSize(2);
  display.setCursor(50,0);
  display.println(dht.readTemperature(),1);
 
  display.setCursor(110,0);
  display.println("C");
  
  display.setTextSize(1);                    
  display.setTextColor(WHITE);             
  display.setCursor(0,20);                
  display.println("HUMI"); 
  
  display.setTextSize(2);
  display.setCursor(50,17);
  display.println(dht.readHumidity(),1);
  
  display.setCursor(110,17);
  display.println("%");
  
  display.display();
}

void deleteCount(){
  while(keycount != 0){
    Code[keycount--]=0;
  }
  return;
}

void red(){
  digitalWrite(LED_RED,HIGH);
  digitalWrite(LED_GREEN,LOW); 
}

void green(){
  digitalWrite(LED_RED,LOW);
  digitalWrite(LED_GREEN,HIGH);  
}

Arduino Uno-2

Arduino
LEDs Controlling System
#include <IRremote.h>

int RECV_PIN=13;          // IR_Receiver data pin
IRrecv irrecv(RECV_PIN);  // Define IR Receiver and results objects
decode_results results;

int LED_1=14;     // indicates Hall LED
int LED_2=15;     // indicates Kitchen LED
int LED_3=16;     // indicates Bed_Room LED
int LED_4=17;     // indicates Bath_Room LED
int LED_5=18;     // indicates Parking_Garage LED
int LED_6=19;     // indicates Garden_Light LED's

int LED_7=2;     //IR_Remote_Mode indicating LED
int LED_8=3;     //Blynk_Mode indicating LED
int LED_9=4;     //Manual_Mode indicating LED

//int LED_9=8;              // Flame_Sensor indication LED
//int Flame_Sensor=9;       // Flame_Sensor Digital output

int toggleState_1 = 0; //Define integer to remember the toggle state for Hall LED
int toggleState_2 = 0; //Define integer to remember the toggle state for Kitchen LED
int toggleState_3 = 0; //Define integer to remember the toggle state for Bed_Room LED
int toggleState_4 = 0; //Define integer to remember the toggle state for Bathroom LED
int toggleState_5 = 0; //Define integer to remember the toggle state for Parking_Garage LED
int toggleState_6 = 0; //Define integer to remember the toggle state for Garden_LED's

int mswitch_1=7;  //Manual switch for Hall LED
int mswitch_2=8;  //Manual switch for Kitchen LED
int mswitch_3=9;  //Manual switch for Bed_Room LED
int mswitch_4=10; //Manual switch for Bath_Room LED
int mswitch_5=11;  //Manual switch for Parking_Garage LED
int mswitch_6=12; //Manual switch for Garden LED's

int mswitch_7=5; //Manual switch for IR_Remote Mode
int mswitch_8=6; //Manual switch for Blynk Mode

void setup(){
  Serial.begin(115200);
  irrecv.enableIRIn();    // Enable the IR Receiver
  for(int i=2; i<5; i++){
    pinMode(i,OUTPUT);
    digitalWrite(i,LOW);
  }
  for(int j=14; j<20; j++){
    pinMode(j,OUTPUT);
    digitalWrite(j,LOW);
  }
  for(int k=5; k<13; k++){
    pinMode(k,INPUT);
  }
  //pinMode(Flame_Sensor,INPUT);
}

void loop(){
  if(digitalRead(mswitch_7)==HIGH && digitalRead(mswitch_8)==LOW){
    digitalWrite(LED_7,HIGH); digitalWrite(LED_8,LOW); digitalWrite(LED_9,LOW);
    IR_Remote_Mode();
  }
  else if(digitalRead(mswitch_7)==LOW && digitalRead(mswitch_8)==HIGH){
    digitalWrite(LED_7,LOW); digitalWrite(LED_8,HIGH); digitalWrite(LED_9,LOW);
    Blynk_Mode();
  }
  else{
    digitalWrite(LED_7,LOW); digitalWrite(LED_8,LOW); digitalWrite(LED_9,HIGH);
    Manual_Mode();
  } 
}

void LedOnOff(int led){
  switch(led){
    case 1:
    if(toggleState_1 == 0){
      digitalWrite(LED_1,HIGH);   //Hall LED is in "On Condition"
      toggleState_1 = 1;
    }
    else{
      digitalWrite(LED_1,LOW);   //Hall LED is in "Off Condition"
      toggleState_1 = 0;     
    }
    break;
    
    case 2:
    if(toggleState_2 == 0){
      digitalWrite(LED_2,HIGH);   //Kitchen LED is in "On Condition"
      toggleState_2 = 1;
    }
    else{
      digitalWrite(LED_2,LOW);   //Kitchen LED is in "Off Condition"
      toggleState_2 = 0;     
    }
    break;

    case 3:
    if(toggleState_3 == 0){
      digitalWrite(LED_3,HIGH);   //Bed_Room LED is in "On Condition"
      toggleState_3 = 1;
    }
    else{
      digitalWrite(LED_3,LOW);   //Bed_Room LED is in "Off Condition"
      toggleState_3 = 0;     
    }
    break;

    case 4:
    if(toggleState_4 == 0){
      digitalWrite(LED_4,HIGH);   //Bathroom LED is in "On Condition"
      toggleState_4 = 1;
    }
    else{
      digitalWrite(LED_4,LOW);   //Bathroom LED is in "Off Condition"
      toggleState_4 = 0;     
    }
    break;

    case 5:
    if(toggleState_5 == 0){
      digitalWrite(LED_5,HIGH);   //Parking_Garage LED is in "On Condition"
      toggleState_5 = 1;
    }
    else{
      digitalWrite(LED_5,LOW);   //Parking_Garage LED is in "Off Condition"
      toggleState_5 = 0;     
    }
    break;

    case 6:
    if(toggleState_6 == 0){
      digitalWrite(LED_6,HIGH);   //Garden_Light LED's is in "On Condition"
      toggleState_6 = 1;
    }
    else{
      digitalWrite(LED_6,LOW);    //Garden_Light LED's is in "Off Condition"
      toggleState_6 = 0;     
    }
    break;
    default : break;
  }
}

void IR_Remote_Mode(){ //Function for IR_Remote operating
  if(irrecv.decode(&results)){
    Serial.println(results.value);
    switch(results.value){
      //case 33480735: LedOnOff(0); break;
      case 33444015: LedOnOff(1); break;                //IR_Remote control for Hall LED
      case 33478695: LedOnOff(2); break;                //IR_Remote control for Kitchen LED
      case 33486855: LedOnOff(3); break;                //IR_Remote control for Bed_Room LED
      case 33435855: LedOnOff(4); break;                //IR_Remote control for Bath_Room LED
      case 33468495: LedOnOff(5); break;                //IR_Remote control for Parking_Garage LED
      case 33452175: LedOnOff(6); break;                //IR_Remote control for Garden LED's
      //case 33423615: LedOnOff(7); break;
      //case 33484815: LedOnOff(8); break;
      //case 33462375: LedOnOff(9); break;
      default : break;
    }
    irrecv.resume(); // Receive the next value
  }
}

void Blynk_Mode(){ //Function for blynk operating
  if(Serial.available()){
    char data=Serial.read();
    switch(data){
      case 'A': LedOnOff(1); break;        //Blynk_App control for Hall LED
      case 'a': LedOnOff(1); break;
      case 'B': LedOnOff(2); break;        //Blynk_App control for Kitchen LED
      case 'b': LedOnOff(2); break;        
      case 'C': LedOnOff(3); break;        //Blynk_App control for Bed_Room LED
      case 'c': LedOnOff(3); break;
      case 'D': LedOnOff(4); break;        //Blynk_App control for Bath_Room LED
      case 'd': LedOnOff(4); break;
      case 'E': LedOnOff(5); break;        //Blynk_App control for Parking_Garage LED
      case 'e': LedOnOff(5); break;
      case 'F': LedOnOff(6); break;        //Blynk_App control for Garden LED's
      case 'f': LedOnOff(6); break;
      default : break;
    }
    Serial.println(data);
  }
  delay(100);
}

void Manual_Mode(){ //Function for manual operating
  Manual_LED_1();
  Manual_LED_2();
  Manual_LED_3();
  Manual_LED_4();
  Manual_LED_5();
  Manual_LED_6();
}

void Manual_LED_1(){
  if(digitalRead(mswitch_1)==HIGH){              //Manual control for Hall LED
    digitalWrite(LED_1,HIGH);
  }
  else{
    digitalWrite(LED_1,LOW);
  }
}
void Manual_LED_2(){
  if(digitalRead(mswitch_2)==HIGH){              //Manual control for Hall LED
    digitalWrite(LED_2,HIGH);
  }
  else{
    digitalWrite(LED_2,LOW);
  }
}
void Manual_LED_3(){
  if(digitalRead(mswitch_3)==HIGH){              //Manual control for Hall LED
    digitalWrite(LED_3,HIGH);
  }
  else{
    digitalWrite(LED_3,LOW);
  }
}
void Manual_LED_4(){
  if(digitalRead(mswitch_4)==HIGH){              //Manual control for Hall LED
    digitalWrite(LED_4,HIGH);
  }
  else{
    digitalWrite(LED_4,LOW);
  }
}
void Manual_LED_5(){
  if(digitalRead(mswitch_5)==HIGH){              //Manual control for Hall LED
    digitalWrite(LED_5,HIGH);
  }
  else{
    digitalWrite(LED_5,LOW);
  }
}
void Manual_LED_6(){
  if(digitalRead(mswitch_6)==HIGH){              //Manual control for Hall LED
    digitalWrite(LED_6,HIGH);
  }
  else{
    digitalWrite(LED_6,LOW);
  }
}

Arduino Nano

Arduino
Water Level Indicator System
const int trigPin = 9; // pin on the arduinowhere the trigger pin is connected
const int echoPin = 10;// pin on the arduino where the echo pin is connected
const int led1 = 2; // water level indicator 1
const int led2 = 3; // water level indicator 2
const int led3 = 4; // water level indicator 3
const int led4 = 5;// pin connected to the base of NPN transistor through a resistor for switching the pump ON and off
const int buzzer=6;
long duration; // variable where the the reflection time of the ultrasound is stored
int distance; // variable where the distance of the measured object is stored
void setup()
{
pinMode (led1, OUTPUT);// sets as output
pinMode (led2, OUTPUT);//sets as output
pinMode (led3, OUTPUT);//sets as aoutput
pinMode(led4, OUTPUT);//sets as output
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzer, OUTPUT);
Serial.begin(9600); // Starts the serial communication
}

void loop()
{
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);


if ( distance<=3)// when water has gotten to this level or is less than this level
{
digitalWrite (led1, HIGH);// led1 comes ON and remains ON
digitalWrite (led2, HIGH);
digitalWrite (led3, HIGH);
digitalWrite (led4, HIGH);
tone(buzzer,3000);
delay(3000);
noTone(buzzer);
delay(3000);
}
if (distance>=4&&distance<=6)// when the level of water has gotten to this level
{
digitalWrite(led1, HIGH);// switch ON the Tap
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
}
if ( distance>=7&&distance<=9)// when water has gotten to this level or is less than this level
{
digitalWrite (led1, HIGH);
digitalWrite (led2, HIGH);//switch ON the led2
digitalWrite (led3, LOW);
digitalWrite (led4, LOW);
}
if( distance>=10&&distance<=12)// when water has gotten to this level or is less than this level
{
digitalWrite (led1, HIGH);//switch ON the led3
digitalWrite (led2, LOW);
digitalWrite (led3, LOW);
digitalWrite (led4, LOW);
}
if (distance>12)// when the level of water has gotten to this level
{
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
digitalWrite(led4,LOW);//led4 goes OF and stays OF
}
}

MLX90614 Library

Keypad-Master Library

LCD I2C Library

DHT Library

SSD Library

IR Remote Library

Blynk Library

BUSIO (I2C) Library

Adafruit GFX Library

Adafruit Sensor Master

Credits

Meda Narendra

Meda Narendra

0 projects • 0 followers
tharun_seemakurthi

tharun_seemakurthi

0 projects • 0 followers
kudumula_aruna

kudumula_aruna

0 projects • 0 followers
vishalsingh37

vishalsingh37

0 projects • 0 followers

Comments

Add projectSign up / Login