Introduction: Home Automation and Security Using 1Sheeld

This is a home automation and security system using 1Sheeld, The project works as the following :

when the user reaches his home door a pir sensor will sense him so a led will be turned on and then he has to say a specific password to can access his home if the password is right the entrance led and the music player will be turned on and if the password is wrong a buzzer will be turned on and the camera will capture a photo of him and tweeted it on twitter and for the kitchen their are a water and a gas sensor if they passed a certain threshold then for sure there is a problem so the 1 sheeld will send you a message on your mobile phone telling you that and if the problem is in the gas ratio the fan will be turned on to push that gas outside your home.

Step 1: Components and Tools Needed

In This project we are going to need :

  1. Smart phone with 1sheeld apllication
  2. 1Sheeld
  3. Arduino Uno/mega
  4. Water sensor
  5. Gas sensor
  6. Leds
  7. Lamp
  8. Fan
  9. Buzzer
  10. Relay module
  11. PIR sensor

Step 2: Code :

*this  is a Home security project using Arduino UNO board and the ammazing 1sheild*/
@author		Ahmed ismail , hussien mohamed
@email		mido-ahlawy-92@hotmail.com ,hussien.G750@gmail.com
@ide		Arduino IDE
* Include 1Sheeld library. */
#include <onesheeld.h></onesheeld.h>
#define CUSTOM_SETTINGS
#define INCLUDE_VOICE_RECOGNIZER_SHIELD
#define INCLUDE_LCD_SHIELD
#define INCLUDE_MUSIC_PLAYER_SHIELD
#define INCLUDE_TERMINAL_SHIELD
#define INCLUDE_CAMERA_SHIELD
#define INCLUDE_TWITTER_SHIELD
#define INCLUDE_SMS_SHIELD
#define pir    A0
#define gas    A1
#define water  A2
#define led1   11
#define led2   12
#define led3   10
#define lamp   13
#define fan    5
#define buzzer 9
/* Define some variables. */
int pirv = 0;
int gasv = 0;
int waterv = 0;
boolean isMessageSent = false;
/* Voice command set by the user. */
const char openCommand[] = "open";
void setup() {
  /* Start communication. */
  OneSheeld.begin();
  /* Error Commands handiling. */
  VoiceRecognition.setOnError(error);
  VoiceRecognition.start();
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(lamp, OUTPUT);
  pinMode(fan, OUTPUT);
}
void loop() {
  LCD.begin();
  pirv =   digitalRead(pir);
  gasv =   digitalRead(gas);
  waterv = analogRead(water);
  if (pirv == 1) {
    digitalWrite(led2, HIGH);
    LCD.print("say password");
    delay(5000);
    if (VoiceRecognition.isNewCommandReceived()) {
      /* Compare the open command. */
      if (!strcmp(openCommand, VoiceRecognition.getLastCommand())) {
        digitalWrite(led2, LOW);
        digitalWrite(led1, HIGH);
        LCD.print("welcome home ");
        MusicPlayer.play();
        delay(5000);
        digitalWrite(led1, LOW);
      }
      else {
        digitalWrite(buzzer, HIGH);
        Camera.setFlash(ON);
        /* Take the picture. */
        Camera.rearCapture();
        /* Wait for 10 seconds. */
        OneSheeld.delay(10000);
        /* Post the picture on Twitter. */
        Twitter.tweetLastPicture("unauthinticated person");
      }
    }
  }
  if (waterv > 300 || gasv > 200) {
    if (!isMessageSent)
    {
      /* Send the SMS. */
      SMS.send("01094537336", "kitchen ALERT");
      /* Set the flag. */
      isMessageSent = true;
    }
    while (gasv > 200) {
      digitalWrite(fan, HIGH);
    }
  }
}
/* Error checking function. */
void error(byte errorData)
{
  /* Switch on error and print it on the terminal. */
  switch (errorData)
  {
    case NETWORK_TIMEOUT_ERROR: Terminal.println("Network timeout"); break;
    case NETWORK_ERROR: Terminal.println("Network Error"); break;
    case AUDIO_ERROR: Terminal.println("Audio error"); break;
    case SERVER_ERROR: Terminal.println("No Server"); break;
    case SPEECH_TIMEOUT_ERROR: Terminal.println("Speech timeout"); break;
    case NO_MATCH_ERROR: Terminal.println("No match"); break;
    case RECOGNIZER_BUSY_ERROR: Terminal.println("Busy"); break;
  }
}