Door Locker with RFID

Created By:

Created On:

Friday, November 15, 2013 - 11:58

Description:

Project Description:

The idea was to create a door with an RFID-controlled lock.

We started out making the physical door using the laser cutter. We printed hinges in mat board with the laser cutter and covered these with vinyl pieces with the same shape to stregthen the hinges.

The door was printed in 3 equally sized pieces of mat board, and a frame was cut by hand in mat board to support the door. We glued the lot to the existing closet.

Our next step was to build a locking mechanism based on arduino schematics wit a RFID sensor. We had some trouble getting the stepper motor running, we tried different codes and settings, but we weren't able to identify the problem. Although we managed to get the RFID part of assembly and the rfid code to work though.

- Parts used for arduino RFID and locker mechanism assembly :
o Arduinoboard (Uno) x2
o Stepper motor (39bygs202)
o RFID tag kit
o RFID-antenna and reader(Grove125KHz RFID reader)
o Driver chip for stepper motor (a4982)

We used this tutorial for connecting the arduino and RFID:

http://www.instructables.com/id/Arduino-and-RFID-from-seeedstudio/

And here is the following code for the RFID part:

#include <SoftwareSerial.h>

#define ADD_TAG_CODE "210014DFE309" //change this ID with your own card TAG
#define DEL_TAG_CODE "210014E2BD6A" //change this ID with your own card TAG

SoftwareSerial rfid = SoftwareSerial(5, 6);
String msg;
String ID ; //string to store allowed cards

void setup()
{
Serial.begin(9600);
Serial.println("Serial Ready");

rfid.begin(9600);
Serial.println("RFID Ready");
}

char c;

void loop(){

while(rfid.available()>0){
c=rfid.read();
msg += c;
Serial.println(msg);
Serial.println(msg.length());
}
msg=msg.substring(1,13);
if(msg.indexOf(ADD_TAG_CODE)>=0) add();
else if(msg.indexOf(DEL_TAG_CODE)>=0) del();
else if(msg.length()>10) verifica();
msg="";

}

void add(){
Serial.print("What TAG do you wanna grant access?: ");
msg="";
while(msg.length()<13){
while(rfid.available()>0){
c=rfid.read();
msg += c;
}
}
if(ID.indexOf(msg)>=0) {
Serial.println("\nAccess already granted for this card.");
msg="";
}
else{
Serial.print("Card: ");
Serial.println(msg);
ID += msg;
ID += ",";
//Serial.print("ID: ");
// Serial.println(ID);
msg="";
Serial.println("Access granted for this card.");
}

}

void del(){
msg="";
Serial.print("What TAG do you wanna deny access?: ");
while(msg.length()<13){
while(rfid.available()>0){
c=rfid.read();
msg += c;
}
}
msg=msg.substring(1,13);
if(ID.indexOf(msg)>=0){
Serial.println(msg);
Serial.println("TAG found. Access for this card denied.");
//ID.replace(card,"");
int pos=ID.indexOf(msg);
msg="";
msg += ID.substring(0,pos);
msg += ID.substring(pos+15,ID.length());
ID="";
ID += msg;
//Serial.print("ID: ");
//Serial.println(ID);
} else Serial.println("\nTAG not found or already denied");
msg="";
}

void verifica(){
msg=msg.substring(1,13);
if(ID.indexOf(msg)>=0) Serial.println("Access granted.");

else Serial.println("Access denied.");
}

The motor was connected to its driver through a bread board and from that to the Arduino board.
The motor needed a power supply of at least 8V so we measured the actual voltage of a 9V battery and it turned out that it supplied only about 4V so we connected a bunch of 3 batteries to give the required voltage supply for the motor.
As mentioned earlier we didn't manage to get the motor running, but followed instructions from the data sheet of the driver chip a4982. we used the LP package.
We used the following code:

//simple A4988 connection
//jumper reset and sleep together
//connect VDD to Arduino 3.3v or 5v
//connect GND to Arduino GND (GND near VDD)
//connect 1A and 1B to stepper coil 1
//connect 2A and 2B to stepper coil 2
//connect VMOT to power source (9v battery + term)
//connect GRD to power source (9v battery - term)

int enable = 13; //connect pin 13 to enable
int sleep = 12; // connect pin 12 to sleep
int reset = 11; //connect pin 11 to reset
int stp = 10; //connect pin 10 to step
int dir = 9; //connect pin 9 to direction

int a = 0; // gen counter

void setup()
{
pinMode(enable, OUTPUT);
pinMode(sleep, OUTPUT);
pinMode(reset, OUTPUT);
pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);
digitalWrite(enable, LOW);
digitalWrite(sleep, HIGH);
digitalWrite(reset, HIGH);
delay(100);
digitalWrite(reset, LOW);
}

void loop()
{
if (a < 200) //sweep 200 step in dir 1
{
a++;
digitalWrite(stp, HIGH);
delay(10);
digitalWrite(stp, LOW);
delay(10);
}
else
{
digitalWrite(dir, HIGH);
a++;
digitalWrite(stp, HIGH);
delay(10);
digitalWrite(stp, LOW);
delay(10);

if (a>400) //sweep 200 in dir 2
{
a = 0;
digitalWrite(dir, LOW);
}
}
}