Good day!
I am having a problem with saving registered RFID tags with date/time in an attendance-based project. My plan is to save the "Given name / ID# / DATE / TIME" when a registered RFID tag is tapped in. I was satisfied with what I got with the help of PLX-DAQ, but now I want to save the data on an SD card. However, I am encountering a problem after adding components for the SD module: it does not read any RFID when tapped. I looked online to see if anyone else has encountered this problem, and for a while, I read that adding a resistor to the MISO pin would work. It did work, but now what I am encountering is that it always prints out in the serial monitoring is "Tag is not enrolled." I already tried my other code with PLX-DAQ, and there seems to be no problem reading the IDs. additionally, tried testing the 2 components individually and both works fine.
I have connected the SCK, MOSI, and MISO of the SD module to the SCK, MOSI, and MISO of the RFID reader, and then added a resistor in the MISO connection to make the 2 components works.
Below is the code that should highlight my problem.
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
#define greenLED 2
#define redLED 7
RTC_DS3231 rtc;
MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 20, 4);
#define ENA 6
#define IN1 5
#define IN2 3
struct Person {
String name;
String id;
};
Person registeredPersons[] = {
{"Alice", "0736d01c"},
{"Victoria", "739588c1"},
{"Charlie", "f38484c1"},
{"David", "436979c1"},
{"Eve", "038076c1"},
{"Frank", "931873c1"},
{"Grace", "e3fe75c1"}
};
void setup() {
lcd.init();
lcd.backlight();
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("Waiting for RFID tag...");
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
digitalWrite(ENA, LOW);
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
DateTime now = rtc.now();
lcd.setCursor(0, 1);
lcd.print("Date:");
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.day(), DEC);
lcd.print("/");
lcd.print(now.year(), DEC);
lcd.setCursor(0, 2);
lcd.print("Time:");
lcd.print(now.hour(), DEC);
lcd.print(":");
lcd.print(now.minute(), DEC);
lcd.print(":");
lcd.print(now.second(), DEC);
if (now.hour() == 17 && now.minute() == 15 && now.second() == 0) { // Door (MOTOR) closing time
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
analogWrite(ENA, 255); // start motor at full speed
delay(5000); // run for 5 seconds
analogWrite(ENA, 0); // stop the motor
}
if (now.hour() == 17 && now.minute() == 17 && now.second() == 0) { // Door (MOTOR) opening time
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(ENA, 255); // start motor at full speed
delay(5000); // run for 5 seconds
analogWrite(ENA, 0); // stop the motor
}
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
String tagID = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
tagID.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : ""));
tagID.concat(String(mfrc522.uid.uidByte[i], HEX));
}
bool isEnrolled = false;
String name = "";
for (int i = 0; i < sizeof(registeredPersons)/sizeof(Person); i++) {
if (registeredPersons[i].id == tagID) {
isEnrolled = true;
name = registeredPersons[i].name;
Serial.print("RFID tag detected: ");
Serial.print(name);
Serial.print(" (");
Serial.print(tagID);
Serial.print(") - ");
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
// record the name, ID, date, and time in Excel
String data = "DATA," + name + "," + tagID + "," + now.month() + "/" + now.day() + "/" + now.year() + "," + now.hour() + ":" + now.minute() + ":" + now.second();
Serial.println(data);
break;
}
}
if (!isEnrolled) {
Serial.println("Tag is not enrolled.");
}
bool isLate = now.hour() >= 17 && now.minute() >= 15; // start of the late hour (change depending on the desired time)
bool isClosing = now.hour() >= 17 && now.minute() >= 17 && now.hour() < 6; // end time of late hour (change depending on the desired time)
lcd.setCursor(0, 0);
lcd.print("Name:");
lcd.print(name);
lcd.setCursor(0, 3);
lcd.print("Status:");
if (isLate) {
lcd.print("Late");
} else {
lcd.print(isEnrolled ? "Recorded" : "Not Enrolled"); // print "Not Enrolled" if RFID tag is not enrolled
}
digitalWrite(greenLED, isEnrolled && !isLate ? HIGH : LOW);
digitalWrite(redLED, isLate ? HIGH : LOW);
// check if it's time to spin the motor
if (isClosing && isEnrolled) {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(ENA, 255); // start motor at full speed
delay(3000); // wait for 3 seconds
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
analogWrite(ENA, 0); // stop the motor
} else if (isLate && !isClosing && isEnrolled) {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(ENA, 255); // start motor at full speed
delay(5000); // run for 5 seconds
analogWrite(ENA, 0); // stop the motor
delay(3000);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
analogWrite(ENA, 255); // start motor at full speed
delay(3000); // wait for 3 seconds
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
analogWrite(ENA, 0); // stop the motor
} else {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
analogWrite(ENA, 0); // stop the motor
}
delay(2000); // wait for 2 seconds
lcd.clear(); // clear the LCD display
mfrc522.PICC_HaltA();
} else {
digitalWrite(greenLED, LOW);
digitalWrite(redLED, LOW); // turn off the red LED
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
analogWrite(ENA, 0); // stop the motor
}
}
Schematic
sorry I can't find the right model for some parts but hopefully it could help.
RFID Reader:
https://circuit.rocks/nfc-rfid-reader-kit-13.56mhz
SD module:
https://shopee.ph/Micro-SD-Storage-Expansion-Board-Micro-SD-TF-Card-Memory-Shield-Module-SPI-For-Arduino-Promotion-i.498112208.12411193753?sp_atk=b78c7587-0f27-456f-9ec3-f14abe129824&xptdk=b78c7587-0f27-456f-9ec3-f14abe129824