In this illustration we will going to wire the RFID (Radio Frequency Identification) Module RC522 in this module it uses a radio signals and a Radio Label Tags for reading and writing data.
How RFID works please refer to this link,
How Servo works please refer to this link.
The most common way of using RFID is the identification or a products, where tag can contain information such as product code, the origin, expiration date, and the manufacturer, etc. also the RFID is used in Tags on animals for tracking purposes, also in vehicles, transportation, cargo tracking and access control and many other purposes.
The RFID Module is able to read tags at operating 12.56MHz frequency, and support cards and tags like Mifare1 S50, Mifare Ultraligh, Mifare1 S70, Mifare DESfire and Mifare Pro.
Gate / Entrance Access Control with RFID
Wiring the RFID Module
This RFID module uses SPI (Serial Peripheral Interface) for communication with the Arduino MCU though the digital pin 10 at 13, pin9 which is the RST (Reset) is connected. See the diagram below the arrangement of the pins and connection to the Arduino board along with the MFRC522 library.
Recognizing the Tags and Cards to Control the Servo using PWM
As you see the sketch below, we include the Servo Code Library which is been already built-in inside of our Arduino IDE, and the RFID You can download the Code library here.
We added two LED to show as our indicator the GREEN will be Access Granted Status and the RED LED will be our Access Denied indicator, which is connected to our Arduino Pin 6.
To read the tag, you need to check the monitor serial number of the tag read by the sensor, and place the number in the code | if (cont.substring(1)==”14 12 22 4A”)
Same thing the cards, you can add identical entries and just change the UID number in each card, released the access and drives the serve, moving to 90* and if the access is denied the red LED will flash.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
/* 14CORE Access Controll Demo */ #include <SPI.h> // Include SPI Bus #include <MFRC522.h> //Include MRFC522 Library #include <Servo.h> // Include Servo Control Library Servo myServo; #define SS_PIN 10 #define RST_PIN 9 MFRC522 mfrc522 (SS_PIN, RST_PIN); // Define pin module RC522 // LED indicators released or denied access int led_granted = 5; int led_denied = 6; char st [20]; void setup () { pinMode (led_granted, OUTPUT); pinMode (led_denied, OUTPUT); myServo.attach(3); // Set servo atach which is connected to digital pin 3 myServo.write(90); // Gate Close Move the servo to the home position Serial.begin (9600) ; // Enable Serial at baud rate 9600 SPI.begin (); // Starts SPI bus Commnunication mfrc522.PCD_Init (); // Starts MFRC522 Serial.println ("Initializing your card reader ..."); Serial.println (); } void loop () { if (! Mfrc522.PICC_IsNewCardPresent ()) // approximation of the card { return; } // Select one of the cards if (! Mfrc522.PICC_ReadCardSerial ()) { return; } Serial.print ("UID Tag:"); // Display the UID serial String content = ""; byte letter; is (byte i = 0; i <mfrc522.uid.size; i ++) { Serial.print (mfrc522.uid.uidByte [i] <0x10? "0": ""); Serial.print (mfrc522.uid.uidByte [i] HEX); cont.concat (String (mfrc522.uid.uidByte [i] <0x10? "0": "")); cont.concat (String (mfrc522.uid.uidByte [i] HEX)); } Serial.println (); Serial.print ("message"); cont.toUpperCase (); if (cont.substring (1) == "14 12 22 4A") // Test if the Card been read { myServo.write (- 90); // Raises the gate and lights the green led digitalWrite (led_granted, HIGH); Serial.println ("Card - Access Granted"); Serial.println (); delay (3000); myServo.write (90); digitalWrite (led_granted, LOW); } if (cont.substring (1) == "14 22 12 8A") // Test if the Card been read { Serial.println ("Card - Access Denied"); Serial.println (); for (int i = 1; i <5; i ++) // Flashing red LED { digitalWrite (led_denied, HIGH); delay (200); digitalWrite (led_denied, LOW); delay (200); } } delay (1000); } Download the MFRC522 Code Library Here | Zip |
Sketch Code for Using Single Channel Relay
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
/* 14CORE Access Controll Demo */ #include <SPI.h> // Include SPI Bus #include <MFRC522.h> //Include MRFC522 Library #define SS_PIN 10 #define RST_PIN 9 MFRC522 mfrc522 (SS_PIN, RST_PIN); // Define pin module RC522 // Relay int R1 = 9; // LED indicators released or denied access int led_granted = 5; int led_denied = 6; char st [20]; void setup () { pinMode (led_granted, OUTPUT); pinMode (led_denied, OUTPUT); Serial.begin (9600) ; // Enable Serial at baud rate 9600 SPI.begin (); // Starts SPI bus Commnunication mfrc522.PCD_Init (); // Starts MFRC522 Serial.println ("Initializing your card reader ..."); Serial.println (); } void loop () { if (! Mfrc522.PICC_IsNewCardPresent ()) // approximation of the card { return; } // Select one of the cards if (! Mfrc522.PICC_ReadCardSerial ()) { return; } Serial.print ("UID Tag:"); // Display the UID serial String content = ""; byte letter; is (byte i = 0; i <mfrc522.uid.size; i ++) { Serial.print (mfrc522.uid.uidByte [i] <0x10? "0": ""); Serial.print (mfrc522.uid.uidByte [i] HEX); cont.concat (String (mfrc522.uid.uidByte [i] <0x10? "0": "")); cont.concat (String (mfrc522.uid.uidByte [i] HEX)); } Serial.println (); Serial.print ("message"); cont.toUpperCase (); if (cont.substring (1) == "14 12 22 4A") // Test if the Card been read { digitalWrite(R1, HIGH); // Raises the gate and lights the green led digitalWrite (led_granted, HIGH); Serial.println ("Card - Access Granted"); Serial.println (); delay (3000); digitalWrite(R1, LOW); digitalWrite (led_granted, LOW); } if (cont.substring (1) == "14 22 12 8A") // Test if the Card been read { Serial.println ("Card - Access Denied"); Serial.println (); for (int i = 1; i <5; i ++) // Flashing red LED { digitalWrite (led_denied, HIGH); delay (200); digitalWrite (led_denied, LOW); delay (200); } } delay (1000); } Download the MFRC522 Code Library Here | Zip |
Download the MFRC522 Code Library Here | Zip
i have an error. which is ‘Mfrc522’ was not declared in this scope..
how to solve this problem?
Hi, you need to import the MFRC522 Library which is can be downloaded at
> https://github.com/miguelbalboa/rfid
Step 1.
1. Goto Arduino library manage then type MFRC522
2. then Install
Other Step
1. Download the MFRC522 Library
2. Extract
3. Copy the folder and Goto My Documents / Arduino / Library and phase.
While uploading the codes to my arduino the error message is coming that mfrc522 was not declared. Can you please let me know the that what is the solution for that
cont was not declared in this scope… why?
how to use relay instead of Servo ?
See above sketch code for does who use a relay instead of servo.
Hey, thanks for the article, great illustrations! Just a little heads up, first illustration with just the RFID wiring, MISO should be Pin 12 :)
hi. i get the error ” error: ‘cont’ was not declared in this scope
if (cont.substring (1) == “7A E0 03 2F”) ”
how can I fix this?
So many typos – here’s the code corrected:
#include // Include SPI Bus
#include //Include MRFC522 Library
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522 (SS_PIN, RST_PIN); // Define pin module RC522
// Relay
int R1 = 4;
// LED indicators released or denied access
int led_granted = 6;
int led_denied = 7;
char st [20];
void setup ()
{
pinMode (led_granted, OUTPUT);
pinMode (led_denied, OUTPUT);
Serial.begin (9600) ; // Enable Serial at baud rate 9600
SPI.begin (); // Starts SPI bus Commnunication
mfrc522.PCD_Init (); // Starts MFRC522
Serial.println (“Initializing your card reader …”);
Serial.println ();
}
void loop ()
{
if (! mfrc522.PICC_IsNewCardPresent ()) // approximation of the card
{
return;
}
// Select one of the cards
if (! mfrc522.PICC_ReadCardSerial ())
{
return;
}
Serial.print (“UID Tag:”); // Display the UID serial
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) == "14 12 22 4A") // Test if the Card been read
{
digitalWrite(R1, HIGH); // Raises the gate and lights the green led
digitalWrite (led_granted, HIGH);
Serial.println ("Card – Access Granted");
Serial.println ();
delay (3000);
digitalWrite(R1, LOW);
digitalWrite (led_granted, LOW);
}
if (content.substring (1) == "14 22 12 8A") // Test if the Card been read
{
Serial.println ("Card – Access Denied");
Serial.println ();
for (int i = 1; i <5; i ++) // Flashing red LED
{
digitalWrite (led_denied, HIGH);
delay (200);
digitalWrite (led_denied, LOW);
delay (200);
}
}
delay (1000);
}
Thanks for sharing, this is a fantastic blog post.Really thank you!