Ahmed Ibrahim AhmedMohamed Aboelalla
Published © GPL3+

Smart Home Automation And Security System Using 1Sheeld

We built a smart home automation and security system using our lovely 1Sheeld board and some sensors and some cool stuff.

IntermediateFull instructions provided5 days17,623
Smart Home Automation And Security System Using 1Sheeld

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
1Sheeld
1Sheeld
×1
Relay (generic)
iam using YW Robot Relay 4 Channel
×1
Buzzer
Buzzer
×2
Temperature Sensor
Temperature Sensor
Iam Using LM35DZ
×1
Jumper wires (generic)
Jumper wires (generic)
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
SparkFun magnetic door switch
×2
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Custom parts and enclosures

Lasser Cutting Drawwing1

Schematics

Relay And AC Lamps Connections

the rest of the components

Code

Smart Home Automation & Security System

Arduino
/*
 * Smart Home Automation And Security System Team SADEE
 * EMAIL : ahmedebrahemua@yahoo.com
 * For More Projects Like Our FB Page :  https://www.facebook.com/Scientific-%D9%90Association-of-the-Department-of-Electrical-Engineering-At-ACU-260274217766395/
 */


#define CUSTOM_SETTINGS                  //Used To Define A Specific Shields That We Will Work With To Save The Arduino memory
#define INCLUDE_VOICE_RECOGNIZER_SHIELD   //Help Us To Communicate With The 1 Sheeld Board With Voice Commands
#define INCLUDE_TEXT_TO_SPEECH_SHIELD      
#define INCLUDE_CLOCK_SHIELD
#define INCLUDE_SMS_SHIELD
#define INCLUDE_EMAIL_SHIELD        

#include <LiquidCrystal.h>
#include <OneSheeld.h>

int minutes,hours;                 //Variables That Will Save The Hour And Minutes In It 
String strh;                        //Will Use This Line To Convert The Int Value That The Clock reads To String
String strm;
char h[4];
char m[4];
LiquidCrystal lcd(2,3,4,5,6,7);

#define receptionLamp A1    // This IS The Reception Relay 
#define bedRoomLamp A2          // This Is The BedRoom 
#define pathRoomLamp A3        // This IS The Bathroom 
#define balaconyLamp A4        // This IS The Kitchen 

const char timeCommand[] = "what time is it";       //The Commands Which We Will Say To The 1Sheeld To Perform Its Task
const char receptionCommandOn[] = "reception on";    
const char receptionCommandOff[] = "reception of";
const char whatsUp[] = "good morning";
const char pathRoomCommandOn[] = "bathroom on";
const char pathRoomCommandOff[] = "bathroom off";
const char balaconyCommandOn[] = "kitchen on";
const char balaconyCommandOff[] = "kitchen off";
const char bedRoomCommandOn[] = "bedroom on";
const char bedRoomCommandOff[] = "bedroom off";
const char lightsOn[] = "on";       //This IS For SMS Shield When We Send An SMS Contains (Lights on) The Lights Will Turn On
const char lightsOff[] = "off";     //This IS For SMS Shield When We Send An SMS Contains (Lights ooff) The Lights Will Turn off
//********************************************************************************************************
const char securityModeOn[] = "security on";    //This Is For The Security System When We Say (Security on) Then We triggered The Security System Anyone Will Break The System The Alarm Will Work
const char securityModeOff[] ="security off";    // Turning Off The Security System Anyone Breaks The Security System The Alarm Will Not Work
//********************************************************************************************************
const char mainCommand[] = "jarvis";               //We Say jarvis Before Any Voice Command To Make The System Hearing me 
String noon;
//#define tmp A0                 //For The TMP Sensor We Use LM35DZ
//int voltage,degree;             //The Variables Which Will Contain The Different Voltages During The Changing Of Temperatures , And The Degree In Celisus After A Simple Mathematical EQ. 

