OUTPUT DEVICES

LCD I2C DISPLAY

For this week's assignment i decided to use an lcd display and plug it to the board I have already design. The main idea was for it to display the readings of the soil moisture sensor that was used in Week 9

lcd

COMPONENTS USED

  • PCB (DESIGNED ON WEEK 6)
  • JUMPER WIRES
  • RFID READER
  • LCD I2C DISPLAY

For this assignment I connected the LCD I2C display to my board together with my RFID reader. This was to display the readings from the rfid into it. The LCD was connected to the board's I2C pins which are SDA and SCL.

lcdconnection

INSTALLING LC LIBRARY

After the connection of the hardware, I then launched Arduino IDE and then installed the LiquidCrystal_I2C library which is used to control the LCD I2C Display.

lcdlibrary

I then updated the RFID code by adding the LCD code to it, so that the rfid readings can be displayed in the LCD. The codes is as follows:


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

const int RST_PIN = D0;     // Reset pin
const int SS_PIN = D1;      // SDA 

#define I2C_ADDR 0x27  // LCD I2C address 
LiquidCrystal_I2C lcd(I2C_ADDR, 16, 2);

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance

void setup() {
  Serial.begin(9600);
  SPI.begin();          // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522

  // I2C pin config 
  Wire.setSDA(6);       // D4 
  Wire.setSCL(7);       // D5 
  Wire.begin();

  lcd.init();           // Initialize LCD
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Scan RFID tag...");
}

void loop() {
  // Check for new RFID card
  if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  // Create a string to hold the UID
  String uidString = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    if (mfrc522.uid.uidByte[i] < 0x10) {
      uidString += "0"; // Leading zero for single hex digits
    }
    uidString += String(mfrc522.uid.uidByte[i], HEX);
  }
  uidString.toUpperCase(); // Optional: make it uppercase

  // Print to Serial
  Serial.print("UID tag: ");
  Serial.println(uidString);

  // Print to LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("RFID UID:");
  lcd.setCursor(0, 1);
  lcd.print(uidString);

  delay(2000); // Display for 2 seconds before next scan
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Scan RFID tag...");

  mfrc522.PICC_HaltA(); // Halt PICC
}

							 

After uploading the code I then tested, the readings displayed on the lcd when I tapped the card on the rfid reader.

FILES

  • CODE