RFID-based Attendance System using Raspberry Pi

Create an RFID-based attendance system using a Raspberry Pi, RC522 module, and an LCD display. This project scans RFID cards/tags to mark student or employee attendance and displays the status in real-time.

1. Introduction to RFID Attendance System

RFID (Radio Frequency Identification) is a wireless communication technology that uses electromagnetic fields to identify and track objects automatically. In this project, we use a Raspberry Pi along with an RC522 RFID module to scan RFID cards or tags. When a tag is scanned, it checks the UID against registered IDs, and if a match is found, attendance is marked and displayed on an LCD screen.

2. What You Need: Components and Tools

Required Components:

  • Raspberry Pi (any model with GPIO pins, preferably Pi 3 or Pi 4)
  • RC522 RFID Reader Module
  • RFID Cards/Tags
  • 16x2 LCD Display (I2C recommended)
  • Jumper Wires
  • Breadboard
  • Power Supply for Raspberry Pi

3. Working Principle of the RFID Attendance System

The RC522 RFID module communicates with the Raspberry Pi over the SPI interface to read the UID from the RFID card. Once the UID is read, the system checks it against a list of registered UIDs in a database or in the code itself. If a valid card is detected, the system updates the attendance and displays a confirmation message on the LCD.

4. Wiring Diagram: Raspberry Pi and RC522 RFID

RC522 to Raspberry Pi Connections (SPI):

  • SDA → Pin 24 (GPIO8)
  • SCK → Pin 23 (GPIO11)
  • MOSI → Pin 19 (GPIO10)
  • MISO → Pin 21 (GPIO9)
  • IRQ → Not Connected
  • GND → GND
  • RST → Pin 22 (GPIO25)
  • 3.3V → 3.3V

LCD (I2C) Connections:

  • VCC → 5V
  • GND → GND
  • SDA → Pin 3 (GPIO2)
  • SCL → Pin 5 (GPIO3)

5. Raspberry Pi Code for RFID Attendance System

  1. Install necessary libraries: `pip install mfrc522`, `pip install RPLCD`
  2. Then upload the following Python code:
import RPi.GPIO as GPIOfrom mfrc522 import SimpleMFRC522from time import sleepimport RPLCD.i2cfrom RPLCD.i2c import CharLCD# Set up GPIO pinsGPIO.setmode(GPIO.BCM)GPIO.setup(18, GPIO.OUT)# Initialize RFID readerreader = SimpleMFRC522()# Initialize LCDlcd = CharLCD('PCF8574', 0x27)lcd.clear()lcd.write_string('Scan RFID Card')# Pre-registered card UID list (use your own card UIDs)valid_cards = ['F3D4B21A', 'C729834B']def mark_attendance(uid):    if uid in valid_cards:        lcd.clear()        lcd.write_string('Access Granted!')        print(f'Access Granted for UID: {uid}')        GPIO.output(18, GPIO.HIGH)    else:        lcd.clear()        lcd.write_string('Access Denied!')        print(f'Access Denied for UID: {uid}')        GPIO.output(18, GPIO.LOW)    sleep(2)    lcd.clear()    lcd.write_string('Scan RFID Card')try:    while True:        print('Waiting for card...')        uid, text = reader.read()        mark_attendance(str(uid))except KeyboardInterrupt:    GPIO.cleanup()

6. Code Explanation

  • `SimpleMFRC522` is used to read the RFID tag data via SPI.
  • The `mark_attendance()` function compares the UID of the scanned card with a list of valid card UIDs.
  • If a match is found, 'Access Granted' is displayed on the LCD and an LED lights up.
  • If no match is found, 'Access Denied' is shown.

7. Applications

  • Automated attendance marking for schools and colleges
  • Employee attendance system
  • Access control in restricted areas
  • Inventory and library management systems

8. FAQs: RFID Attendance System on Raspberry Pi

Q: Why isn't my RFID module working?

A: Ensure that the module is properly connected and powered. Check the SPI configuration and ensure the correct GPIO pins are used.

Q: Can I store attendance data in a database?

A: Yes, you can store attendance in a database like MySQL or SQLite, or even send it to a cloud server using an API.

Q: Can I use this system for multiple users?

A: Yes, you can add more RFID cards to the `valid_cards` list or store user data in a database to scale the system.

9. Conclusion: What You’ve Learned

  • How to interface an RFID reader with a Raspberry Pi using SPI
  • How to read RFID card data and process it on a Raspberry Pi
  • Building a simple attendance system with an LCD display

10. Resources and References