Good morning house. Pls i need your assistance. I am new into the house of Arduino programming. How do I apply delay in Arduino Eeprom so that the instructions in the Eeprom can be reset to zero (0) after the countdown time of the delay. I am building a RFID Attendance system with sms notification for students of a particular school and I want the Eeprom to retain the students information for a particular period of time...
Welcome to the forum
What length of period do you have in mind ?
Minutes, hours, days ?
Will all of the data in the EEPROM be reset at once after a period or will it be done on a student by student basis based on the time that the record for each student was recorded ?
How many student records do you need to keep ?
Which Arduino board are you using ?
do you need to physically erase the data for compliance reasons (like GDPR in Europe) or it's just a matter of limited storage space in your EEPROM?
Do you want to delete each individual based on their own time, or everyone at the same time ?
My thought would be to store the event time along with the student data, then each time the system is executed, it checks the elapsed interval, and does the deed.
I want everything to return back to the initial state zero
This is my program code that contains the Eeprom. Pls help me out.
#include <RTClib.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <DS3231.h>
#include <EEPROM.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
SoftwareSerial sim(2, 2);
String number = "+2348104654863"; // +977 is the country code
int state1;
int state2;
int state3;
int state4;
int state5;
//addresses in the eeprom
#define buzzerPin A1
#define RST_PIN A0
#define SDA_PIN 10
MFRC522 mfrc522(SDA_PIN, RST_PIN);
DS3231 rtc(SDA, SCL);
void setup() {
lcd.begin();
// Turn on the blacklight
lcd.backlight();
Serial.begin(9600);
sim.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
rtc.begin();
pinMode(buzzerPin, OUTPUT);
// read the state of each student rfid card when arduino is turned on
state1 = EEPROM.read(0);
state2 = EEPROM.read(1);
state3 = EEPROM.read(2);
state4 = EEPROM.read(3);
state5 = EEPROM.read(4);
lcd.setCursor(0, 0);
lcd.print(" WELCOME TO ");
lcd.setCursor(0, 1);
lcd.print("BEST ENKEFALOS C");
delay(4000);
lcd.clear();
}
void loop() {
eeprom_write();
RTC();
rfid();
}
void eeprom_write(){
EEPROM.write(0,state1);
EEPROM.write(1,state2);
EEPROM.write(2,state3);
EEPROM.write(3,state4);
EEPROM.write(4,state5);
}
void RTC()
{
//rtc.setDOW(MONDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(02, 44, 00); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(9, 04, 2023); // Set the date to January 1st, 2014
lcd.setCursor(0, 0);
lcd.print("Put Your Card to" );
lcd.setCursor(0, 1);
lcd.print("the Reader......");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.print(rtc.getTimeStr());
lcd.setCursor(0, 1);
lcd.print("Date: ");
lcd.print(rtc.getDateStr());
delay(1000);
lcd.clear();
}
void rfid()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
String content = "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
content.toUpperCase();
if (content.substring(1) == "D4 8A E9 2A" && state1 == 0) //change here the UID of the card/cards that you want to give access
{
beepON();
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("Mr Hassan ");
lcd.setCursor(7, 1);
lcd.print("Welcome");
info();
SendHassan();
state1 = 1;
}
else if (content.substring(1) == "D4 8A E9 2A" && state1 == 1) //change here the UID of the card/cards that you want to give access
{
beepON();
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("Mr Hassan ");
lcd.setCursor(7, 1);
lcd.print("GoodBye");
info();
SendHassan();
state1 = 0;
}
else if (content.substring(1) == "E2 60 5B 21" && state2 == 0) //change here the UID of the card/cards that you want to give access
{
beepON();
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("M. Bisola ");
lcd.setCursor(7, 1);
lcd.print("Welcome");
info();
SendAdeyemi();
state2 = 1;
}
else if (content.substring(1) == "E2 60 5B 21" && state2 == 1) //change here the UID of the card/cards that you want to give access
{
beepON();
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("M. Bisola ");
lcd.setCursor(7, 1);
lcd.print("GoodBye");
info();
SendAdeyemi();
state2 = 0;
}
else if (content.substring(1) == "E2 60 5B 21" && state3 == 0) //change here the UID of the card/cards that you want to give access
{
beepON();
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("M. Bisola ");
lcd.setCursor(7, 1);
lcd.print("Welcome");
info();
SendAdeyemi();
state2 = 1;
}
else if (content.substring(1) == "E2 60 5B 21" && state3 == 1) //change here the UID of the card/cards that you want to give access
{
beepON();
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("M. Bisola ");
lcd.setCursor(7, 1);
lcd.print("GoodBye");
info();
SendAdeyemi();
state2 = 0;
}
else if (content.substring(1) == "E2 60 5B 21" && state4 == 0) //change here the UID of the card/cards that you want to give access
{
beepON();
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("M. Bisola ");
lcd.setCursor(7, 1);
lcd.print("Welcome");
info();
SendAdeyemi();
state2 = 1;
}
else if (content.substring(1) == "E2 60 5B 21" && state4 == 1) //change here the UID of the card/cards that you want to give access
{
beepON();
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("M. Bisola ");
lcd.setCursor(7, 1);
lcd.print("GoodBye");
info();
SendAdeyemi();
state2 = 0;
}
else if (content.substring(1) == "E2 60 5B 21" && state5 == 0) //change here the UID of the card/cards that you want to give access
{
beepON();
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("M. Bisola ");
lcd.setCursor(7, 1);
lcd.print("Welcome");
info();
SendAdeyemi();
state2 = 1;
}
else if (content.substring(1) == "E2 60 5B 21" && state5 == 1) //change here the UID of the card/cards that you want to give access
{
beepON();
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("M. Bisola ");
lcd.setCursor(7, 1);
lcd.print("GoodBye");
info();
SendAdeyemi();
state2 = 0;
}
else {
digitalWrite(buzzerPin, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ID : ");
lcd.print("Unknown");
lcd.setCursor(0, 1);
lcd.print("Access denied");
Serial.println(" Access denied");
delay(1500);
digitalWrite(buzzerPin, LOW);
lcd.clear();
}
}
void smsSend()
{
lcd.setCursor(0, 0);
lcd.print("Sending SMS");
for (int x = 11; x < 16; x++)
{
lcd.setCursor(x, 0);
lcd.print(".");
delay(1000);
}
}
void beepON()
{
digitalWrite(buzzerPin, HIGH);
delay(200);
digitalWrite(buzzerPin, LOW);
delay(100);
}
void info()
{
lcd.setCursor(0, 0);
lcd.print("Name : ");
lcd.setCursor(0, 1);
lcd.print("");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Authorized Access");
delay(1000);
lcd.clear();
}
void SendHassan()
{
lcd.setCursor(0, 0);
lcd.print("SMS Sending");
sim.println("AT+CMGF=1");
delay(1000);
sim.println("AT+CMGS="" + number + ""\r");
delay(1000);
if (state1 == 0) {
const char Hassan[] = "Mr Hassan arrived to school at ";
sim.print(Hassan);
}
else if (state1 == 1) {
const char Hassan[] = "Mr Hassan left school at ";
sim.print(Hassan);
}
sim.println(rtc.getTimeStr());
delay(100);
sim.println((char)26);
smsSend();
}
void SendAdeyemi()
{
lcd.setCursor(0, 0);
lcd.print("SMS Sending");
sim.println("AT+CMGF=1");
delay(1000);
sim.println("AT+CMGS="" + number + ""\r");
delay(1000);
if (state2 == 0) {
const char Adeyemi[] = "Mrs Adeyemi arrived to school at ";
sim.print(Adeyemi);
}
else if (state2 == 1) {
const char Adeyemi[] = "Mrs Adeyemi left school at ";
sim.print(Adeyemi);
}
sim.println(rtc.getTimeStr());
delay(100);
sim.println((char)26);
smsSend();
}
void SendRasheed()
{
lcd.setCursor(0, 0);
lcd.print("SMS Sending");
sim.println("AT+CMGF=1");
delay(1000);
sim.println("AT+CMGS="" + number + ""\r");
delay(1000);
if (state3 == 0) {
const char Rasheed[] = "Mr Rasheed arrived to school at ";
sim.print(Rasheed);
}
else if (state3 == 1) {
const char Rasheed[] = "Mr Rasheed left school at ";
sim.print(Rasheed);
}
sim.println(rtc.getTimeStr());
delay(100);
sim.println((char)26);
smsSend();
}
void SendGeorge()
{
lcd.setCursor(0, 0);
lcd.print("SMS Sending");
sim.println("AT+CMGF=1");
delay(1000);
sim.println("AT+CMGS="" + number + ""\r");
delay(1000);
if (state4 == 0) {
const char George[] = "Mr George arrived to school at ";
sim.print(George);
}
else if (state4 == 1) {
const char George[] = "Mr George left school at";
sim.print(George);
}
sim.println(rtc.getTimeStr());
delay(100);
sim.println((char)26);
smsSend();
}
void SendTonia()
{
lcd.setCursor(0, 0);
lcd.print("SMS Sending");
sim.println("AT+CMGF=1");
delay(1000);
sim.println("AT+CMGS="" + number + ""\r");
delay(1000);
if (state5 == 0) {
const char Tonia[] = "Miss Tonia arrived to school at ";
sim.print(Tonia);
}
else if (state5 == 1) {
const char Tonia[] = "Miss Tonia left school at ";
sim.print(Tonia);
}
sim.println(rtc.getTimeStr());
delay(100);
sim.println((char)26);
smsSend();
}
Hours, 12hours to be precise
You’re writing a lot more code than you need.
Look into structures and arrays… along with EEPROM.put and .get, which will make your life a lot easier.
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.