SuryaTuraga
Published © GPL3+

Crack Me If You Can

RFID reader and servo motor enabled locker to keep your precious things safe.

IntermediateShowcase (no instructions)2,491
Crack Me If You Can

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Buzzer
Buzzer
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Servos (Tower Pro MG996R)
×1
RFID reader (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Arduino RFID locker

Code

Arduino RFID locker

Arduino
Works on any Arduino Uno systems with the required controls
// Created by Surya Skywalker. This code will be used in the locker. when the correct card is swiped, light goes gren and door opens and when swiped a second time, door closes and light goes
// to blue. when wrong card is swiped, ligh goes red and buzzer beeps. 

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>

#define SS_PIN 10
#define RST_PIN 9
#define Buzzer 8 // Pin 3 connected to + pin of the Buzzer

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

int pos = 0;    // variable to store the servo position
int num = 0;
int redPin = 2;
int greenPin = 4;
int bluePin = 7;
int counter = 0;
const int buzzerPin = 8;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  Serial.println("Approximate your card to the reader...");
  Serial.println();
  myservo.attach(3);  // attaches the servo on pin 9 to the servo object
  myservo.write(0); //Set the servo at position 0
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  setColor(0, 0, 225);  // blue
  pinMode(Buzzer, OUTPUT); // Set buzzer pin to an Output pin
  digitalWrite(Buzzer, LOW); // Buzzer Off at startup

}

void loop() {
  // put your main code here, to run repeatedly:
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "4A 31 07 85") //change here the UID of the card/cards that you want to give access
  {
    if (num % 2 == 0)
    {
      setColor(0, 225, 0); // Green
      myservo.write(180);
      Serial.println("Authorized access");
      Serial.println();
    }
    else  {
      Serial.println("Locking...");
      myservo.write(0);
      delay(750);
      Serial.println("Message : Locked");
      Serial.println();
      setColor(0, 0, 225); // Blue
    }
    num = num + 1;
    delay(3000);
  }
 
  else   {
    setColor(225, 0, 0); // Red
    Serial.println("Access denied");
    Serial.println();
    beep(1000,10000);
    setColor(0, 0, 225); // Blue
  }
}

void setColor(int red, int green, int blue)
{
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);  
}

void beep(int note, int duration)
{
  //Play tone on buzzerPin
  tone(buzzerPin, note);
  delay(duration);
  //Stop tone on buzzerPin
  noTone(buzzerPin);
 
  delay(50);
 
  //Increment counter
  counter++;
}

Credits

SuryaTuraga

SuryaTuraga

0 projects • 3 followers

Comments