Project in progress
Locks controlled via bluetooth

Locks controlled via bluetooth © CC BY-NC

Onesheeld application. With this you can allow up to 10 person to use some resources as doors etc, with name associate to a numeric pass.

  • 2,164 views
  • 2 comments
  • 13 respects

Components and supplies

About this project


Arduino + 1Sheeld application: system for the management of a cabinet inside the FabLab by reference voice and typing a password.

Easy to convert for handling of other similar resources.


--------------------------------------------------------------------------------------------------

INSTRUCTIONS

--------------------------------------------------------------------------------------------------

Hardware

Lock:

  1. 1 servo motor;
  2. 1 red Led;
  3. 1 green Led;
  4. parts created in Autodesk Inventor and printed with Delta Wasp and Prusa I3;
  5. wires;
  6. 3M screews.


Core:

  1. Arduino Uno;
  2. 1Sheeld;


The current code is only for demonstration, so we used only 2 locks. To use it with a larger number of locks you may want to build an extension card pin with simple shift registers.


Software

  • In order to reduce the size of 1Sheeld library is recommended to follow the tutorial below: http://1sheeld.com/tutorials/how-to-decrease-1sheeld-library-size-for-arduino-especially-uno 
  • In order to prevent the memory overflow, you must insert all names of people who can access resources controlled by this application in the arrayName[] definition.
  • Even if you can change with the "password" command, should be anyway entered the default passwords in arrayPassword[] definition.
  • In arrayLockPin and arrayLockStatus you can specify the pin which will be connected to the various LED locks.
  • In order to decrease the wearing of the engines and the power used we detach the servos to stop the segnal from Arduino.


Android Application

You must enable:

  1. KeyPad shield;
  2. TextToSpeech shield;
  3. VoiceRecognition shield.


Commands:

  1. Use Voice Recognition to access to your command menu;
  2. Use KeyPad to insert your password;
  3. you can:
  • Open the lock using Voice Recognition and saying "open";
  • Close the lock using Voice Recognition and saying "close";
  • Change your Password using Voice Recognition and saying "password" and then using Keypad to insert new password;
  • Exit to your menu using Voice Recognition and saying "exit";

Note: you need to get out of a session with the command "exit" to allow another person to access their menu.

Code

Untitled fileC/C++
/*-----------------------------------------------------------------------------------------------------------------------------------------
  Onesheeld application that use 3 Shields : VoiceRecognition; Keypad; TextToSpeech. You must run those items in OneSheeld Android App,
  in order to use this application. With this you can allow up to 10 person to use some critical resources, doors, lock box etc, with
  name associate to a numeric password. In our case we use this program to control the cabinet doors of FabLab crew. In normal mode the
  person who want to use the resource, say is name in the VoiceRecognition section and then compone his password in the Keypad.
  All the operation are  articulated by a voice through TextToSpeech.

  Paolo Sanna Technical Manager of FabLab SPQwoRk May 20015
  
  ------------------------------------------------------------------------------------------------------------------------------------------*/



/* invoke OneSheeld library */
#include <OneSheeld.h>
#include <Servo.h>

/*definition block*/
#define maxNumberofGuy 10 /* 10 number of max users */
#define startName "noOne"

/*variables*/
int ledPin1 = 4;
int ledStatus1 = 7;
int ledPin2 = 8;
int ledStatus2 = 12;
int Actualpassword;
char *voiceCommand;
String voiceCommandString;
String actualName;
String arrayName[maxNumberofGuy] = {"paolo", "tommaso", "sergio", "fabiano", "jonathan", "lorenzo", "eleonora", "valerio"}; //members
int arrayPassword[maxNumberofGuy] = {1234, 4321, 9874, 4789, 6547, 7456, 8523, 3258}; //default passwords
int arrayLockPin[maxNumberofGuy] = {ledPin1,ledPin2, }; //led lock pairs
int arrayLockStatus[maxNumberofGuy] = {ledStatus1,ledStatus2, };
int positionArray;
int count = 0;
//create servo object for each lock
Servo lock1; // lock number 1
Servo lock2; // lock number 2

