Wiring help for RFID based attendance system


So, this is the circuit I've been working on, and I can't seem to make it work it is getting stuck in the Initialization of the SD card. I'd be grateful for your suggestion and help.

Here is the full code of it:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
char array1[]= "           ";
int tim = 500;
LiquidCrystal_I2C lcd(0x27, 16, 2);
 
#include <MFRC522.h> // for the RFID
#include <SPI.h> // for the RFID and SD card module
#include <SD.h> // for the SD card
#include <RTClib.h> // for the RTC
 
// define pins for RFID
#define CS_RFID 10
#define RST_RFID 9
// define select pin for SD card module
#define CS_SD 4 
 
// Create a file to store the data
File myFile;
 
// Instance of the class for RFID
MFRC522 rfid(CS_RFID, RST_RFID); 
 
Variable to hold the tag's UID

String uidString;
 
// Instance of the class for RTC
RTC_DS1307 rtc;
 
// Define check in time
const int checkInHour = 9;
const int checkInMinute = 5;
 
//Variable to hold user check in
int userCheckInHour;
int userCheckInMinute;
 
// Pins for LEDs and buzzer
const int redLED = 6;
const int greenLED = 7;
const int buzzer = 5;
 
void setup() {
  
  // Set LEDs and buzzer as outputs
  pinMode(redLED, OUTPUT);  
  pinMode(greenLED, OUTPUT);
  pinMode(buzzer, OUTPUT);

  lcd.init();  //initialize the lcd
  lcd.backlight();  //open the backlight 
  
  
  // Init Serial port
  Serial.begin(9600);
  lcd.begin(16,2);
  while(!Serial); // for Leonardo/Micro/Zero
  
  // Init SPI bus
  SPI.begin(); 
  // Init MFRC522 
  rfid.PCD_Init(); 
 
  // Setup for the SD card
  Serial.print("Initializing SD card...");
  lcd.print("Initializing ");
  lcd.setCursor(0, 1);
  lcd.print("SD card...");
  delay(3000);
  lcd.clear();
  if(!SD.begin(CS_SD)) {
    Serial.println("initialization failed!");
    lcd.print("Initializing ");
    lcd.setCursor(0, 1);
    lcd.print("failed!");
    return;
  }
  Serial.println("initialization done.");
  lcd.print("Initialization ");
  lcd.setCursor(0, 1);
  lcd.print("Done...");
 
  // Setup for the RTC  
  if(!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    lcd.clear();
    lcd.print("Couldn't find RTC");
    while(1);
  }
  else {
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
  if(!rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    lcd.clear();
    lcd.print("RTC Not Running!");
  }
}
 
void loop() {
  //look for new cards
  if(rfid.PICC_IsNewCardPresent()) {
    readRFID();
    logCard();
    verifyCheckIn();
  }
  delay(10);
}
 
void readRFID() {
  rfid.PICC_ReadCardSerial();
  lcd.clear();
  Serial.print("Tag UID: ");
  lcd.print("Tag UID: ");
  uidString = String(rfid.uid.uidByte[0]) + " " + String(rfid.uid.uidByte[1]) + " " + 
    String(rfid.uid.uidByte[2]) + " " + String(rfid.uid.uidByte[3]);
  Serial.println(uidString);
  lcd.setCursor(0, 1);
  lcd.print(uidString);
  delay(2000);
 
  // Sound the buzzer when a card is read
  tone(buzzer, 2000); 
  delay(200);        
  noTone(buzzer);
  
  delay(200);
}
 
void logCard() {
  // Enables SD card chip select pin
  digitalWrite(CS_SD,LOW);
  
  // Open file
  myFile=SD.open("DATA.txt", FILE_WRITE);
 
  // If the file opened ok, write to it
  if (myFile) {
    Serial.println("File opened ok");
    lcd.clear();
    lcd.print("File opened ok");
    delay(2000);
    myFile.print(uidString);
    myFile.print(", ");   
    
    // Save time on SD card
    DateTime now = rtc.now();
    myFile.print(now.year(), DEC);
    myFile.print('/');
    myFile.print(now.month(), DEC);
    myFile.print('/');
    myFile.print(now.day(), DEC);
    myFile.print(',');
    myFile.print(now.hour(), DEC);
    myFile.print(':');
    myFile.println(now.minute(), DEC);
    
    // Print time on Serial monitor
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.println(now.minute(), DEC);
    Serial.println("sucessfully written on SD card");
 
    lcd.clear();
    lcd.print(now.year(), DEC);
    lcd.print(':');
    lcd.print(now.month(), DEC);
    lcd.print(':');
    lcd.print(now.day(), DEC);
    lcd.print(' ');
    lcd.setCursor(11, 0);
    lcd.print(now.hour(), DEC);
    lcd.print(':');
    lcd.print(now.minute(), DEC);
    lcd.setCursor(0, 1);
    lcd.print("Written on SD...");
    delay(2000);
    
    myFile.close();
 
    // Save check in time;
    userCheckInHour = now.hour();
    userCheckInMinute = now.minute();
  }
  else {
    
    Serial.println("error opening data.txt");  
    lcd.clear();
    lcd.print("error opening data.txt");
  }
  // Disables SD card chip select pin  
  digitalWrite(CS_SD,HIGH);
}
 
void verifyCheckIn(){
  if((userCheckInHour < checkInHour)||((userCheckInHour==checkInHour) && (userCheckInMinute <= checkInMinute))){
    digitalWrite(greenLED, HIGH);
    delay(2000);
    digitalWrite(greenLED,LOW);
    Serial.println("You're welcome!");
    lcd.clear();
    lcd.print("You're Welcome!");
  }
  else{
    digitalWrite(redLED, HIGH);
    delay(2000);
    digitalWrite(redLED,LOW);
    Serial.println("You are late...");
    lcd.clear();
    lcd.print("You are Late...");
    delay(3000);
    lcd.clear();
    lcd.print("Put RFID to Scan");
    
  }
}

EDIT your original post, delete all the code, then put it back using CODE TAGS .

I don’t suggest cutting & pasting the existing code text, because it probably now has unwanted formatting characters inserted by the web renderer.

Please post the code properly in code tags </>

There's a lot going on in your circuit... have you been able to get the SD card working by itself?

Yes, I had a separate test for all of the components.

I also edited the codes now

Done editing sir

I already edited it sir

Just to be clear.. you get this message?

if(!SD.begin(CS_SD)) 
  {
    Serial.println("initialization failed!");

Can you please show how the SD card is connected to the Arduino. Do you have a schematic? (not the drawing above).

You've got both CS_RFID and CS_SD connected to pin 10.

No. The system gets stuck where the initialization of the SD card is done, and RFID is, I think, the one that is not working after that.

So I'm just gonna change it to both 10, and test if it will work?


This was my basis

No, you need to move one of the wires to another pin.

I'll try it sir

I'd suggest that you choose to move the CS_SD connection to the pin that the sketch is expecting it on.


Still not working, sir. It still gets stuck on this process, and RFID seems not working.

... bit hard to help when you don't explain the problem clearly ... but as @JohnLincoln said.. you should probably first check that your wiring matches the code.


This is what I mean. After this, there's no process at all. RFID seems to be not working to read RFID cards.

Did you do this @weightless_odd ... seems like some good advice.

Yes, I already did that. Nothing happens.

Post the new code & new wiring/schematic.