/* this code is used to check if someone trying to enter you home ,after entering the password 3 times wrong using the keypad of the shield
the shield will send you a message that
tell you someone try to enter your home ,if he had already entered the ultrasonic will detect that
then the shield will write a post on your timeline to ask people who near from your home to help you ,cause this one nw in you home.
the led will blink only when the password is correct
the password will be (1234)*/
#define CUSTOM_SETTINGS
#define INCLUDE_SMS_SHIELD
#define INCLUDE_FACEBOOK_SHIELD
#define INCLUDE_KEYPAD_SHIELD
#define INCLUDE_TERMINAL_SHIELD
#include <OneSheeld.h>
#define ECHOPIN 12 // Pin to receive echo pulse
#define TRIGPIN 11 // Pin to send trigger pulse
/* Define an iterator. */
int iterations = 0;
bool isAnyButtonIsPressed = false;
/* A name for the LED on pin 13. */
int ledPin = 5;
int i = 0;
void setup()
{
/* Start communication. */
OneSheeld.begin();
/* Set the LED as output. */
pinMode(ledPin, OUTPUT);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
}
void loop()
{
/* Check if any button is pressed */
if ((Keypad.isAnyColumnPressed() || Keypad.isAnyColumnPressed()))
{
isAnyButtonIsPressed = true;
Terminal.println("A button is pressed");
}
else {
isAnyButtonIsPressed = false;
}
/* Check if "1" is pressed, iterate one time. */
if (iterations == 0 && isOnePressed() && isAnyButtonIsPressed == true)
{
Terminal.println("One is pressed");
iterations++;
}
/* Check if "2" is pressed, iterate one time. */
else if (iterations == 1 && isTwoPressed() && isAnyButtonIsPressed == true)
{
Terminal.println("Two is pressed");
iterations++;
}
/* Check if "3" is pressed, iterate one time. */
else if (iterations == 2 && isThreePressed() && isAnyButtonIsPressed == true)
{
Terminal.println("Three is pressed");
iterations++;
}
/* Check if "4" is pressed, iterate one time. */
else if (iterations == 3 && isFourPressed() && isAnyButtonIsPressed == true)
{
Terminal.println("Four is pressed");
iterations++;
}
/* Check if any other button is pressed, reset iterations. */
else if (isOtherButtonPressed() && isAnyButtonIsPressed == true)
{
iterations = 0;
}
//--------------------------------- Check out the password --------------------------------------
/* Check if the number of iterations is 4, blink the LED. */
if (iterations == 4)
{
digitalWrite(ledPin, HIGH);
OneSheeld.delay(3000);
digitalWrite(ledPin, LOW);
OneSheeld.delay(3000);
Terminal.print("Welcome home");
/* Reset the iterator. */
iterations = 0;
isAnyButtonIsPressed == false;
}
else if (iterations == 0 && isAnyButtonIsPressed == true) {
Terminal.println("Wrong one try again ");
i += 1;
Terminal.print("Number of trials = ");
Terminal.println(i);
if (i == 3) {
Terminal.println("The third wrong trial");
/* Send the SMS. */
SMS.send("write your mobile number", "someone trying to enter my house");
Terminal.println("SMS was sent");
// read the ultrasonic value 10 times
for (int j = 0; j <= 9; j++) {
readUltrasonic();
}
// reset the values of i
i = 0;
}//if i equal 3
}//void loop
delay(150);
}//void loop
void readUltrasonic() {
//--------------------------------- Check out ultrasonic sensor --------------------------------------
/* ultrasonic code to check if someone has entered the house */
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW);
// Distance Calculation
float distance = pulseIn(ECHOPIN, HIGH);
distance = distance / 58;
Terminal.print(distance);
Terminal.println(" cm");
if (distance < 50) {
Facebook.post("heeelp! someone has entered my home ..");
}
else {
Terminal.println("safe");
}
}
//--------------------------------------- Keypad Functions ---------------------------------------
/* Helper functions check if a certain button is pressed by checking its row and column. */
boolean isOnePressed() {
return Keypad.isRowPressed(0) && Keypad.isColumnPressed(0);
}
boolean isTwoPressed() {
return Keypad.isRowPressed(0) && Keypad.isColumnPressed(1);
}
boolean isThreePressed() {
return Keypad.isRowPressed(0) && Keypad.isColumnPressed(2);
}
boolean isFourPressed() {
return Keypad.isRowPressed(1) && Keypad.isColumnPressed(0);
}
boolean isOtherButtonPressed() {
return ((Keypad.isAnyColumnPressed() || Keypad.isAnyColumnPressed()) && !isOnePressed() && !isTwoPressed() && !isThreePressed() && !isFourPressed());
}
Comments