Week 11 Embedded Networking and Communications

This week's assignment is about Embedded Networking and Communications. I am using an Arduino UNO to create an RFID Door Lock System.It’s a fun and secure way to unlock the door.

Learning Objectives

1 Introduction

πŸ’‘1.1 RFID

RFID uses electromagnetic waves in the radio frequency spectrum for communication and data transfer. RFID tags are used in many industries and we can find them in product tags from stores to security access cards. RFID tags can expedite the checkout and can be used for antitheft measures.

Components of an RFID System An RFID system typically consists of several main components, each playing a different role in the system.

1
Component Description
RFID Tag Used to store and transmit information.
RFID Reader Reads the data from the RFID tag by emitting radio waves. It communicates with a microcontroller or computer.
Antenna Transmits and receives radio waves between the RFID tag and reader, influencing the system's range and performance.
Middleware Software that manages and processes the data between the RFID system and application, facilitating communication with the database.
Software Used to process and manage the data from RFID tags and integrate it into applications (e.g., security, inventory management).
Database Stores the RFID tag information and related data, enabling real-time updates and retrieval of relevant data for processing.
Power Supply Provides necessary power for the RFID system, especially for active tags and readers.

πŸ“œ1.3 RC522 RFID

The RC522 RFID is a popular RFID reader/writer module that communicates with microcontrollers like Arduino. It uses the MFRC522 chip and supports reading and writing of 13.56 MHz RFID cards/tags.

1

RC522 RFID Module Pins and Descriptions

1
Pin Description
SDA / SCL I2C Communication pins: Data (SDA) and Clock (SCL).
SS / SCK / MOSI / MISO SPI Communication pins: Slave Select (SS), Clock (SCK), Master Out Slave In (MOSI), and Master In Slave Out (MISO).
RX / TX UART Communication pins for serial data transmission.
IRQ Interrupt signal from the module to indicate RFID tag detection.
GND Ground pin that needs to be connected to the GND pin on the Arduino.
RST Reset pin for the module.
VCC Supply pin for the module. The supply voltage ranges from 2.5V to 3.3V and must be connected to the 3.3V pin on the Arduino.
1

RC522 RFID Reader/Writer Module|Parts&Circuit Diagram

2 Circuit Setup

2.1 βš™οΈComponents

RFID Module & Arduino Uno Board & RFID Key Tag & Relay Module & I2C LCD1602 & Breadboard & Jumper Wires

2.2 Circuit Setup

2.2.1 RFID Module

RFID Module Arduino Uno
3.3V3.3V
GNDGND
RST2
SDA (SS)10
MOSI11
MISO12
SCK13
IRQ7

2.2.2 I2C LCD1602

I2C LCD1602 Arduino Uno
GNDGND
VCC5V
SDAA4
SCLA5

2.2.3 Relay Module

Relay Module Arduino Uno
SIG8
VCC5V
GNDGND
1

3 Reading an RFID Tag

3.1 Installing the MFRC522 Library

  1. βœ…Open Arduino IDE.
  2. βœ…Click Tools β†’ Manage Libraries (S+C+M)
  3. In the search bar, type: MFRC522.
  4. βœ…Find MFRC522 by GithubCommunity.
  5. βœ…Click the Install button.

Notes:Place the RFID key tag near the center of the reader

3.2 Test Code

1

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

#define SS_PIN 10
#define RST_PIN 2
MFRC522 rfid(SS_PIN, RST_PIN);

void setup() {
    Serial.begin(9600);
    SPI.begin();
    rfid.PCD_Init();
    Serial.println("Scan RFID Card...");
}

void loop() {
    if (!rfid.PICC_IsNewCardPresent()) {
        return;
    }
    if (!rfid.PICC_ReadCardSerial()) {
        return;
    }
    Serial.print("Card ID: ");
    for (byte i = 0; i < rfid.uid.size; i++) {
        Serial.print(rfid.uid.uidByte[i], HEX);
        Serial.print(" ");
    }
    Serial.println();
    rfid.PICC_HaltA();
}
    

3.3 Card ID

βœ… πŸ“‘ Serial Debugging: Viewing scanned card IDs in the Serial Monitor.

Card ID 1: 73 B2 63 D

Card ID 2: D3 E1 5C A3

1

πŸ“Œ RFID Serial Monitor Output & Troubleshooting

1 1
Serial Monitor Output Possible Issue Suggested Solution
⚠ ERROR: RFID module not detected Wiring issue or incorrect power supply ensure standard SPI pins and 3.3V power are used
No card detected No RFID card detected near reader Try a different RFID card, adjust scanning angle, or ensure the card is 13.56MHz.
Failed to read card Read failure due to card or hardware issue Try another card, adjust timing (add delay), or test another RFID module.
Card ID: xx xx xx xx Success πŸŽ‰ RFID card read successfully. Use this ID for verification logic.

4 RFID Door Lock System Code

1

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

#define SS_PIN 10
#define RST_PIN 2
#define RELAY_PIN 8

MFRC522 rfid(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte allowedUID[4] = {0x73, 0xB2, 0x63, 0xD};

void setup() {
    Serial.begin(9600);
    SPI.begin();
    rfid.PCD_Init();
    lcd.init();
    lcd.backlight();
    pinMode(RELAY_PIN, OUTPUT);
    digitalWrite(RELAY_PIN, LOW);
    lcd.setCursor(0, 0);
    lcd.print("Welcome !");
}

void loop() {
    if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) {
        return;
    }
    bool isAuthorized = true;
    for (byte i = 0; i < rfid.uid.size; i++) {
        if (rfid.uid.uidByte[i] != allowedUID[i]) {
            isAuthorized = false;
        }
    }
    if (isAuthorized) {
        digitalWrite(RELAY_PIN, HIGH);
        lcd.setCursor(0, 1);
        lcd.print("Welcome home !");
        delay(2000);
        digitalWrite(RELAY_PIN, LOW);
    } else {
        lcd.setCursor(0, 1);
        lcd.print("Unknown Guy !");
        delay(2000);
    }
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Welcome !");
    rfid.PICC_HaltA();
}
    

5 Compilation & Testing

Run Steps

1

Run Results

At the beginning, we can see "Welcome!" displayed on the I2C LCD1602.

Swipe Card 1, and the relay's normally open contact will activate. The LCD will display:

After two seconds, it will return to displaying "Welcome!".

Swipe Card 2, and if the ID is incorrect, the relay's normally open contact will deactivate. The LCD will display:

After two seconds, it will return to displaying "Welcome!".

6 Issues and Solutions

7 Conclusion

This project demonstrates how RFID technology can be used for access control. The combination of an RFID reader, LCD display, and relay allows for a secure and user-friendly door lock system.

Code01 for this week Code02 for this week

Upload and Run Arduino Program

Step-by-Step Guide:

  1. πŸ”Œ Connect the Arduino Board: Use a USB cable to connect the Arduino to computer.
  2. πŸ–₯ Open Arduino IDEArduino official website.
  3. βš™οΈ Select Board & Port:
    • Go to Tools β†’ Board and select your Arduino Uno.
    • Go to Tools β†’ Port and select the correct port COM5.
  4. πŸ“‹ Code: Open the code.
  5. βœ… Compile & Upload Code:
    • Click the βœ”οΈ (checkmark icon) to verify the code.
    • Click the ⬆️ (upload icon) to upload the code.
  6. πŸ“Ÿ Open Serial Monitor:
    • Go to Tools β†’ Serial Monitor .(shift+alt+M)
    • Set baud rate to 9600.
    • Check code