byte smile[] = {                     //Making A Smile Symbol On The Liquid crystal Screen
  B00000,
  B01001,
  B01001,
  B00000,
  B00000,
  B10001,
  B01110,
  B00000,
};

#define magneticReception 8          //The MAgnetic Switch For The Reception
#define magneticBalacony 9           //The MAgnetic Switch For The Balacony
int buzzer2 = 10;     // This Buzzer iS for temperature sensor
      //D11 Was Free;
int buzzer1 = A5;     //This Buzzer Is For The Magnetic Switches If Someone Breaks The Security System This Will Buzzer Will Work
int magneticReceptionState;       //Variable Will Contain The Reading Of The MAgnetic Switch If It Was 1 Or 0
int magneticBalaconyState;
int state =0;                        // This For Jarvis
bool security;                        // This For the Security System 

void setup() {


noTone(buzzer1);
noTone(buzzer2);

//analogReference(INTERNAL);          //Reference For The TMP Sensor To Be Accurate 1.1 Voltage

digitalWrite(receptionLamp,HIGH);
digitalWrite(bedRoomLamp,HIGH);
digitalWrite(pathRoomLamp,HIGH);
digitalWrite(balaconyLamp,HIGH);


//passState = false;

lcd.begin(16,2);          //Begin The LCD 
OneSheeld.begin();             //Begin the OneSheeld Board

pinMode(receptionLamp,OUTPUT);           
pinMode(bedRoomLamp,OUTPUT);
pinMode(balaconyLamp,OUTPUT);
pinMode(pathRoomLamp,OUTPUT);
pinMode(buzzer1,OUTPUT);       //for magnetic switch
pinMode(magneticReception,INPUT_PULLUP);        //We Use The PULLUP Resistor Which Builtin In The Board
pinMode(magneticBalacony,INPUT_PULLUP);
//pinMode(tmp,INPUT);
pinMode(buzzer2,OUTPUT);  //for temperature sensor
lcd.createChar(0,smile);

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Welcome To The ");
delay(4000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Smart Home");
lcd.setCursor(0,1);
lcd.print("Automation And ");
delay(4000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Security System");
delay(4000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("CALIBRATING....");
delay(10000);
if(!VoiceRecognition.isNewCommandReceived())           //If there IS No Voice Commands Print This WOrds
{
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("We Are Here To");
    lcd.setCursor(4,1);
    lcd.print("HELP You");
    
}
security =false;

}

void loop() {


Clock.queryDateAndTime();             //This Function for Quering The Date And Time USing The Clock Shield On The OneSheeld Board
SMS.setOnSmsReceive(&MyFunction);             //This Function For The SMS 

minutes = Clock.getMinutes();
hours = Clock.getHours();

if(hours>12)                  //We Doing This To Change The Time from 24 Hours System to 12 Hours System And To know Is It AM Or PM
{
  hours-=12;
  noon="P M";
}
else
{
 noon="A M";  
}

strh = String(hours);
strm = String(minutes);
strh.toCharArray(h,4);                          //Converting The Hours Which We Convert To String To be A Char Array
strm.toCharArray(m,4);


VoiceRecognition.start();                  //Start The Voice Recognition Shield
OneSheeld.delay(8000);                       //Delay To make The orders Then Start Agaim
if(VoiceRecognition.isNewCommandReceived())
{
  if(!strcmp(mainCommand,VoiceRecognition.getLastCommand()))                  //Compare The Last Voice Command With The Main Command Which is "Alexa" 
  {
    TextToSpeech.say("yes sir");                    //This Function Is To Order The Text To Speech Shield To Perform Its Task 
    lcd.clear();
    lcd.setCursor(8,0);
    lcd.write(byte(0));
    state = 1;
  }

  
  if(!strcmp(receptionCommandOn,VoiceRecognition.getLastCommand())&&state==1)        //Compare The Two Strings The Last Command Received And The String That I made Before
  {
    TextToSpeech.say("ok sir lamp in the reception is on");              
    OneSheeld.delay(2500);
    digitalWrite(receptionLamp,LOW);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("The Hall Lamp Is");
    lcd.setCursor(8,1);
    lcd.print("ON");
    state =0;
  
  }
  else if (!strcmp(receptionCommandOff,VoiceRecognition.getLastCommand())&&state==1)
  {    
    TextToSpeech.say("ok sir lamp in the reception is off");
    OneSheeld.delay(2500);
    digitalWrite(receptionLamp,HIGH);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("The Hall Lamp Is");
    lcd.setCursor(7,1);
    lcd.print("OFF");
    state =0;
  }
  else if (!strcmp(bedRoomCommandOn,VoiceRecognition.getLastCommand())&&state==1)
  {
    TextToSpeech.say("ok sir lamp in the bedRoom is on");
    OneSheeld.delay(2500);
    digitalWrite(bedRoomLamp,LOW);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("The BedRoom");
    lcd.setCursor(0,1);
    lcd.print("lamp Is: ON");
    state =0;
  }

  else if (!strcmp(bedRoomCommandOff,VoiceRecognition.getLastCommand())&&state==1)
  {
    TextToSpeech.say("ok sir lamp in the bedroom is off");
    OneSheeld.delay(2500);
    digitalWrite(bedRoomLamp,HIGH);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("The Bedroom");
    lcd.setCursor(0,1);
    lcd.print("lamp Is: OFF");
    state=0;
  }
  else if (!strcmp(pathRoomCommandOn,VoiceRecognition.getLastCommand())&&state==1)
  {
    TextToSpeech.say("ok sir lamp in the bathroom is on");
    OneSheeld.delay(2500);
    digitalWrite(pathRoomLamp,LOW);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("The Bathroom");
    lcd.setCursor(0,1);
    lcd.print("lamp Is: ON");
    state=0;
  }

  else if (!strcmp(pathRoomCommandOff,VoiceRecognition.getLastCommand())&&state==1)
  {
    TextToSpeech.say("ok sir lamp in the bathroom is off");
    OneSheeld.delay(2500);
    digitalWrite(pathRoomLamp,HIGH);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("The Bathroom");
    lcd.setCursor(0,1);
    lcd.print("lamp Is: OFF");
  }

  else if (!strcmp(balaconyCommandOn,VoiceRecognition.getLastCommand())&&state==1)
  {
    TextToSpeech.say("ok sir lamp in the kitchen is on");
    OneSheeld.delay(2500);
    digitalWrite(balaconyLamp,LOW);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("The Kitchen");
    lcd.setCursor(0,1);
    lcd.print("Lamp Is: ON");
    state=0;
  }

  else if (!strcmp(balaconyCommandOff,VoiceRecognition.getLastCommand())&&state==1)
  {
    TextToSpeech.say("ok sir lamp in the kitchen is off");
    OneSheeld.delay(2500);
    digitalWrite(balaconyLamp,HIGH);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("The Kitchen");
    lcd.setCursor(0,1);
    lcd.print("Lamp Is: OFF");
    state=0;
  }
  else if(!strcmp(whatsUp,VoiceRecognition.getLastCommand())&&state==1)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Good Morning :)");
    lcd.setCursor(0,1);
    lcd.print("Its A Good Day"); 
    TextToSpeech.say("good morning sir");
    OneSheeld.delay(1500);
    TextToSpeech.say("time in cairo is");
    OneSheeld.delay(1500);
    TextToSpeech.say(h);
    OneSheeld.delay(1000);
    TextToSpeech.say(m);
    OneSheeld.delay(1000);
    TextToSpeech.say(noon);
    state=0;
  }
  else if(!strcmp(timeCommand,VoiceRecognition.getLastCommand())&&state==1)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Time In Cairo Is");
    lcd.setCursor(0,1);
    lcd.print(h);
    lcd.print(":");
    lcd.print(m);
    lcd.print(" ");
    lcd.print(noon);
    TextToSpeech.say("time in cairo is");
    OneSheeld.delay(1500);
    TextToSpeech.say(h);
    OneSheeld.delay(1000);
    TextToSpeech.say(m);
    OneSheeld.delay(1000);
    TextToSpeech.say(noon);
    state=0;
    
  }

  //************************************************************************************************


 else if (!strcmp(securityModeOn,VoiceRecognition.getLastCommand())&&state==1)
  {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.write("Ok,Sir Feel Safe");
  lcd.setCursor(0,1);
  lcd.write("Security Mode");
  delay(200);
  TextToSpeech.say("security system was triggered");
  security=true;
  state=0;
  }

else if (!strcmp(securityModeOff,VoiceRecognition.getLastCommand())&&state==1)
  {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.write("Ok,Sir Security");
  lcd.setCursor(0,1);
  lcd.write("is OFF");
  delay(200);
  TextToSpeech.say("security system was turned off");
  security=false;
  state=0;
  }  
 }


//**********************************************************Security System ***********************************************************


  

magneticReceptionState = digitalRead(magneticReception);
magneticBalaconyState = digitalRead(magneticBalacony);



if(security == true)
{
  if(magneticReceptionState == HIGH || magneticBalaconyState == HIGH)    //If Someone Opens The Door While The Security System Was Working It Will Alarm
  {
    tone(buzzer1 ,1500);
    Email.send("ahmedebrahemua@yahoo.com","Home Security System","Someone Entered Your Home , Be Carefull");
    OneSheeld.delay(3500);
  }
  else if (magneticReceptionState == LOW || magneticBalaconyState == LOW)
  {
    noTone(buzzer1);
  }

}

else if (security == false)
{
  noTone(buzzer1);
}
/*voltage = analogRead(tmp);
  voltage = voltage * 1100 / 1024;
  degree = voltage / 10;

  if(degree >= 35)
  {
    tone(buzzer2,1500);
    Email.send("ahmedebrahemua@yahoo.com","Home Security System","The Temperature In The Kitchen IS Higher Than 45 , Be Carefull");
    OneSheeld.delay(5000);
  }
  else if (degree<25)
  {
    noTone(buzzer2);
  }*/
}

