This project was developed in partnership with Robô Lúdico Schooland JLCPCB Factory that offers 5 free PCBs of Arduino Compatible Board.

Introduction

Radiofrequency identification or RFID (Radio - Frequency Identification) is a method of automatic identification through radio signals, retrieving, and storing data through RFID tags.

These RFID tags can be placed on animals, objects.

Thus, these labels have many applications such as the non-stop label placed on vehicles, animal identification.

There are 3 types of RFID tags: passive is tags that respond to the signal sent by the transmitter, semi-passive, and active tags that emit the signal itself.

There are currently several ways to control access to a location: using a fingerprint, keypad with a password, and using an RFID system.

In this article, we will learn how to develop an access control system using RFID technology.

This system will consist of the MFRC522 RFID module, a servo motor to open the door, a display to be the system's HMI, and signaling LEDs.

So in this article, we will learn how to develop an access control using an RFID module.

Therefore, through this article you will learn:

Now, we will start the complete presentation of the development of the parking access control system project using the RFID module.

Developing the parking access control system using the RFID Module with Arduino

The heart of this project is the RFID module, which consists of a printed circuit board with the MFRC522 integrated circuit and an antenna on the board.

When the board is energized, the module emits a radio frequency signal and when a tag approaches the module, the tag is read, each tag has a different code.

The module is powered by 3.3 V and it uses SPI (Serial Peripheral Interface) communication to communicate with the microcontroller used.

To develop this project the first step is to assemble the circuit in figure 1.

Parking.jpg

The operation of the circuit is quite simple! The Servo-Motor works as a mechanism for opening and closing the gate. Each time the tag is recognized by the RFID module, the Arduino sends the information to activate or close the gate.

The LCD is used to function as a communication interface with the user.

Next, we'll see how the programming logic for this project works.

The operating logic of the parking system control with Arduino

To program the Arduino Nano we will need the following libraries:

For this project, we'll use the JLCPCB Arduino Compatible printed circuit board presented below.

You can obtain the Arduino JLCPCB compatible PCB for your projects for $2 in your first order with the link: Earn my PCBs Arduino Compatible.

Use the JLC-RECE coupon, earn a $2 off discount, and earn 5 PCBs.

Access the link and download the Gerber files of the JLCPCB Arduino Compatible Printed Circuit Board.

The liquidCrystal_I2C and MFRC522 libraries are not installed in the Arduino IDE, so we will have to install them.

After installing the libraries, close the Arduino IDE and open it again.

The complete code is shown below.

/* * Teste Leitor RFID * tag 1 F1 B103 1F 241 17703 31
F1 B1 03 1F
 tag 2 14 45 29 57 20 69 41 87
14 45 29 57
 */

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

Servo myservo ;
LiquidCrystal_I2C lcd (0x27,2,1,0,4,5,6,7,3,POSITIVE);

#define vermelho 4
#define verde 5
#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522 (SS_PIN, RST_PIN);

void setup() {  Wire.begin();
  lcd.begin(16,2);  lcd.setBacklight(HIGH);  lcd.setCursor(0,0);  lcd.print("Aproxime a sua   ");  lcd.setCursor(0,1);  lcd.print("tag do leitor ");    pinMode(verde,OUTPUT);  pinMode(vermelho,OUTPUT);    Serial.begin(9600);  SPI.begin();  Serial.println("Aproxime a tag do leitor ");    mfrc522.PCD_Init();     digitalWrite(verde,0);  digitalWrite(vermelho,0);    myservo.attach(6);  }

void loop() {    if(!mfrc522.PICC_IsNewCardPresent())  {    return;  }    if(!mfrc522.PICC_ReadCardSerial())  {    return;  }
  Serial.print(" UID da tag : ");    String conteudo = "";    byte letra;    for (byte i = 0; i< mfrc522.uid.size; i++)  {   Serial.print(mfrc522.uid.uidByte[i] <0x10 ? "0":" ");   Serial.print(mfrc522.uid.uidByte[i], HEX);      conteudo.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));   conteudo.concat(String(mfrc522.uid.uidByte[i], HEX));  }    Serial.println();  Serial.print("Mensagem : ");    conteudo.toUpperCase();    if(conteudo.substring(1) == "14 45 29 57")  {    lcd.clear();    Serial.println("Acesso liberado ");      lcd.setBacklight(HIGH);    lcd.setCursor(0,0);    lcd.print("Ola !");    lcd.setCursor(0,1);    lcd.print("Acesso liberado");        digitalWrite(verde,1);    digitalWrite(vermelho,0);        myservo.write(95);    delay(800);    myservo.write(10);    digitalWrite(verde,0);    digitalWrite(vermelho,1);  }   if(conteudo.substring(1) == "F1 B1 03 1F")  {        lcd.clear();    Serial.println("Acesso negado ");    digitalWrite(verde,0);    digitalWrite(vermelho,1);        lcd.setBacklight(HIGH);    lcd.setCursor(0,0);    lcd.print("Erro ! Tag nao ");    lcd.setCursor(0,1);    lcd.print("autorizada ");      }      delay(1000);   lcd.clear();       lcd.setBacklight(HIGH);   lcd.setCursor(0,0);   lcd.print("Aproxime a sua  ");   lcd.setCursor(0,1);   lcd.print("tag do leitor ");
}

In the following, we will explain the complete logic for this project.

The first thing you need is to declare all libraries of the components used in your project.

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

After that, we declare the object of the servo motor and the LCD. The creation of the objects is presented below.

Servo myservo;
LiquidCrystal_I2C lcd (0x27,2,1,0,4,5,6,7,3,POSITIVE);
MFRC522 mfrc522 (SS_PIN, RST_PIN);

Now, we have the mapping of the connection pins on the Arduino.

#define vermelho 4
#define verde 5
#define SS_PIN 10
#define RST_PIN 9

Below is the void setup function. It initializes the I2C serial communication, serial communication, configures pins as output, and the pins where the servo motor is connected.

void setup() {
  Wire.begin();
  lcd.begin(16,2);  lcd.setBacklight(HIGH);  lcd.setCursor(0,0);  lcd.print("Aproxime a sua   ");  lcd.setCursor(0,1);  lcd.print("tag do leitor ");    pinMode(verde,OUTPUT);  pinMode(vermelho,OUTPUT);    Serial.begin(9600);  SPI.begin();  Serial.println("Aproxime a tag do leitor ");    mfrc522.PCD_Init();     digitalWrite(verde,0);  digitalWrite(vermelho,0);    myservo.attach(6);  }

Now let's understand how the complete programming logic works, which was implemented within the void loop function. See the void loop code below.

void loop() {    if(!mfrc522.PICC_IsNewCardPresent())  {    return;  }    if(!mfrc522.PICC_ReadCardSerial())  {    return;  }
  Serial.print(" UID da tag : ");    String conteudo = "";    byte letra;    for (byte i = 0; i< mfrc522.uid.size; i++)  {   Serial.print(mfrc522.uid.uidByte[i] <0x10 ? "0":" ");   Serial.print(mfrc522.uid.uidByte[i], HEX);      conteudo.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));   conteudo.concat(String(mfrc522.uid.uidByte[i], HEX));  }    Serial.println();  Serial.print("Mensagem : ");    conteudo.toUpperCase();    if(conteudo.substring(1) == "14 45 29 57")  {    lcd.clear();    Serial.println("Acesso liberado ");      lcd.setBacklight(HIGH);    lcd.setCursor(0,0);    lcd.print("Ola !");    lcd.setCursor(0,1);    lcd.print("Acesso liberado");        digitalWrite(verde,1);    digitalWrite(vermelho,0);        myservo.write(95);    delay(800);    myservo.write(10);    digitalWrite(verde,0);    digitalWrite(vermelho,1);  }   if(conteudo.substring(1) == "F1 B1 03 1F")  {        lcd.clear();    Serial.println("Acesso negado ");    digitalWrite(verde,0);    digitalWrite(vermelho,1);        lcd.setBacklight(HIGH);    lcd.setCursor(0,0);    lcd.print("Erro ! Tag nao ");    lcd.setCursor(0,1);    lcd.print("autorizada ");      }      delay(1000);   lcd.clear();       lcd.setBacklight(HIGH);   lcd.setCursor(0,0);   lcd.print("Aproxime a sua  ");   lcd.setCursor(0,1);   lcd.print("tag do leitor ");
}

