> For the complete documentation index, see [llms.txt](https://htooaunklinn-organization.gitbook.io/htooaunklinn-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://htooaunklinn-organization.gitbook.io/htooaunklinn-docs/hardware-and-iot/arduino-on-macos/mini-project-1.md).

# Mini Project 1

<figure><img src="/files/avG2EnmVBiBW2WOLEJw4" alt="" width="375"><figcaption></figcaption></figure>

**RFID RC522 Module (SPI)**

| RFID Pin     | Arduino Pin |
| ------------ | ----------- |
| **SDA (SS)** | **10**      |
| **SCK**      | **13**      |
| **MOSI**     | **11**      |
| **MISO**     | **12**      |
| **GND**      | **GND**     |
| **RST**      | **9**       |
| **3.3V**     | **3.3V**    |

**16x2 LCD (Using 4-bit Mode)**

| LCD Pin        | New Arduino Pin                        |
| -------------- | -------------------------------------- |
| **VSS**        | **GND**                                |
| **VDD**        | **5V**                                 |
| **V0**         | **(Potentiometer - Contrast Control)** |
| **RS**         | **7**                                  |
| **RW**         | **GND**                                |
| **E (Enable)** | **6**                                  |
| **D4**         | **5**                                  |
| **D5**         | **4**                                  |
| **D6**         | **3**                                  |
| **D7**         | **2**                                  |
| **A**          | **5V**                                 |
| **K**          | **GND**                                |

```cpp
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>

#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);

// Initialize the LCD with new separate pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup() {
  Serial.begin(9600);
  Serial.println("System Initialized");

  SPI.begin();
  mfrc522.PCD_Init();

  lcd.begin(16, 2);
  lcd.print("Place your card");
  Serial.println("Waiting for card...");
}

void loop() {
  if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  Serial.println("Card detected!");

  // Clear the LCD and prepare to display the UID
  lcd.clear();
  lcd.print("UID: ");

  Serial.print("UID tag: ");
  String uidString = "";

  for (byte i = 0; i < mfrc522.uid.size; i++) {
    // Convert byte to HEX without spaces
    if (mfrc522.uid.uidByte[i] < 0x10) {
      uidString += "0";  // Add leading zero for single-digit hex values
    }
    uidString += String(mfrc522.uid.uidByte[i], HEX);
  }

  // Convert to uppercase for better readability
  uidString.toUpperCase();

  // Print UID to Serial Monitor and LCD
  Serial.println(uidString);
  lcd.print(uidString);

  Serial.println("UID displayed on LCD.");

  mfrc522.PICC_HaltA();
  Serial.println("Waiting for next card...");
}
```