/*Commands Flags*/
bool passAquired = false;
bool vacancyFlag = false;
bool blinkFlag = false;
bool wrongName = false;
bool newCommandFlag = true;

/*initialization */
void setup()
{
  OneSheeld.begin();
  actualName.reserve(11);
  positionArray = 0;
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledStatus1, OUTPUT);
  pinMode(ledStatus2, OUTPUT);
  actualName = startName;
  lock1.attach(3);
  lock2.attach(5);
  lock1.write(0);
  lock2.write(0);
  digitalWrite(ledPin1,LOW);
  digitalWrite(ledStatus1,HIGH);
  digitalWrite(ledPin2,LOW);
  digitalWrite(ledStatus2,HIGH);
}

void loop()
{
  searchName();
}
/*Functions definition*/

void searchName()
{
 
  if (actualName == startName){
      for(int pos = 0; pos<10; pos++){ 
    if (blinkFlag){
      digitalWrite(arrayLockStatus[pos], HIGH); OneSheeld.delay(50);
    } else 
    if (!blinkFlag){
      digitalWrite(arrayLockStatus[pos], LOW); OneSheeld.delay(50);
    }
    }
    blinkFlag = !blinkFlag;
  }

  positionArray = 0;
  passAquired = false;
  if (VoiceRecognition.isNewCommandReceived( )){
    voiceCommandString = VoiceRecognition.getCommandAsString();
    OneSheeld.delay(1000);
    actualName = String(voiceCommandString);
    if (Names(actualName) && (count < 3)){
      TextToSpeech.say(F("Insert password"));
      OneSheeld.delay(1000);
      while (!Keypad.isAnyRowPressed() && !passAquired){
        Keypad.setOnButtonChange(&password);
        OneSheeld.delay(1000);
      }
      count++;
      passControl(positionArray);
    } else 
    if (!(Names(actualName)) || (count = 3)){
      actualName = startName;
    }
  }
}

void commandMenu()
{
  newCommandFlag = true;
  TextToSpeech.say(F("Command"));
  OneSheeld.delay(2000);
  while (newCommandFlag)
  {
    OneSheeld.delay(2000);
    if ( VoiceRecognition.isNewCommandReceived()){
      OneSheeld.delay(2000);
      voiceCommand = VoiceRecognition.getLastCommand();
      if (strstr(voiceCommand, "open") != NULL) { // open lock   
        openLock(positionArray);
      } else 
      if (strstr(voiceCommand, "close") != NULL){ // close lock     
        closeLock(positionArray);
      } else 
      if (strstr(voiceCommand, "password") != NULL) { // change password      
        changePassword();
      } else 
      if (strstr(voiceCommand, "exit") != NULL){ // exit  menu
        newCommandFlag = false;
        TextToSpeech.say(F("Goodbye"));
        OneSheeld.delay(1000);
        ledBlink(arrayLockStatus[positionArray], 2);
        actualName = startName;
        searchName();
      } else {
        TextToSpeech.say(F("Repeat"));
        OneSheeld.delay(1000);
      }
    }
  }
}

bool Names(String seekName)
{
  boolean machedName = false;
  /* search the name in the list of FabLab crew members */
  do  {
    if (arrayName[positionArray] == seekName){
      machedName = true;
    } else {
      positionArray++;
    }
  }  while ((!machedName) && (positionArray < 9));
  if (!machedName){
    return false;
  } else 
  if (machedName){
    return true;
    ledBlink(arrayLockStatus[positionArray], 2);
    digitalWrite(arrayLockPin[positionArray], HIGH);
  }
}

