Hussien MohamedAhmed Ismail
Published

Home Security Automation Using 1Sheeld

Our project can be easily done in different places and it's away simple thankfully to 1Sheeld.

AdvancedShowcase (no instructions)Over 1 day6,375
Home Security Automation Using 1Sheeld

Things used in this project

Story

Read more

Code

Home Automation and security system using 1Sheeld

C/C++
/*

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

when the user reaches his home door a pir sesnor 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 enterance 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 sesnor if they passed a certain threshold
then for sure there is a problem so the 1 sheild 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

*/


/* Include 1Sheeld library. */
#include <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;
  }
}

Credits

Hussien Mohamed

Hussien Mohamed

2 projects • 10 followers
Addicted to the embedded world , pro chess player , electronics engineer
Ahmed Ismail

Ahmed Ismail

1 project • 6 followers
i am a computer engineer addicted to embedded systems

Comments