Skip to content

Connecting 125Khz RFID module to arduino – Part 2

AHA Project RFID Part 2

In this tutorial we will see how we can recognize persons using our RFID reader.
Two LEDs will be added at the project in order to get some better user experience.
A "security line" will be also added. The concept of the "security line" is pretty simple.
If the line get's 5V (is HIGH) then arduino knows that the RFID reader is working correctly otherwise the RFID reader is broken (or the communication between arduino - RFID reader).
As always we will make an "object based" approach.
From the first article of RFID we can find the TAG IDs.
It is time to associate the TAG ID with the so called "Authorized Persons".
An authorized person is the owner of a Tag ID key.
So an authorized person is defined like this :

//Type definition of Authorized Person
typedef struct
  {  
     String Name;
     String Tag_ID;
  } Authorized_Person;

Let's see now the "house" definition.

The house has a "name"
It should test if the alarm is working or not (broken or not),
It should also know the state of the alarm (active [armed] or not)
Which authorized person visited the house lately
The Max_Duration_To_Exit_Home is the duration in ms to wait till an authorized person exits the house
Max_Duration_To_Enter_Home is the duration in ms that a person must be authorized otherwise the alarm starts.

//Type definition of House
typedef struct
  {  
     String Name;
     boolean Is_Alarm_System_OK; // True : alarm system not broken -- False : alarm system broken
     boolean Is_Alarm_Activated; // True : no-one in the house [armed] -- False : some authorized person in house 
     Authorized_Person Last_Authorized_Person;
     int Max_Duration_To_Exit_Home; // in ms 
     int Max_Duration_To_Enter_Home;  //in ms
  } House;

 

The definition of our variables and the pins is reported below.
We have to define :
How_Many_Authorized_Persons
Our array of the Authorized_Person
RFID_TX_Pin =2
Security_Pin = 3;
Green_Led_Pin = 4;
Red_Led_Pin = 5;

Notice the usage of the LEDs :
The green led -> deactivated alarm
The red led -> blinks for "Max_Duration_To_Exit_Home" and then stays red (alarm is activated)

//Authorized_Persons is an array of Authorized_Person type
const int How_Many_Authorized_Persons = 3;
Authorized_Person Authorized_Persons[How_Many_Authorized_Persons]; 

//House
House My_House;

//Define pins 
const int RFID_TX_Pin = 2;  // the TX pin that the RDIF Sensor is attached
const int Security_Pin = 3; // the pin that the security line wire is attached. If the security line breaks then the alarm system is considered broken.
const int Green_Led_Pin = 4; // the green led -> deactivated alarm
const int Red_Led_Pin = 5;   //the red led -> blinks for Max_Duration_To_Exit_Home and then stays red (alarm is activated)

//Vars for leds ...
unsigned long Current_Ms;
unsigned long Previous_Ms = 0;
long Red_Blink_Duration_Ms = 0; //How many time the RED LED blinks
int Red_Led_State = LOW;
long Red_Blink_Interval = 1000; // interval at which to blink (milliseconds). Only red led can blink !

Notice how from the definitions we gave we obtained a nice and clean code.
The better understanding a problem the better solve it.
We are ready to built our system into the breadboard.