How to Use RFID Sensor with Arduino (Card + Tag)

In this tutorial, you will build a device that uses RFID detection to turn on an LED light. This application can be used, for example, to open a door with RFID control.

This is a tutorial suitable for learning in video format, if you prefer a more complete tutorial you can find it at this link!

Parts Required

  • Arduino
  • RC522 RFID Reader
  • Jumper wires
  • LED
  • Breadboard


Connect the LED light and resistor to the digital output pin 4 (as you can see in the following code).


#include <SPI.h>
#include <MFRC522.h> 

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above

#define LED_BUILTIN 4 // Configurable, set LED pin

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

void setup() {
  // initialize digital pin LED_BUILTIN as an output.

  Serial.begin(9600);   // Initialize serial communications with the PC
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522
  delay(4);       // Optional delay. Some board do need more time after init to be ready, see Readme
  mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
  Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));

void loop() {
  // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
  if ( ! mfrc522.PICC_IsNewCardPresent()) {

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {

  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second

  // Dump debug info about the card; PICC_HaltA() is automatically called

The code shown will turn the light on and off at 2-second intervals, if you want to put a button to control it just add a digital input.



Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!

Hello! We have noticed you are using an ad blocker. Our website is funded by advertising which allows you to access all our content for free. By disabling your ad blocker, you are contributing to the sustainability of our project and ensuring we continue to provide high-quality, useful tutorials. We appreciate your support!