يمنى السيد ندا
Published © GPL3+

Secure Your Home by a Password

Activate your security system with Arduino and 1sheeld.

BeginnerFull instructions provided3 hours3,489
Secure Your Home by a Password

Things used in this project

Story

Read more

Schematics

fritzing circuit

Code

code

Arduino
security system sketch
#define CUSTOM_SETTINGS
#define INCLUDE_KEYPAD_SHIELD
#define INCLUDE_CAMERA_SHIELD
#define INCLUDE_TWITTER_SHIELD
#define INCLUDE_MUSIC_PLAYER_SHIELD

/* Include 1Sheeld library. */
#include <OneSheeld.h>

/* Define an iterator. */
int iterations = 0;
/* A name for the LED on pin 13. */
int ledPin1 = 13;
int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin2 = 5;      // select the pin for the LED
int BuzzerPin = 4;    // select the pin for the Buzzer
int sensorValue = 0;  // variable to store the value coming from the sensor
bool flag ;
int push = 12;


void setup()
{
  /* Start communication. */
  OneSheeld.begin();
  /* Set the LED as output. */
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(BuzzerPin, OUTPUT);
  pinMode(sensorPin, INPUT);
}

void loop()
{
  /* Check if "1" is pressed, iterate one time. */
  if (iterations == 0 && isTwoPressed())
  {
    iterations++;
  }
  /* Check if "2" is pressed, iterate one time. */
  else if (iterations == 1 && isZeroPressed())
  {
    iterations++;
  }
  /* Check if "3" is pressed, iterate one time. */
  else if (iterations == 2 && isOnePressed())
  {
    iterations++;
  }
  /* Check if "4" is pressed, iterate one time. */
  else if (iterations == 3 && isSixPressed())
  {
    iterations++;
  }
  /* Check if any other button is pressed, reset iterations. */
  else if (isOtherButtonPressed())
  {
    iterations = 0;
  }

  /* Check if the number of iterations is 4, blink the LED. */
  if (iterations == 4)
  {
    digitalWrite(ledPin1, HIGH);
    // OneSheeld.delay(500);
    //  digitalWrite(ledPin1,LOW);
    flag = true;
    /* Reset the iterator. */
    iterations = 0;
  }

  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  if ( (sensorValue >= 45) && (flag ) )
  {
    digitalWrite(ledPin2, HIGH);
    /* Turn on the camera flash. */
    Camera.setFlash(ON);
    /* Take the picture. */
    Camera.rearCapture();
    /* Wait for 10 seconds. */
    OneSheeld.delay(10000);
    /* Set the volume. */
    MusicPlayer.setVolume(5);
    /* Turn on the music. */
    MusicPlayer.play();
    /* Post the picture on Twitter. */
   // Twitter.tweetLastPicture("Posted by @1Sheeld");
   if ( push == 1)
   { flag = false ;
   }
  }


}

/* Helper functions check if a certain button is pressed by checking its row and column. */

boolean isTwoPressed() {
  return Keypad.isRowPressed(0) && Keypad.isColumnPressed(1);
}

boolean isZeroPressed() {
  return Keypad.isRowPressed(3) && Keypad.isColumnPressed(1);
}

boolean isOnePressed() {
  return Keypad.isRowPressed(0) && Keypad.isColumnPressed(0);
}

boolean isSixPressed() {
  return Keypad.isRowPressed(1) && Keypad.isColumnPressed(2);
}

boolean isOtherButtonPressed() {
  return ((Keypad.isAnyColumnPressed() || Keypad.isAnyColumnPressed()) && !isTwoPressed() && !isZeroPressed() && !isOnePressed() && !isSixPressed());
}

Credits

يمنى السيد ندا

يمنى السيد ندا

2 projects • 4 followers
faculty of engineering, Alazhar university forth year, electronics & communication self employed embedded system engineer
Thanks to Rana Samy.

Comments