Week 11 Embedded Networking and Communications

This week, after learning I2C communication, I used my own PCB with a XIAO-ESP32-C3 (master) to communicate. It is connected to a computer to read serial input (keyboard 1 or 2) and control the LED connected to D7 on the Arduino (slave). I also used an Arduino UNO to create an RFID door lock system.

Learning Objectives

I used AI-assisted tools to help me learn and understand Embedded Networking and Communications, as well as I2C communication.

Group Assignment

1.1 Embedded Network and Communication

Refers to how these systems exchange information via wired or wireless networks to achieve collaboration and control.

1.2 Common Communication Methods

Type Common Protocol Features Applicable Scenarios
Wired UART Simple, point-to-point Direct communication between Arduino UNO, Xiao ESP32
I2C Supports multi-master/multi-slave, two-wire bus Multiple sensors, multi-slave control
SPI High-speed, full duplex Sensors, high-speed peripherals
Wireless Wi-Fi Long distance, Internet access Smart home, remote monitoring
Bluetooth/BLE Low power, short distance Mobile interaction, data synchronization
LoRa Ultra long distance, low speed IoT, sensor networks
Zigbee Self-organizing, low power Smart home, sensor networks

2.1 I2C Communication

I2C (Inter-Integrated Circuit) is a two-wire, synchronous, half-duplex, master-slave serial communication bus developed by Philips (now NXP).

2.2 I2C Physical Connection

Wire Function
SDA (Serial Data) Data line
SCL (Serial Clock) Clock line

2.3 I2C Roles: Master and Slave

3.1 I2C Communication Test with Two Arduino Uno

Master board: connected to computer, reads serial input (keyboard A or B), sends it via I2C to the slave.

Slave board: receives I2C message and controls onboard LED (D13) accordingly.

1

3.2 Upload Code

Step 1: Upload Slave code

1

Step 2: Upload Master code

1

3.3 Hardware Connection

Master UNO Slave UNO Note
A4 (SDA) A4 (SDA) I2C data line
A5 (SCL) A5 (SCL) I2C clock line
GND GND Common ground
5V 5V Power optional
1

3.4 Test

Press A on the keyboard → LED turns on;Press B on the keyboard → LED turns off.

1

video

Code01 for this week Code02 for this week

Individual Assignment

After learning I2C communication, I used my own PCB with a XIAO-ESP32-C3 (master) to communicate. It is connected to a computer to read serial input (keyboard 1 or 2) and control the LED connected to D7 on the Arduino (slave)

1.1 Upload Slave Code

LED connection

1

code

1

Serial output: I2C Slave Ready

1

1.2 Upload Master Code

1

code

1

The serial monitor shows: ESP-ROM: esp32c3-api1-20210207 I2C Master is ready. Press 1 to turn the LED ON, 2 to turn it OFF.

1

1.3 Hardware Connection

Signal ESP32-C3 Arduino Uno
SDA D6 SDA
SCL D7 SCL
GND GND GND
LED D7 → LED → GND
1

1.4 Test

Press 1 on the keyboard → LED turns on; Press 2 on the keyboard → LED turns off.

1

Video

Code03 for this week Code04 for this week

In an access control system, the RC522 module is used to detect RFID cards and read their UID. The node sends the UID to the master controller through a wired I2C connection. The master controller then parses the UID and instructs the display to record and show the information.

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

1

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 ToolsManage 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!".

video

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.

Code05 for this week Code06 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