*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;
}
}