void password(byte row, byte column)
{
  /*password will be formed by at maximum of 5 numbers */
  int newPassword[] = {0, 0, 0, 0, 0};
  int count = 5;
  bool aquiredFlag = false;
  int numberHold;
  if (!Keypad.isAnyRowPressed()) {}
  else {
    /*to insert the password you must start with the asterisk  and ends with hash */
    if (!(Keypad.isRowPressed(3) && Keypad.isColumnPressed(0))){
      TextToSpeech.say(F("Press asterisk"));
      OneSheeld.delay(2000);
    }
    else {
      TextToSpeech.say(F("Ready"));

      OneSheeld.delay(1000);
      while (!aquiredFlag && count != 0 ){
        numberHold = numberPressed();
        OneSheeld.delay(1000);
        /*create the password from buttons pushed in the Keypad */
        if (numberHold == 10) {
          aquiredFlag = true;
        } else {
          aquiredFlag = false;
        }
        if ((count == 5) && !aquiredFlag){
          {
            count--;
            newPassword[4] = numberHold;
          }
        } else 
        if ((count == 4) && !aquiredFlag){
          {
            count--;
            newPassword[3] = newPassword[4];
            newPassword[4] = numberHold;
          }
        } else 
        if ((count == 3) && !aquiredFlag){
          { count--; newPassword[2] = newPassword[3]; newPassword[3] = newPassword[4];
            newPassword[4] = numberHold;
          }
        } else 
        if ((count == 2) && !aquiredFlag){
          { count--; newPassword[1] = newPassword[2]; newPassword[2] = newPassword[3];
            newPassword[3] = newPassword[4]; newPassword[4] = numberHold;
          }
        } else 
        if ((count == 1) && !aquiredFlag){
          { count--; newPassword[0] = newPassword[1]; newPassword[1] = newPassword[2];
            newPassword[2] = newPassword[3]; newPassword[3] = newPassword[4]; newPassword[4] = numberHold;
          }
        }
      }
      Actualpassword = 10000 * newPassword[0] + 1000 * newPassword[1] + 100 * newPassword[2] + 10 * newPassword[3] + newPassword[4]; // transform the passwords digits to a number
      passAquired = true;
    }
  }
}

void passControl(int n)
{
  passAquired = false;
  int pass = arrayPassword[n];   //transfer the password value to pass for password test
  //password tests
  if (Actualpassword == pass){
    TextToSpeech.say(F("Access allowed"));
    OneSheeld.delay(2000);
    commandMenu();         //if the password is correct go to the commands menu
  } else 
  if (Actualpassword != pass){
    TextToSpeech.say(F("Access denied"));
    OneSheeld.delay(2000);
    searchName();     //if the password is wrong return to the first generic menu
  }
}

int numberPressed()
{
  TextToSpeech.say(F("Insert number"));
  /* test the keypad buttons to return the correct number pressed */
  while (!Keypad.isAnyRowPressed())
  {
    OneSheeld.delay(1500);
    if (Keypad.isRowPressed(0) && Keypad.isColumnPressed(0)) {
      ledBlink(arrayLockPin[positionArray], 1);
      return 1;
    } else 
    if (Keypad.isRowPressed(0) && Keypad.isColumnPressed(1)) {
      ledBlink(arrayLockPin[positionArray], 1);
      return 2;
    } else 
    if (Keypad.isRowPressed(0) && Keypad.isColumnPressed(2)) {
      ledBlink(arrayLockPin[positionArray], 1);
      return 3;
    } else 
    if (Keypad.isRowPressed(1) && Keypad.isColumnPressed(0)) {
      ledBlink(arrayLockPin[positionArray], 1);
      return 4;
    } else 
    if (Keypad.isRowPressed(1) && Keypad.isColumnPressed(1)) {
      ledBlink(arrayLockPin[positionArray], 1);
      return 5;
    } else 
    if (Keypad.isRowPressed(1) && Keypad.isColumnPressed(2)) {
      ledBlink(arrayLockPin[positionArray], 1);
      return 6;
    } else 
    if (Keypad.isRowPressed(2) && Keypad.isColumnPressed(0)) {
      ledBlink(arrayLockPin[positionArray], 1);
      return 7;
    } else 
    if (Keypad.isRowPressed(2) && Keypad.isColumnPressed(1)) {
      ledBlink(arrayLockPin[positionArray], 1);
      return 8;
    } else 
    if (Keypad.isRowPressed(2) && Keypad.isColumnPressed(2)) {
      ledBlink(arrayLockPin[positionArray], 1);
      return 9;
    } else 
    if (Keypad.isRowPressed(3) && Keypad.isColumnPressed(1)) {
      ledBlink(arrayLockPin[positionArray], 1);
      return 0;
    } else 
    if (Keypad.isRowPressed(3) && Keypad.isColumnPressed(2)) {
      ledBlink(arrayLockPin[positionArray], 2);
      return 10;
    } else 
    if (Keypad.isRowPressed(3) && Keypad.isColumnPressed(0)) {
      return 11;
    } else 
    if (Keypad.isRowPressed(3) && Keypad.isColumnPressed(3)) {
      return 11;
    } else 
    if (Keypad.isRowPressed(2) && Keypad.isColumnPressed(3)) {
      return 11;
    } else 
    if (Keypad.isRowPressed(1) && Keypad.isColumnPressed(3)) {
      return 11;
    } else 
    if (Keypad.isRowPressed(0) && Keypad.isColumnPressed(3)) {
      return 11;
    }
  }
}

