I will show you how to easily make a RFID lock using an Arduino UNO and RFID RC522 (MIFARE protocol). This project can also be seen here: Arduino RFID lock.
Step 1: Components- Arduino UNO
- RFID RC522
- TG9e servo
- LED RGB - WS2812
- 2 x RFID tag
At the beginning, we import all the needed libraries.
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <Adafruit_NeoPixel.h> //----------------------------------------------------------
Then we configure and initialize: UART speed
We initiate rc522. We set the servo to zero.
void setup() { Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("For more: http://geek.adachsoft.com");
Serial.println("Arduino RFID lock");
Serial.println("");
myservo.attach(SERVO_PIN);
myservo.write( 0 );
pixels.begin();
pixels.setPixelColor(0, 32, 32, 32);
pixels.show();
delay(500);
pixels.setPixelColor(0, 0, 0, 0);
pixels.show();
}
//----------------------------------------------------------
After we read the UID tag, we compare it with the proper UID. If the UID is the same then start the servo.
if( content == "77-39-50-39" ){ Serial.println("Authorized access");
myservo.write( 90 );
pixels.setPixelColor(0, 0, 32, 0);
pixels.show();
delay(1000);
myservo.write( 0 );
pixels.setPixelColor(0, 0, 0, 0);
pixels.show();
}else{
Serial.println("Access denied");
pixels.setPixelColor(0, 32, 0, 0);
pixels.show();
delay(500);
pixels.setPixelColor(0, 0, 0, 0);
pixels.show();
}
//----------------------------------------------------------
Download source code: RFID_with_servo.ino
Step 4: End and Checking
Comments