Ramy ElMallah
Published © GPL3+

Home Automation using Arduino and 1Sheeld

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

BeginnerFull instructions provided1 hour6,189
Home Automation using Arduino and 1Sheeld

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
1Sheeld
1Sheeld
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Android device
Android device
×1
Arduino cable
×1
electric strike
×1
relay module
×1
smoke sensor module
×1
jumpers
×1
lamp
×1

Story

Read more

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.

Code

home automation using arduino and 1sheeld

Arduino
#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);

    }
  }
}

Credits

Ramy ElMallah

Ramy ElMallah

1 project • 6 followers
I believe in the power of entrepreneurship. Interested in robotics and automation. Studying Mechatronic Systems Engineering at SFU!

Comments