Monday, 8 September 2025

Exoeriment 9 (EM 18 Reader Module)

 //#include <SPI.h>

//#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
//MFRC522 rfid(SS_PIN, RST_PIN);

// Map each card UID to a name and add more cards as needed
String cardUIDs[] = { "1D000552D19B", "1D000858E7AA", "1D0006B8BD1E"}; // Replace with actual UIDs from EM-18
String cardNames[] = { "mahesh", "Charan","manikanta"};   // Replace with actual names

// Function to get the name associated with the UID
String getCardName(String uid) {
  for (int i = 0; i < sizeof(cardUIDs) / sizeof(cardUIDs[0]); i++) {
    if (uid == cardUIDs[i]) {
      return cardNames[i];
    }
  }
  return "Unknown";
}

void setup () {
  Serial.begin(9600); // Initialize serial communication with EM-18 (default 9600 baud)
  Serial.println("Scan your RFID card...");
}

void loop () {
  // Check if EM-18 sent data
  if (Serial.available() > 0) {
    String uid = Serial.readStringUntil('\n'); // Read UID until newline (EM-18 sends 12 chars + CR/LF)
    uid.trim();  // Remove spaces/newline characters

    String name = getCardName(uid);

    if (name != "Unknown") {
      Serial.print("Attendance Marked for: ");
      Serial.println(name);
    } else {
      Serial.print("Card not recognized: ");
      Serial.println(uid);
    }
  }
}

No comments:

Post a Comment