void ledBlink(int LedtoBlink, int typeofBlink)
{
  switch (typeofBlink)
  {
    case 1: digitalWrite(LedtoBlink, HIGH); {
        OneSheeld.delay(200);
        digitalWrite(LedtoBlink, LOW);
        break;
      }
    case 2: digitalWrite(LedtoBlink, HIGH); {
        OneSheeld.delay(50); digitalWrite(LedtoBlink, LOW);
        OneSheeld.delay(50); digitalWrite(LedtoBlink, HIGH); OneSheeld.delay(100); digitalWrite(LedtoBlink, LOW); break;
      }
  }
}

void openLock(int positionLock)
{
  switch (positionLock){
   case 0: {lock1.attach(3);lock1.write(90);OneSheeld.delay(1000); lock1.detach(); digitalWrite(arrayLockPin[positionArray],HIGH);digitalWrite(arrayLockStatus[positionArray],LOW);commandMenu(); break;}
   case 1: {lock2.attach(5);lock2.write(90);OneSheeld.delay(1000); lock2.detach(); digitalWrite(arrayLockPin[positionArray],HIGH);digitalWrite(arrayLockStatus[positionArray],LOW);commandMenu(); break;}   
 }
}

void closeLock(int positionLock)
{
    switch (positionLock){
   case 0: {lock1.attach(3);lock1.write(0);OneSheeld.delay(1000); lock1.detach();digitalWrite(arrayLockPin[positionArray],LOW);digitalWrite(arrayLockStatus[positionArray],HIGH); searchName(); break;}
   case 1: {lock2.attach(5);lock2.write(0);OneSheeld.delay(1000); lock2.detach();digitalWrite(arrayLockPin[positionArray],LOW);digitalWrite(arrayLockStatus[positionArray],HIGH); searchName(); break;}   
 }  
}

void changePassword()
{
  TextToSpeech.say(F("Insert new password"));
  OneSheeld.delay(2000);
  while (!Keypad.isAnyRowPressed() && !passAquired){
    Keypad.setOnButtonChange(&password);
    OneSheeld.delay(2000);
  }
  arrayPassword[positionArray] = Actualpassword;
  ledBlink(arrayLockStatus[positionArray], 2);
  TextToSpeech.say(F("Password aquired"));
  OneSheeld.delay(2000);
  passAquired = false;
}

Custom parts and enclosures

Servo motor Lock enclosure for 3d Printer
Lock.zip

Schematics

MakerSpaceFritzing.fzz
MakerSpaceFritzing.fzz

Comments

Similar projects you might like

Bluetooth Controlled Light Switch

Project showcase by Team The Instrumentation Crustaceans

  • 23,397 views
  • 4 comments
  • 26 respects

Controlled Board Eraser using Arduino and 1Sheeld

Project in progress by Mahmoud Ayad

  • 7,131 views
  • 3 comments
  • 32 respects

Bluetooth Controlled Servo

Project tutorial by JANAK13

  • 2,722 views
  • 9 comments
  • 18 respects

Gesture Controlled Trainable Arduino Robot Arm via Bluetooth

Project tutorial by KureBas Robotics

  • 11,564 views
  • 41 comments
  • 98 respects

Bluetooth Controlled Car

Project showcase by Ian St. Louis

  • 10,776 views
  • 3 comments
  • 12 respects

Bluetooth Controlled Car

Project in progress by samanfern

  • 4,133 views
  • 16 comments
  • 31 respects
Add projectSign up / Login