Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h> //
- #include <SD.h> //
- #include <Wire.h> //
- #include "RTClib.h" //
- #include <MFRC522.h> //
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- #define SS_PIN 8 // 10 for shield // 8 for normal small module
- #define RST_PIN 9 // FOR RFID READER
- MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
- //-------------------------------------------------------------------------USER # 1
- String OrjwanID = "19 DD E3 B8";
- String OrjwanID_NUMBER = "3720112";
- boolean OrjwanStatus = true;
- //-------------------------------------------------------------------------
- //-------------------------------------------------------------------------USER # 2
- String NoorID = "02 A6 B1 34";
- String NoorID_NUMBER = "3720559";
- boolean NoorStatus = true;
- //-------------------------------------------------------------------------
- // A simple data logger for the Arduino analog pins
- // how many milliseconds between grabbing data and logging it. 1000 ms is once a second
- #define LOG_INTERVAL 1000 // mills between entries (reduce to take more/faster data)
- // how many milliseconds before writing the logged data permanently to disk
- // set it to the LOG_INTERVAL to write each time (safest)
- // set it to 10*LOG_INTERVAL to write all data every 10 datareads, you could lose up to
- // the last 10 reads if power is lost but it uses less power and is much faster!
- #define SYNC_INTERVAL 1000 // mills between calls to flush() - to write data to the card
- uint32_t syncTime = 0; // time of last sync()
- int buttonReading = 1;
- #define ECHO_TO_SERIAL 0 // echo data to serial port
- #define WAIT_TO_START 0 // Wait for serial input in setup()
- RTC_DS1307 RTC; // define the Real Time Clock object
- DateTime now;
- // for the data logging shield, we use digital pin 10 for the SD cs line
- const int chipSelect = 10;
- // the logging file
- File logfile;
- void error(char *str)
- {
- Serial.print("error: ");
- Serial.println(str);
- while (1);
- }
- void setup(void)
- {
- lcd.init();
- lcd.backlight();
- lcd.print("Connecting...");
- Serial.begin(9600);
- Serial.println();
- SPI.begin(); // Initiate SPI bus
- mfrc522.PCD_Init(); // Initiate MFRC522
- pinMode(7, OUTPUT);
- #if WAIT_TO_START
- Serial.println("Type any character to start");
- while (!Serial.available());
- #endif //WAIT_TO_START
- // initialize the SD card
- Serial.print("Initializing SD card...");
- // make sure that the default chip select pin is set to
- // output, even if you don't use it:
- pinMode(10, OUTPUT);
- // pinMode(buttonPin, INPUT);
- // see if the card is present and can be initialized:
- if (!SD.begin(chipSelect)) {
- error("Card failed, or not present");
- }
- Serial.println("card initialized.");
- // create a new file
- char filename[] = "LOGGER00.CSV";
- for (uint8_t i = 0; i < 100; i++) {
- filename[6] = i / 10 + '0';
- filename[7] = i % 10 + '0';
- if (! SD.exists(filename)) {
- // only open a new file if it doesn't exist
- logfile = SD.open(filename, FILE_WRITE);
- break; // leave the loop!
- }
- }
- if (! logfile) {
- error("couldnt create file");
- }
- Serial.print("Logging to: ");
- Serial.println(filename);
- // connect to RTC
- Wire.begin();
- if (!RTC.begin()) {
- logfile.println("RTC failed");
- #if ECHO_TO_SERIAL
- Serial.println("RTC failed");
- #endif //ECHO_TO_SERIAL
- }
- logfile.println("Date,Time,Log");
- #if ECHO_TO_SERIAL
- Serial.println("Date-Time,Status");
- #endif //ECHO_TO_SERIAL
- delay(2000);
- lcd.clear();
- lcd.print("System Ready");
- delay(2500);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Log:");
- }
- void loop()
- {
- // 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;
- buzz();
- 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));
- }
- Serial.println();
- content.toUpperCase();
- //Serial.println(content.substring(1));
- ///////////////////////////////////////////////////////////////////////// User #001 /start
- if (content.substring(1) == OrjwanID)
- {
- if (OrjwanStatus == true) {
- OrjwanStatus = false;
- //Serial.println("Orjwan Just Signed IN");
- logTime();
- #if ECHO_TO_SERIAL
- logTimeSerial();
- #endif //ECHO_TO_SERIAL
- delay(10);
- logfile.print(", ");
- logfile.print("Orjwan Just Signed IN");
- logfile.print(", ");
- logfile.print(OrjwanID_NUMBER);
- lcd.setCursor(5, 0);
- lcd.print(OrjwanID_NUMBER);
- lcd.setCursor(0, 1);
- lcd.print("Orjwan-Sign IN");
- delay(3000);
- clearLCD();
- #if ECHO_TO_SERIAL
- Serial.print(", ");
- Serial.print("Orjwan Just Signed IN");
- #endif //ECHO_TO_SERIAL
- logfile.println();
- #if ECHO_TO_SERIAL
- Serial.println();
- #endif // ECHO_TO_SERIAL
- // Now we write data to disk! Don't sync too often - requires 2048 bytes of I/O to SD card
- // which uses a bunch of power and takes time
- if ((millis() - syncTime) < SYNC_INTERVAL) return;
- syncTime = millis();
- // blink LED to show we are syncing data to the card & updating FAT!
- logfile.flush();
- delay(1000);
- }
- else if (OrjwanStatus == false) {
- OrjwanStatus = true;
- //Serial.println("User 001 Just Signed OUT");
- logTime();
- #if ECHO_TO_SERIAL
- logTimeSerial();
- #endif //ECHO_TO_SERIAL
- delay(10);
- logfile.print(", ");
- logfile.print("Orjwan Just Signed OUT");
- logfile.print(", ");
- logfile.print("3720112");
- lcd.setCursor(5, 0);
- lcd.print("3720112");
- lcd.setCursor(0, 1);
- lcd.print("Orjwan-Sign OUT");
- delay(3000);
- clearLCD();
- #if ECHO_TO_SERIAL
- Serial.print(", ");
- Serial.print("Orjwan Just Signed OUT");
- #endif //ECHO_TO_SERIAL
- logfile.println();
- #if ECHO_TO_SERIAL
- Serial.println();
- #endif // ECHO_TO_SERIAL
- // Now we write data to disk! Don't sync too often - requires 2048 bytes of I/O to SD card
- // which uses a bunch of power and takes time
- if ((millis() - syncTime) < SYNC_INTERVAL) return;
- syncTime = millis();
- // blink LED to show we are syncing data to the card & updating FAT!
- logfile.flush();
- delay(1000);
- }
- }
- ///////////////////////////////////////////////////////////////////////// User #001 /end
- ///////////////////////////////////////////////////////////////////////// User #002 /start //*** [1]
- if (content.substring(1) == NoorID) //*** [2]
- {
- if (NoorStatus == true) { //*** [3]
- NoorStatus = false; //*** [4]
- logTime();
- #if ECHO_TO_SERIAL
- logTimeSerial();
- #endif //ECHO_TO_SERIAL
- delay(10);
- logfile.print(", ");
- logfile.print("Noor Just Signed IN"); //*** [5]
- logfile.print(", ");
- logfile.print(NoorID_NUMBER);
- lcd.setCursor(5, 0);
- lcd.print(NoorID_NUMBER);
- lcd.setCursor(0, 1);
- // "1234567891234567" 16x characters only #######
- lcd.print("Noor-Sign IN "); //*** [7]
- delay(3000);
- clearLCD();
- #if ECHO_TO_SERIAL
- Serial.print(", ");
- Serial.print("Noor Just Signed IN"); //*** [6]
- #endif //ECHO_TO_SERIAL
- logfile.println();
- #if ECHO_TO_SERIAL
- Serial.println();
- #endif // ECHO_TO_SERIAL
- if ((millis() - syncTime) < SYNC_INTERVAL) return;
- syncTime = millis();
- logfile.flush();
- delay(1000);
- }
- else if (NoorStatus == false) { //*** [8]
- NoorStatus = true; //*** [9]
- logTime();
- #if ECHO_TO_SERIAL
- logTimeSerial();
- #endif //ECHO_TO_SERIAL
- delay(10);
- logfile.print(", ");
- logfile.print("Noor Just Signed OUT"); //*** [10]
- logfile.print(", ");
- logfile.print(NoorID_NUMBER);
- lcd.setCursor(5, 0);
- lcd.print(NoorID_NUMBER);
- lcd.setCursor(0, 1);
- // "1234567891234567" 16x characters only #######
- lcd.print("Noor-Sign OUT"); //*** [12]
- delay(3000);
- clearLCD();
- #if ECHO_TO_SERIAL
- Serial.print(", ");
- Serial.print("Noor Just Signed OUT"); //*** [11]
- #endif //ECHO_TO_SERIAL
- logfile.println();
- #if ECHO_TO_SERIAL
- Serial.println();
- #endif // ECHO_TO_SERIAL
- if ((millis() - syncTime) < SYNC_INTERVAL) return;
- syncTime = millis();
- logfile.flush();
- delay(1000);
- }
- }
- ///////////////////////////////////////////////////////////////////////// User #002 /end //*** [13]
- }// end of LOOP
- void buzz() {
- digitalWrite(7, 1);
- delay(100);
- digitalWrite(7, 0);
- delay(50);
- }
- void logTime() {
- now = RTC.now();
- logfile.print('"');
- logfile.print(now.year(), DEC);
- logfile.print("/");
- logfile.print(now.month(), DEC);
- logfile.print("/");
- logfile.print(now.day(), DEC);
- logfile.print('"');
- logfile.print(",");
- logfile.print(now.hour(), DEC);
- logfile.print(":");
- logfile.print(now.minute(), DEC);
- logfile.print(":");
- logfile.print(now.second(), DEC);
- }
- void logTimeSerial() {
- Serial.print('"');
- 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.print(now.minute(), DEC);
- Serial.print(":");
- Serial.print(now.second(), DEC);
- Serial.print('"');
- }
- void clearLCD() {
- lcd.setCursor(0, 0);
- lcd.print("Log: ");
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement