In this tutorial, you will build a device that uses RFID detection to turn on an LED light. This project provides an introduction to using RFID sensors to control responses with an Arduino.
Parts List
- Arduino Uno
- An RC522 RFID Reader, such as this one, or a similar RFID sensor (you will also want the RFID Card/Tag that comes with it)
- Wires (of various lengths and ends)
- An LED light bulb
- A 330 ohm resistor
Images of parts needed for this project. Clock-wise from top-left: Arduino Uno, resistor, wires of different types, RFID sensor and cards, LED light.
Circuit Diagram
Step 1: Connect the RFID Sensor to the Arduino
First, let’s get the RFID sensor component working.
Gather the parts listed in the parts list. Use wires to connect the RFID sensor to the Arduino Uno. Refer to the table and image below or the project circuit diagram for specifics on which pins to connect.
Source: https://www.youtube.com/watch?v=23aMjljCLZI
Note: If your RFID sensor does not come with pin headers, you may need to solder the pin headers to your sensor first.
Step 2: Test the RFID Sensor Functionality
Next, test that the RFID sensor is correctly wired and working as expected.
To do so, download the RFID library found here and add it to your Arduino libraries. You can also find some good additional information on purchasing and trouble-shooting problems with your RFID sensor on the linked GitHub page.
Find the DumpInfo example code by navigating to Examples > MFRC522 > DumpInfo.
Connect the Arduino Uno to your computer and upload the code.
Open the Serial Monitor by selecting the magnifying glass in the upper right hand corner of the sketch.
Now test the RFID sensor! As you bring an RFID Tag or Card close to the RFID reader, you should see the output on the Serial Monitor change.
Specifically, the Serial monitor shows the ID/UID, type and any data blocks the sensor can read from the Tag or Card.
Step 3: Add LED Light
Now let’s add the LED light.
Connect the LED light and resistor to the breadboard as shown in the circuit diagram.
Circuit diagram for connecting LED (left) and Image of completed circuit with RFID sensor and LED light (right)
Step 4: Upload and Run Code
Download or copy the below included code and open it in the Arduino IDE. This sketch is similar to the DumpInfo example sketch, but also turns on and off an LED light when the RFID Card is detected.
Move an RFID Tag or Card at reading distance of the RFID sensor. You should see the LED light blink once.
Note that the LED light is just one example of an output that could be controlled by the RFID sensor.
Many other actions could also be triggered by the RFID!
For example, try running a motor or making a sound based on the RFID detection. There are many possibilities!
/* Using an RFID sensor to blink an LED light
*
* Date: 4/11/20
*
* Description: This sketch uses an RFID sensor to blink an LED lightbulb.
* When you bring an RFID Tag or Card within reading distance of the sensor,
* the LED lightbulb will blink on and off once. The ssketch also prints the
* ID/UID, type and any data blocks it can read from the RFID Tag or Card to
* the serial monitor
*
* The sketch extends a MFRC522 library example;
* for further details and other examples see: https://github.com/miguelbalboa/rfid
*
*/
#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.
pinMode(LED_BUILTIN, 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()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
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
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
One reply on “Using an RFID sensor to blink an LED light”
Cant seem to get it to light up the external LED, i have the wires in the exact same config, tried other pins and configs, even another arduino. But cant seem to get it to light no matter what.