0:00
Did you know that RFID technology is used in everything from access control systems
0:07
to inventory management? Today I'll show you exactly how to use an RFID RC 522 module with Arduino
0:14
Here's what we need an Arduino board, an RFIDRC 522 module. A couple of LEDs, 220 om resistors for the LEDs, some jumper wires
0:24
First we need to connect the RFID module to the Arduino. The connections are simple
0:28
SDA pin goes to Arduino. Pin 10, SCK to pin 13, M-O-S-I to pin 11, M-I-S-O to pin 12, R-S-T pin to pin 9, V-C-C to 3.3 volts on the Arduino, and G-N-D, connect the LEDs to digital pins 2 and 7 respectively
0:45
Now let's assemble it all together. Once everything's wired up, let's move on to the code
1:45
This is the code we'll be using for the project. Before we dive into the code, you need to install the MFRC 522 library
1:52
I will post the link to this library in the description. Now let's break down the key lines of the code that make this project work
1:58
Here, we're defining the pins that connect the RFID module to the Arduino
2:02
The SS underscore pin is connected to pin 10 and the RST underscore pin is connected to pin 9
2:07
These pins are important because they allow the Arduino to communicate with the RFID module
2:12
Next we create an instance of the MFRC 5 class which handles the RFID module This instance MyRFID is what we use to interact with the RFID reader throughout the code Here we setting up two LEDs one on pin two and another on pin seven
2:27
These will help us visually indicate whether access is granted or denied
2:31
Next, in the setup function, we initialize everything. Here, we initialize serial communication so we can monitor output in the serial monitor
2:39
Then we start the SPI communication bus, which allows the Arduino to talk to the RFID module
2:43
The PCD underscore init function sets up the RFID module and prepares it to scan cards
2:48
The loop function is where the magic happens. This part of the code continuously checks for RFID cards
2:54
This checks if a new RFID card is near the reader. If no card is present, it simply returns and waits
2:59
When a card is scanned, we light up the first LED as an indicator and print the card's unique ID in the serial monitor
3:05
Now let's see what happens when the scan cards UID is processed. This part of the code loops through the bytes of the cards UID or unique identifier and to
3:13
displays it in the serial monitor. This is the ID we'll use to determine whether access is granted or denied
3:18
Finally we check the UID of the card against a preset value If the UID matches the one in the code we grant access by lighting up the second LED and printing access granted If the UID doesn match we deny access Let see the RFID module in action As I placed this RFID tag near the reader watch the first LED
3:48
The first LED lights up showing that the tag has been scanned and the tag's unique identifier is displayed in the
3:53
the serial monitor. This confirms that the module has read the tag and is communicating with the Arduino
3:58
Now let's check the access control. If the tag matches the programmed ID, the second LED will turn on
4:04
As you can see, access is granted and the second LED lights up. When I remove the tag, the second LED turns off
4:10
showing that access has ended. Let's try a different tag now. The first LED still lights up, but watch
4:15
what happens. No access is granted so the second LED stays off. The serial monitor shows the
4:21
tag's unique ID, but since it doesn't match our access list, it's denied. If you found this tutorial
4:26
helpful, give it a thumbs up and share it with others who are getting started with Arduino. Be sure
4:30
to subscribe for more tutorials like this and let me know in the comments what projects you'd
4:34
like to see next. See you in the next video and happy coding