Introduction: Key Card Lock

This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)

This Instructable is going to detail how to make a key card access lock that can be attached to fridge or drawer. Simply put the access card up to the sensor and the lock will open.

Step 1: Materials Needed

Arduino Uno

Motor Shield

Stepper Motor

Breadboard

Battery and Battery connector

Pushbutton

RFID Key Card Module

Box for hardware storage

Step 2: 3D Printing

First it is necessary to 3D print all your parts. You need to print the mount bracket, pin, shaft, gear and cover. Use the schematics above to 3D design the parts with Inventor.

Drawings in this order.

1. Cover

2. Pin

3. Shaft.

4. Gear

5. Mount

6. Bracket

Step 3: Attach Shaft to Gear

Glue the shaft to the gear by placing it in the hole designed for it

Step 4: Attach Motor to Cover

Attach the Motor to the Cover using two screws. Then the shaft should slide through the hole in the cover and rest on the motor.

Step 5: Attach 5M Tape to Mount

Cut tape and stick tape to Mount where it is white in the photo.Slide the pin through the holes into resting positon. The cover, gear, shaft and motor should stick on top.

Step 6: Wiring to Arduino

Follow the Wiring diagram with these instructions.

RFID

SDA to pin 10

SCK to pin 13

MOSI to pin 11

MISO to pin 12

IRQ no pin

GRD to GRD

RST to pin 8

3.3V to 3.3V

Motor Shield

Step motor attaches to A B C and D

IN1 to pin 2

IN2 to pin 3

IN3 to pin 4

IN4 to pin 5

+ to 5V

- to GND

Button

To pin 6

To GND

Step 7: CODE Libraries

Download these and put in your libraries

Step 8: CODE Primary

Copy and paste this into your code