//*******************************************************************************************************************************

void MyFunction(char* phoneNumber , char* messageBody)            // SMS Function ()
{
if(!strcmp(lightsOn,messageBody))                //If We Send "lights on" As SMS All the Lights Will Turn On
{
  digitalWrite(receptionLamp,LOW);
  delay(500);
  digitalWrite(pathRoomLamp,LOW);
  delay(500);
  digitalWrite(bedRoomLamp,LOW);
  delay(500);
  digitalWrite(balaconyLamp,LOW);
  delay(500); 
  TextToSpeech.say("all lights was turned on");
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("All Lights is ON");
  delay(300);
  Email.send("ahmedebrahemua@yahoo.com","Home Security System"," all Lights Were Turned ON");
  OneSheeld.delay(3500);

}
else if(!strcmp(lightsOff,messageBody))                    //If We Send "lights off" As SMS All the Lights Will Turn Off
{
  digitalWrite(receptionLamp,HIGH);
  delay(500);
  digitalWrite(pathRoomLamp,HIGH);
  delay(500);
  digitalWrite(bedRoomLamp,HIGH);
  delay(500);
  digitalWrite(balaconyLamp,HIGH);
  delay(500);
  TextToSpeech.say("all lights was turned off");
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("All Lights Is OFF");
  delay(300);
  Email.send("ahmedebrahemua@yahoo.com","Home Security System"," all Were Turned OFF ");
  OneSheeld.delay(3500);
}
}

Credits

Ahmed Ibrahim Ahmed

Ahmed Ibrahim Ahmed

11 projects • 106 followers
An Egyptian Computer Engineering Student, Robotics And Embedded Systems Geek.
Mohamed Aboelalla

Mohamed Aboelalla

1 project • 5 followers
An Egyptian Electrical Engineering Student, Robotics And Embedded System Geeks. Professional At Handmade Boards.

Comments