Project tutorial
Home Automation using Arduino and 1Sheeld

Home Automation using Arduino and 1Sheeld © GPL3+

Control house lights using keypad on the android phone, smoke detection system, opening home door by a pattern.

  • 4,398 views
  • 2 comments
  • 12 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
×1
Screen shot 2019 03 20 at 2 38 27 pm fqndazqcx1
1Sheeld
×1
11026 02
Jumper wires (generic)
×1
12002 04
Breadboard (generic)
×1
1434509556 android phone color
Android device
×1
Arduino cable
×1
electric strike
×1
relay module
×1
smoke sensor module
×1
jumpers
×1
lamp
×1

About this project

This home automation project is mainly based on Arduino UNO, 1sheeld and an android smartphone. I decided to build this project so that I can make more use of my android smartphone to make the life easier.

Tools and Components Used:

1x breadboard

1x Arduino UNO

1x Arduino cable

1x smoke sensor module

1x Relay Module

1x 220V lamp

1x Home power source

1x 1Sheeld

1x Electric strike

Jumpers

This project enables you to:

1. Control your home (or at least your room's) lights and power outlets (on/off) using a keypad in your android smartphone.

2. Get a buzzer beep through your phone speaker in case of detecting smoke in your home that exceed a threshold predefined value.

3. Access your home, simply opening your home door lock, through entering a pattern. In case of entering the correct pattern, the door becomes unlocked and you get an email informing you that the home was accessed. In case of entering a wrong pattern, a photo of the one entering the pattern is captured and sent to you attached in a mail informing you of an attempt to access the home.

First Step:

1. Connect the 1sheeld to the arduino.

2. Connect the signal pin of the relay module to pin 13 in the Arduino.

3. Connect the vcc pin of the relay module to the 5V pin of the Arduino.

4. Connect the GND pin of the really module to pin GND of the Arduino.

5. Connect the vcc pin of the smoke sensor to pin 5V of the Arduino.

6. Connect the GND pin of the smoke sensor to the GND pin of the arduino.

7. Connect the analog signal pin of the smoke sensor to pin A0 of the Arduino.

8. Connect the signal pin of the electric strike to pin 13 of the Arduino.

9. Connect the power pins of the electric strike to prop-er power sources.

10, Connect Arduino to your computer through the USB cable.

Second Step: Write the code

1. Download 1sheeld Arduino Library and save it in the suitable folder.

2. Start writing the code by adding initialization values and library defining

#define CUSTOM_SETTINGS
#define INCLUDE_BUZZER_SHIELD
#define INCLUDE_PUSH_BUTTON_SHIELD
#define INCLUDE_KEYPAD_SHIELD
#define INCLUDE_EMAIL_SHIELD
#define INCLUDE_PATTERN_SHIELD
#define INCLUDE_CAMERA_SHIELD
#include 
int taken =0;
long previousMillis = 0;
int State = LOW;
int lamp = 12;
int sensor = A0;
int reading = 0;
int Lock = 13;
PatternNode patternStored[] = { {0, 0}, {1, 0}, {2, 0}, {2, 1}, {2, 2} };
int counter = 0;
int length = 0;

3. Writing the setup part of the arduino program

void setup()
{
 OneSheeld.begin();
 pinMode(lamp, OUTPUT);
 pinMode(sensor, INPUT);
 pinMode(Lock, OUTPUT);
}

4. Write the function of the pattern and door lock

void pattern() {  if (Pattern.isNewPatternReceived())
 {
   /* This pointer act as array to store the last pattern entered by user. */
   PatternNode * patternEntered = Pattern.getLastPattern();
   /* Get the length of the pattern to loop over it. */
   length = Pattern.getLastPatternLength();
   /* Check if the pattern length is equal to 5. */
   if (length == 5)
   {
     for (int i = 0; i < length ; i++)
     {
       if (patternEntered[i].row == patternStored[i].row && patternEntered[i].col == patternStored[i].col)
       {
         counter++;
       }
     }
     if (counter == 5)
     {
       digitalWrite(Lock, HIGH); // lock is high when opened
       Email.send("your_email@gmail.com", "Your Home Security", "Your home was accessed right now!");
     taken =0;
     }
     else
     {
       digitalWrite(Lock, LOW);
       if (taken ==0){
       Camera.setFlash(ON);
       Camera.rearCapture();
       taken = 1;
       }
       Email.attachLastPicture ("your_email@gmail.com", "Your Home Security", "Someone tried to access your home and we took a picture of him", 0);
       counter = 0;
     }
   }
   /* If pattern length is different turn off the LED.  */
   else
   {
     digitalWrite(Lock, LOW);
    if (taken ==0){
       Camera.setFlash(ON);
       Camera.rearCapture();
       taken = 1;
       }
     Email.attachLastPicture ("your_emailh@gmail.com", "Your Home Security", "Someone tried to access your home and we took a picture of him", 0);
   }
 }
}

5. Write the loop part of the code in which the function of the keypad and the smoke sensor and the calling of the pattern function are included

void loop()
{
 if (Keypad.isRowPressed(0) && Keypad.isColumnPressed(0))
 {
   if (digitalRead(lamp) == LOW)
   {
     digitalWrite(lamp, HIGH);
   }
   else
   {
     digitalWrite(lamp, LOW);
   }
 }
 reading = analogRead(sensor);
 if (reading >= 90) {
   unsigned long currentMillis = millis();
   if (currentMillis - previousMillis > 1500) {
     // save the last time you blinked the LED
     previousMillis = currentMillis;
     // if the LED is off turn it on and vice-versa:
     if (State == LOW)
     { State = HIGH;
       Buzzer.buzzOn();
     }
     else
     { State = LOW;
       Buzzer.buzzOff();
     }
   }
 }
 else
 {
   Buzzer.buzzOff();
 }
 pattern();
}

Third step: Upload the code

1. Switch the 1sheeld to the upload mode with the switch being directed away from 1sheeld logo.

2. Verify the code on Arduino IDE.

3. Upload the code to the Arduino.

4. Switch the 1sheeld to the bluetooth mode using the switch directed towards the 1sheeld logo.

Fourth and Final Step: HAVE FUN!

1. Download 1sheeld app from play store for android.

2. Open your bluetooth and connect to your shield from the app.

3. Add the following shields:

- Buzzer

- Keypad

- E-mail

- Camera

- Pattern

4. Start testing:

- Click the '1' button of the keypad and enjoy the lamp turning on and turning off when you click it again.

- Expose the smoke sensor of your home to smoke and listen to your phone speaker beeping.

- Try to enter the correct pattern (which is L in this case as written in the code and which is the default pattern) and see the electric strike opening and receiving the email.

- Try to enter a wrong pattern and check the received mail with your photo attachedas the one who have tried to access the home door.

I hope you enjoy the project and learn much from it!

Code

home automation using arduino and 1sheeldArduino
#define CUSTOM_SETTINGS
#define INCLUDE_BUZZER_SHIELD
#define INCLUDE_KEYPAD_SHIELD
#define INCLUDE_EMAIL_SHIELD
#define INCLUDE_PATTERN_SHIELD
#define INCLUDE_CAMERA_SHIELD
#include <OneSheeld.h>
int taken =0;
long previousMillis = 0;
int State = LOW;

int lamp = 12;
int sensor = A0;
int reading = 0;
int Lock = 13;
PatternNode patternStored[] = { {0, 0}, {1, 0}, {2, 0}, {2, 1}, {2, 2} };
int counter = 0;
int length = 0;

void setup()
{
  OneSheeld.begin();
  pinMode(lamp, OUTPUT);
  pinMode(sensor, INPUT);
  pinMode(Lock, OUTPUT);

}

void loop()
{
  if (Keypad.isRowPressed(0) && Keypad.isColumnPressed(0))
  {
    if (digitalRead(lamp) == LOW)
    {
      digitalWrite(lamp, HIGH);
    }
    else
    {
      digitalWrite(lamp, LOW);
    }
  }

  reading = analogRead(sensor);
  if (reading >= 90) {
    unsigned long currentMillis = millis();

    if (currentMillis - previousMillis > 1500) {
      previousMillis = currentMillis;

      if (State == LOW)
      { State = HIGH;
        Buzzer.buzzOn();
      }

      else
      { State = LOW;
        Buzzer.buzzOff();
      }

    }
  }
  else
  {
    Buzzer.buzzOff();
  }

  pattern();

}

void pattern() {


  if (Pattern.isNewPatternReceived())
  {
    PatternNode * patternEntered = Pattern.getLastPattern();

    length = Pattern.getLastPatternLength();
    if (length == 5)
    {

      for (int i = 0; i < length ; i++)
      {

        if (patternEntered[i].row == patternStored[i].row && patternEntered[i].col == patternStored[i].col)
        {
          counter++;
        }
      }


      if (counter == 5)
      {
        digitalWrite(Lock, HIGH); // lock is high when opened
        Email.send("username@gmail.com", "Your Home Security", "Your home was accessed right now!");
      taken =0;
      }
      else
      {
        digitalWrite(Lock, LOW);
        if (taken ==0){
        Camera.setFlash(ON);
        Camera.rearCapture();
        taken = 1;
        }
        Email.attachLastPicture ("username@gmail.com", "Your Home Security", "Someone tried to access your home and we took a picture of him", 0);
        counter = 0;
      }
    }
    else
    {

      digitalWrite(Lock, LOW);
     if (taken ==0){
        Camera.setFlash(ON);
        Camera.rearCapture();
        taken = 1;
        }
      Email.attachLastPicture ("username@gmail.com", "Your Home Security", "Someone tried to access your home and we took a picture of him", 0);

    }
  }
}

Schematics

Project diagram
This is the diagram of the project on fritzing and the only thing which isn't included is the electric strike. I used notes in the fritzing project as alternatives of modules which are not available in fritzing libraries.
project.fzz

Comments

Similar projects you might like

SMS based Home Automation system using 1SHEELD

Project tutorial by Tanishq Jaiswal

  • 30,061 views
  • 11 comments
  • 64 respects

Home Security Automation Using 1Sheeld

Project showcase by Hussien Mohamed and Ahmed Ismail

  • 4,450 views
  • 0 comments
  • 6 respects

Security System With 1Sheeld

Project showcase by nada abdelnaby mady

  • 2,198 views
  • 0 comments
  • 2 respects

Smart Home Automation And Security System Using 1Sheeld

Project tutorial by Team SADEE

  • 9,129 views
  • 6 comments
  • 31 respects

Control Music Volume and Ledbar Using Slider of 1Sheeld

Project tutorial by ahmed ismail

  • 2,112 views
  • 2 comments
  • 14 respects

Arduino can hear and understand your voice with 1Sheeld !

Project tutorial by Alessandro Didonna

  • 4,091 views
  • 1 comment
  • 11 respects
Add projectSign up / Login