/******************************************

#define pin1 2//these are the Arduino pins that we use to activate coils 1-4 of the stepper motor #define pin2 3 #define pin3 4 #define pin4 5

#define delaytime 5 //delay time in ms to control the stepper motor delaytime. //Our tests showed that 8 is about the fastest that can yield reliable operation w/o missing steps

#define buttonS 6 // defining button to close lock

#define gearratio 64 const int stepsPerRevolution = 2048; const int mySteps = 255;

#include // Include of the RC522 Library #include "FastLED.h" // Include of the FastLED library #include // Used for communication via SPI with the Module

#define SDAPIN 10 // RFID Module SDA Pin is connected to the UNO 10 Pin #define RESETPIN 8 // RFID Module RST Pin is connected to the UNO 8 Pin

//#define Buzzer 3 // Pin 3 connected to + pin of the Buzzer

byte FoundTag; // Variable used to check if Tag was found byte ReadTag; // Variable used to store anti-collision value to read Tag information byte TagData[MAX_LEN]; // Variable used to store Full Tag Data byte TagSerialNumber[5]; // Variable used to store only Tag Serial Number byte GoodTagSerialNumber[5] = {0xE4, 0xD2, 0x51, 0xEB}; // The Tag Serial number we are looking for

MFRC522 nfc(SDAPIN, RESETPIN); // Init of the library using the UNO pins declared above

void setup() { // initialize the 8 pin as an output: pinMode(pin1, OUTPUT); pinMode(pin2, OUTPUT); pinMode(pin3, OUTPUT); pinMode(pin4, OUTPUT);

pinMode(buttonS, INPUT); // setting the pinmode for the button digitalWrite(buttonS, HIGH); //defining the button as HIGH //Serial.begin(9600);

SPI.begin(); Serial.begin(9600); //For serial monitor

// Start to find an RFID Module Serial.println("Looking for RFID Reader"); nfc.begin(); byte version = nfc.getFirmwareVersion(); // Variable to store Firmware version of the Module

// If can't find an RFID Module if (! version) { Serial.print("Didn't find RC522 board."); while(1); //Wait until a RFID Module is found }

// If found, print the information about the RFID Module Serial.print("Found chip RC522 "); Serial.print("Firmware version: 0x"); Serial.println(version, HEX); Serial.println(); }

void loop(){

String GoodTag="False"; // Variable used to confirm good Tag Detected

// Check to see if a Tag was detected // If yes, then the variable FoundTag will contain "MI_OK" FoundTag = nfc.requestTag(MF1_REQIDL, TagData);

if (FoundTag == MI_OK) { delay(200);

// Get anti-collision value to properly read information from the Tag ReadTag = nfc.antiCollision(TagData); memcpy(TagSerialNumber, TagData, 4); // Write the Tag information in the TagSerialNumber variable

Serial.println("Tag detected."); Serial.print("Serial Number: "); for (int i = 0; i < 4; i++) { // Loop to print serial number to serial monitor Serial.print(TagSerialNumber[i], HEX); Serial.print(", "); } Serial.println(""); Serial.println();

// Check if detected Tag has the right Serial number we are looking for for(int i=0; i < 4; i++){ if (GoodTagSerialNumber[i] != TagSerialNumber[i]) { break; // if not equal, then break out of the "for" loop } if (i == 3) { // if we made it to 4 loops then the Tag Serial numbers are matching GoodTag="TRUE"; } } if (GoodTag == "TRUE"){ Serial.println("Success!!!!!!!"); // if good tag, initiates motor Serial.println(); int numberOfSteps = mySteps; step_OFF(); //turning all coils off while(numberOfSteps>0){ forward(); //going forward numberOfSteps -- ;//counting down the number of steps } delay(100); } FastLED.show(); for (int y = 0; y < 3; y++){

delay (50) ;// Delay 1ms

delay (50) ;// delay 1ms } delay(1500); } else { Serial.println("TAG NOT ACCEPTED...... :("); Serial.println();

}

if(digitalRead(buttonS) == LOW){ // if button pressed, initiates motor step_OFF(); //turning all coils off int numberOfSteps = mySteps; while(numberOfSteps>0){ backward(); //going backward numberOfSteps -- ;//counting down the number of steps Serial.println("LOW"); } delay(100); } }

Copy and paste this into a functions tab

//these functions set the pin settings for each of the four steps per rotation of the motor (keepp in mind that the motor in the kit is geared down,
//i.e. there are many steps necessary per rotation

void Step_A(){ digitalWrite(pin1, HIGH);//turn on coil 1 digitalWrite(pin2, LOW); digitalWrite(pin3, LOW); digitalWrite(pin4, LOW); } void Step_B(){ digitalWrite(pin1, LOW); digitalWrite(pin2, HIGH);//turn on coil 2 digitalWrite(pin3, LOW); digitalWrite(pin4, LOW); } void Step_C(){ digitalWrite(pin1, LOW); digitalWrite(pin2, LOW); digitalWrite(pin3, HIGH); //turn on coil 3 digitalWrite(pin4, LOW); } void Step_D(){ digitalWrite(pin1, LOW); digitalWrite(pin2, LOW); digitalWrite(pin3, LOW); digitalWrite(pin4, HIGH); //turn on coil 4 } void step_OFF(){ digitalWrite(pin1, LOW); //power all coils down digitalWrite(pin2, LOW); digitalWrite(pin3, LOW); digitalWrite(pin4, LOW); }

//these functions run the above configurations in forward and reverse order //the direction of a stepper motor depends on the order in which the coils are turned on. void forward(){//one tooth forward Step_A(); delay(delaytime); Step_B(); delay(delaytime); Step_C(); delay(delaytime); Step_D(); delay(delaytime); }

void backward(){//one tooth backward Step_D(); delay(delaytime); Step_C(); delay(delaytime); Step_B(); delay(delaytime); Step_A(); delay(delaytime); }

Start the serial monitor and run the code.

Press your card up to the sensor and write down the tag info.

Replace the accepted tag info with your tag info

Step 9: Container

Get your container and cut open a hole for the button. Place all wiring into the box.

Congratulations! Your Key Access Lock is now finished!