Hi there; I would like to get support from you for a problem that happened to me for the first time about the software I developed. I made an RFID logger. I used the RC522 module as an RFID reader. I can detect the current time with the DS3231 RTC module. Finally, I used the SD card module. The operation of the algorithm firstly the user reads his own RFID card. Then, when he reads the RFID card of the door, the current date and time information is recorded on the SD card. The system I developed works. I share the software below.
#include <Arduino.h>
#include <SPI.h>
#include <MFRC522.h>
#include <uRTCLib.h>
#include <SD.h>
#define RFID_RST_PIN 9
#define RFID_SS_PIN 10
#define SD_SS_PIN 4
#define BLUE_LED_PIN 3
#define RED_LED_PIN 5
#define GREEN_LED_PIN 6
#define BUTTON_PIN 7
#define BUZZER_PIN 8
void RFID_READER();
void DATE_TIME();
void SAVE_LOG();
void TRANSFER_LOG();
void CREATE_NEW_FILE();
MFRC522 rfid(RFID_SS_PIN, RFID_RST_PIN);
byte ID_1[4] = {0x9D, 0x3A, 0x4F, 0x31};
byte ID_2[4] = {0xEA, 0x0E, 0xC9, 0x9E};
byte ID_3[4] = {0xBA, 0xD9, 0xC6, 0x9E};
byte ID_4[4] = {0x6A, 0x64, 0xB1, 0x15};
byte ID_5[4] = {0xFA, 0x58, 0xC1, 0x9E};
byte ID_6[4] = {0x3A, 0xCF, 0xBE, 0x9E};
byte ID_7[4] = {0xBA, 0x3A, 0x60, 0x9F};
byte securityID_1[4] = {0x7A, 0xB2, 0x65, 0x9F};
byte securityID_2[4] = {0x9A, 0x94, 0x55, 0x9F};
byte securityID_3[4] = {0xBA, 0xA5, 0x5A, 0x9F};
byte securityID_4[4] = {0x5A, 0x85, 0x6B, 0x9F};
byte securityID_5[4] = {0xEA, 0xEC, 0x8B, 0x9E};
byte securityID_6[4] = {0x8A, 0x5C, 0x80, 0x9E};
byte securityID_7[4] = {0x0A, 0x62, 0x8E, 0x9E};
byte securityID_8[4] = {0x3A, 0xB1, 0x6D, 0x6C};
byte securityID_9[4] = {0x7A, 0x88, 0x75, 0x6C};
byte securityID_10[4] = {0xCA, 0x7C, 0x72, 0x6C};
byte securityID_11[4] = {0xAA, 0x38, 0x73, 0x6C};
byte securityID_12[4] = {0x3A, 0xC6, 0x73, 0x6C};
byte securityID_13[4] = {0xEA, 0x31, 0x6B, 0x6C};
byte securityID_14[4] = {0x8A, 0x85, 0x4D, 0xA0};
byte adminID_1[4] = {0x8A, 0x15, 0x7D, 0x9E};
uRTCLib rtc(0x68);
char daysOfWeek[7][12] = {"Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi", "Pazar"};
int buttonState, voltageValue;
String gate, securityName, currentDay, currentMonth, currentYear, currentHour, currentMinute, currentSecond;
String fileName = "MERKEZ.txt";
char bufferDay[20], bufferMonth[20], bufferYear[20], bufferHour[20], bufferMinute[20], bufferSecond[20];
bool logTime = false;
bool securityCardPressed = false;
bool adminLogin = false;
File myFile;
void setup()
{
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT);
pinMode(BLUE_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
SPI.begin();
rfid.PCD_Init();
URTCLIB_WIRE.begin();
SD.begin(SD_SS_PIN);
//rtc.set(0, 7, 17, 2, 15, 8, 23); //Saati kalibra ederken (Saniye, Dakika, Saat, Gün Adı, Gün Tarihi, Ay, Yıl)
DATE_TIME();
for (int i = 0; i < 3; i++)
{
digitalWrite(GREEN_LED_PIN, HIGH);
delay(250);
digitalWrite(GREEN_LED_PIN, LOW);
delay(250);
}
// CREATE_NEW_FILE();
}
void loop()
{
//rtc.refresh();
RFID_READER();
SAVE_LOG();
TRANSFER_LOG();
}
void RFID_READER()
{
if ((securityCardPressed == false) && (adminLogin == false))
{
digitalWrite(RFID_SS_PIN, LOW);
digitalWrite(SD_SS_PIN, HIGH);
if (!rfid.PICC_IsNewCardPresent()) // Yeni Kartın Okunmasını Bekle
{
return;
}
if (!rfid.PICC_ReadCardSerial()) // Kart Okunmadığı Zaman Bekle
{
return;
}
if ((rfid.uid.uidByte[0] == securityID_1[0]) && (rfid.uid.uidByte[1] == securityID_1[1]) && (rfid.uid.uidByte[2] == securityID_1[2]) && (rfid.uid.uidByte[3] == securityID_1[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G1";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_2[0]) && (rfid.uid.uidByte[1] == securityID_2[1]) && (rfid.uid.uidByte[2] == securityID_2[2]) && (rfid.uid.uidByte[3] == securityID_2[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G2";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_3[0]) && (rfid.uid.uidByte[1] == securityID_3[1]) && (rfid.uid.uidByte[2] == securityID_3[2]) && (rfid.uid.uidByte[3] == securityID_3[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G3";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_4[0]) && (rfid.uid.uidByte[1] == securityID_4[1]) && (rfid.uid.uidByte[2] == securityID_4[2]) && (rfid.uid.uidByte[3] == securityID_4[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G4";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_5[0]) && (rfid.uid.uidByte[1] == securityID_5[1]) && (rfid.uid.uidByte[2] == securityID_5[2]) && (rfid.uid.uidByte[3] == securityID_5[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G5";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_6[0]) && (rfid.uid.uidByte[1] == securityID_6[1]) && (rfid.uid.uidByte[2] == securityID_6[2]) && (rfid.uid.uidByte[3] == securityID_6[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G6";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_7[0]) && (rfid.uid.uidByte[1] == securityID_7[1]) && (rfid.uid.uidByte[2] == securityID_7[2]) && (rfid.uid.uidByte[3] == securityID_7[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G7";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_8[0]) && (rfid.uid.uidByte[1] == securityID_8[1]) && (rfid.uid.uidByte[2] == securityID_8[2]) && (rfid.uid.uidByte[3] == securityID_8[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G8";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_9[0]) && (rfid.uid.uidByte[1] == securityID_9[1]) && (rfid.uid.uidByte[2] == securityID_9[2]) && (rfid.uid.uidByte[3] == securityID_9[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G9";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_10[0]) && (rfid.uid.uidByte[1] == securityID_10[1]) && (rfid.uid.uidByte[2] == securityID_10[2]) && (rfid.uid.uidByte[3] == securityID_10[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G10";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_11[0]) && (rfid.uid.uidByte[1] == securityID_11[1]) && (rfid.uid.uidByte[2] == securityID_11[2]) && (rfid.uid.uidByte[3] == securityID_11[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G11";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_12[0]) && (rfid.uid.uidByte[1] == securityID_12[1]) && (rfid.uid.uidByte[2] == securityID_12[2]) && (rfid.uid.uidByte[3] == securityID_12[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G12";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_13[0]) && (rfid.uid.uidByte[1] == securityID_13[1]) && (rfid.uid.uidByte[2] == securityID_13[2]) && (rfid.uid.uidByte[3] == securityID_13[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G13";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == securityID_14[0]) && (rfid.uid.uidByte[1] == securityID_14[1]) && (rfid.uid.uidByte[2] == securityID_14[2]) && (rfid.uid.uidByte[3] == securityID_14[3]))
{
digitalWrite(BLUE_LED_PIN, HIGH);
delay(200);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
securityName = "G14";
securityCardPressed = true;
}
else if ((rfid.uid.uidByte[0] == adminID_1[0]) && (rfid.uid.uidByte[1] == adminID_1[1]) && (rfid.uid.uidByte[2] == adminID_1[2]) && (rfid.uid.uidByte[3] == adminID_1[3]))
{
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(GREEN_LED_PIN, HIGH);
delay(200);
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
delay(50);
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
adminLogin = true;
}
else
{
Serial.println("Access denied");
Serial.print("ID Number: ");
for (int j = 0; j < 4; j++)
{
Serial.print(rfid.uid.uidByte[j], HEX);
Serial.print(" ");
}
Serial.println();
digitalWrite(RED_LED_PIN, HIGH);
delay(250);
digitalWrite(RED_LED_PIN, LOW);
}
rfid.PICC_HaltA();
}
if ((logTime == false) && (securityCardPressed == true))
{
digitalWrite(RFID_SS_PIN, LOW);
digitalWrite(SD_SS_PIN, HIGH);
if (!rfid.PICC_IsNewCardPresent()) // Yeni Kartın Okunmasını Bekle
{
return;
}
if (!rfid.PICC_ReadCardSerial()) // Kart Okunmadığı Zaman Bekle
{
return;
}
if ((rfid.uid.uidByte[0] == ID_1[0]) && (rfid.uid.uidByte[1] == ID_1[1]) && (rfid.uid.uidByte[2] == ID_1[2]) && (rfid.uid.uidByte[3] == ID_1[3]))
{
Serial.println("Authorized access");
Serial.print("ID Number: ");
for (int i = 0; i < 4; i++)
{
Serial.print(rfid.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
DATE_TIME();
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(GREEN_LED_PIN, HIGH);
delay(200);
digitalWrite(GREEN_LED_PIN, LOW);
gate = "K1";
logTime = true;
}
else if ((rfid.uid.uidByte[0] == ID_2[0]) && (rfid.uid.uidByte[1] == ID_2[1]) && (rfid.uid.uidByte[2] == ID_2[2]) && (rfid.uid.uidByte[3] == ID_2[3]))
{
Serial.println("Authorized access");
Serial.print("ID Number: ");
for (int i = 0; i < 4; i++)
{
Serial.print(rfid.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
DATE_TIME();
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(GREEN_LED_PIN, HIGH);
delay(200);
digitalWrite(GREEN_LED_PIN, LOW);
gate = "K2";
logTime = true;
}
else if ((rfid.uid.uidByte[0] == ID_3[0]) && (rfid.uid.uidByte[1] == ID_3[1]) && (rfid.uid.uidByte[2] == ID_3[2]) && (rfid.uid.uidByte[3] == ID_3[3]))
{
Serial.println("Authorized access");
Serial.print("ID Number: ");
for (int i = 0; i < 4; i++)
{
Serial.print(rfid.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
DATE_TIME();
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(GREEN_LED_PIN, HIGH);
delay(200);
digitalWrite(GREEN_LED_PIN, LOW);
gate = "K3";
logTime = true;
}
else if ((rfid.uid.uidByte[0] == ID_4[0]) && (rfid.uid.uidByte[1] == ID_4[1]) && (rfid.uid.uidByte[2] == ID_4[2]) && (rfid.uid.uidByte[3] == ID_4[3]))
{
Serial.println("Authorized access");
Serial.print("ID Number: ");
for (int i = 0; i < 4; i++)
{
Serial.print(rfid.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
DATE_TIME();
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(GREEN_LED_PIN, HIGH);
delay(200);
digitalWrite(GREEN_LED_PIN, LOW);
gate = "K4";
logTime = true;
}
else if ((rfid.uid.uidByte[0] == ID_5[0]) && (rfid.uid.uidByte[1] == ID_5[1]) && (rfid.uid.uidByte[2] == ID_5[2]) && (rfid.uid.uidByte[3] == ID_5[3]))
{
Serial.println("Authorized access");
Serial.print("ID Number: ");
for (int i = 0; i < 4; i++)
{
Serial.print(rfid.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
DATE_TIME();
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(GREEN_LED_PIN, HIGH);
delay(200);
digitalWrite(GREEN_LED_PIN, LOW);
gate = "K5";
logTime = true;
}
else if ((rfid.uid.uidByte[0] == ID_6[0]) && (rfid.uid.uidByte[1] == ID_6[1]) && (rfid.uid.uidByte[2] == ID_6[2]) && (rfid.uid.uidByte[3] == ID_6[3]))
{
Serial.println("Authorized access");
Serial.print("ID Number: ");
for (int i = 0; i < 4; i++)
{
Serial.print(rfid.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
DATE_TIME();
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(GREEN_LED_PIN, HIGH);
delay(200);
digitalWrite(GREEN_LED_PIN, LOW);
gate = "K6";
logTime = true;
}
else if ((rfid.uid.uidByte[0] == ID_7[0]) && (rfid.uid.uidByte[1] == ID_7[1]) && (rfid.uid.uidByte[2] == ID_7[2]) && (rfid.uid.uidByte[3] == ID_7[3]))
{
Serial.println("Authorized access");
Serial.print("ID Number: ");
for (int i = 0; i < 4; i++)
{
Serial.print(rfid.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
DATE_TIME();
digitalWrite(BUZZER_PIN, HIGH);
delay(50);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(GREEN_LED_PIN, HIGH);
delay(200);
digitalWrite(GREEN_LED_PIN, LOW);
gate = "K7";
logTime = true;
}
else
{
Serial.println("Access denied");
Serial.print("ID Number: ");
for (int j = 0; j < 4; j++)
{
Serial.print(rfid.uid.uidByte[j], HEX);
Serial.print(" ");
}
Serial.println();
digitalWrite(RED_LED_PIN, HIGH);
delay(250);
digitalWrite(RED_LED_PIN, LOW);
}
rfid.PICC_HaltA(); // Kart 1 Kere Okunduktan Sonra Bekle
}
}
void DATE_TIME()
{
rtc.refresh();
currentDay = (rtc.day() < 10) ? "0" + String(rtc.day()) : String(rtc.day());
currentMonth = (rtc.month() < 10) ? "0" + String(rtc.month()) : String(rtc.month());
currentYear = String(rtc.year());
currentHour = (rtc.hour() < 10) ? "0" + String(rtc.hour()) : String(rtc.hour());
currentMinute = (rtc.minute() < 10) ? "0" + String(rtc.minute()) : String(rtc.minute());
currentSecond = (rtc.second() < 10) ? "0" + String(rtc.second()) : String(rtc.second());
// if ((rtc.day() == 1) && (rtc.hour() == 0) && (rtc.minute() == 0))
// {
// CREATE_NEW_FILE();
// }
}
void SAVE_LOG()
{
if (logTime == true)
{
digitalWrite(RFID_SS_PIN, HIGH);
digitalWrite(SD_SS_PIN, LOW);
SD.begin(SD_SS_PIN);
myFile = SD.open(fileName, FILE_WRITE);
if (myFile)
{
myFile.print(securityName);
myFile.print("_");
myFile.print(gate);
myFile.print("_");
myFile.print(currentDay);
myFile.print(".");
myFile.print(currentMonth);
myFile.print(".");
myFile.print(currentYear);
myFile.print("_");
myFile.print(currentHour);
myFile.print(":");
myFile.print(currentMinute);
myFile.print(":");
myFile.println(currentSecond);
if (gate == "K7")
{
myFile.println("**********");
}
Serial.print(securityName);
Serial.print(": ");
Serial.print(gate);
Serial.print(" => ");
Serial.print(currentDay);
Serial.print('/');
Serial.print(currentMonth);
Serial.print('/');
Serial.print(currentYear);
Serial.print(" (");
Serial.print(daysOfWeek[rtc.dayOfWeek() - 1]);
Serial.print(") ");
Serial.print(currentHour);
Serial.print(':');
Serial.print(currentMinute);
Serial.print(':');
Serial.println(currentSecond);
Serial.println("------------------------------------------------------------");
logTime = false;
securityCardPressed = false;
}
else
{
for (int i = 0; i < 3; i++)
{
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH);
delay(250);
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
delay(250);
}
logTime = false;
securityCardPressed = false;
}
myFile.close();
}
}
void TRANSFER_LOG()
{
if (Serial.available())
{
char serialData = Serial.read();
if (serialData == 'r')
{
adminLogin = true;
}
}
if (adminLogin == true)
{
SD.begin(SD_SS_PIN);
digitalWrite(RFID_SS_PIN, HIGH);
digitalWrite(SD_SS_PIN, LOW);
myFile = SD.open(fileName);
if (myFile)
{
while (myFile.available())
{
Serial.write(myFile.read());
digitalWrite(BLUE_LED_PIN, HIGH);
digitalWrite(RED_LED_PIN, HIGH);
}
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(RED_LED_PIN, LOW);
myFile.close();
adminLogin = false;
}
// buttonState = digitalRead(BUTTON_PIN);
// if (buttonState == 1)
// {
// adminLogin = true;
// }
// if ((buttonState == 0) && (adminLogin == true))
// {
// SD.begin(SD_SS_PIN);
// digitalWrite(RFID_SS_PIN, HIGH);
// digitalWrite(SD_SS_PIN, LOW);
// myFile = SD.open(fileName);
// if (myFile)
// {
// while (myFile.available())
// {
// Serial.write(myFile.read());
// digitalWrite(BLUE_LED_PIN, HIGH);
// digitalWrite(RED_LED_PIN, HIGH);
// }
// digitalWrite(BLUE_LED_PIN, LOW);
// digitalWrite(RED_LED_PIN, LOW);
// myFile.close();
// adminLogin = false;
// }
else
{
Serial.println("HATA");
}
}
}
// void CREATE_NEW_FILE()
// {
// SD.begin(SD_SS_PIN);
// digitalWrite(RFID_SS_PIN, HIGH);
// digitalWrite(SD_SS_PIN, LOW);
// if (SD.exists(fileName))
// {
// myFile.close();
// }
// fileName = "20" + currentYear + "_" + currentMonth + ".txt";
// myFile = SD.open(fileName, FILE_WRITE);
// delay(100);
// myFile.close();
// }
My problem is as follows, when I disconnect the power of the arduino and reconnect it, the system does not work. By the way, I connect the arduino to the PC with a cable. When I reinstall the software on the arduino, the system starts working. When I disconnect the power of the arduino and reconnect it, the system stops working. I have never encountered such a problem before. What could be the source of the problem?
In the setup function, I switch the LED on and off 3 times to show that the system has started to work. When I cut the power and give it again, the setup function works because the led flashes. But the functions in the loop function do not work. I would be very happy if you could help me.