The first thing you should do is check that there is no tag being detected and that no tag is being read. The code is shown below.

if(!mfrc522.PICC_IsNewCardPresent())  {    return;  }    if(!mfrc522.PICC_ReadCardSerial())  {    return;  }

After that, the system reads the tag and presents its value on the IDE Arduino serial monitor. See the code portion below.

Serial.print(" UID da tag : ");    String conteudo = "";    byte letra;    for (byte i = 0; i< mfrc522.uid.size; i++)  {   Serial.print(mfrc522.uid.uidByte[i] <0x10 ? "0":" ");   Serial.print(mfrc522.uid.uidByte[i], HEX);      conteudo.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));   conteudo.concat(String(mfrc522.uid.uidByte[i], HEX));  }    Serial.println();  Serial.print("Mensagem : ");    conteudo.toUpperCase();

Após a apresentação do código da tag, o sistema compara o valor da tag com um valor em hexadecimal cadastrado no sistema.

if(conteudo.substring(1) == "14 45 29 57")  {
    lcd.clear();    Serial.println("Acesso liberado ");      lcd.setBacklight(HIGH);    lcd.setCursor(0,0);    lcd.print("Ola !");    lcd.setCursor(0,1);    lcd.print("Acesso liberado");        digitalWrite(verde,1);    digitalWrite(vermelho,0);        myservo.write(95);    delay(800);    myservo.write(10);    digitalWrite(verde,0);    digitalWrite(vermelho,1);
  }

The commands of the condition above will be executed if the tag value is equal to 14 45 29 57. Among these commands, the LCD will print the access message and activate the servo motor to open the entrance gate.

If the tag value is equal to the F1 B1 03 1F value, the code flow enters the condition and displays the message "Tag not authorized!" and does not trigger the servo motor to release access.

The code portion is shown below.

if(conteudo.substring(1) == "F1 B1 03 1F")  {        lcd.clear();    Serial.println("Acesso negado ");    digitalWrite(verde,0);    digitalWrite(vermelho,1);        lcd.setBacklight(HIGH);    lcd.setCursor(0,0);    lcd.print("Erro ! Tag nao ");    lcd.setCursor(0,1);    lcd.print("autorizada ");      }

Finally, the system cleans the LCD screen and displays the message for the user to bring the tag closer to the RFID reader. The code region is shown below.

delay(1000);   lcd.clear();       lcd.setBacklight(HIGH);   lcd.setCursor(0,0);   lcd.print("Aproxime a sua  ");   lcd.setCursor(0,1);   lcd.print("tag do leitor ");

Now, we will see the result of the code working with the circuit on our bench.

After programming the Arduino Uno we will have the system working.

In figure 2 we have the initial message of the system asking the user to approach the tag to release access.

cancela1.gif

In figure 3 we have the user using a correct tag to allow access, then the green led turns on and activates the servo motor, and access is displayed on the display.

After 800 ms the servo motor returns to the initial position and the green led goes out and the red one lights up.

cancela2.gif

In figure 4 the user used an unregistered tag, so the system gives an error and does not release access.

cancela3.gif

After that, the system restarts the programming logic operating cycle.

Conclusion and Future project improvements

Systems that use RFID technology are applied in several types of projects. They are not limited, only, to control and access systems. A very common application is to use it to identify batches of clothing and other goods, for example.

Use your creativity and you will find different types of applications for your projects with the RFID module with Arduino.

In the future, we will create the prototype of a gate system with Arduino for you to set up your parking lot in practice with the use of a laser cutting machine or 3D printer.

Acknowledgments

We thank the company JLCPCB - Printed Circuit Board Factory and Robô Lúdico School for the support and partnership in the development of this project.

We thank the Robô Lúdico School in Brazil to create several projects and courses about robotics and Arduino.

We leave a link for you to purchase your printed circuit boards for a value of $ 2 through that link. Use the JLC-RECE coupon, earn a $2 off discount, and earn 5 PCBs.