diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..14ece03 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,27 @@ +[submodule "SD_v2/access_control/libraries/Adafruit_ST3775"] + path = SD_v2/access_control/libraries/Adafruit_ST3775 + url = https://github.com/adafruit/Adafruit-ST7735-Library.git +[submodule "SD_v2/access_control/libraries/Adafruit_GFX"] + path = SD_v2/access_control/libraries/Adafruit_GFX + url = https://github.com/adafruit/Adafruit-GFX-Library.git +[submodule "SD_v2/access_control/libraries/Sodaq_DS3231"] + path = SD_v2/access_control/libraries/Sodaq_DS3231 + url = https://github.com/SodaqMoja/Sodaq_DS3231.git +[submodule "SD_v2/access_control/libraries/MFRC522"] + path = SD_v2/access_control/libraries/MFRC522 + url = https://github.com/miguelbalboa/rfid.git +[submodule "SD_v2/Makefile_Build/libs/Sodaq_DS3231"] + path = SD_v2/Makefile_Build/libs/Sodaq_DS3231 + url = https://github.com/SodaqMoja/Sodaq_DS3231.git +[submodule "SD_v2/Makefile_Build/libs/Adafruit_ST3775"] + path = SD_v2/Makefile_Build/libs/Adafruit_ST3775 + url = https://github.com/adafruit/Adafruit-ST7735-Library.git +[submodule "SD_v2/Makefile_Build/libs/Adafruit_GFX"] + path = SD_v2/Makefile_Build/libs/Adafruit_GFX + url = https://github.com/adafruit/Adafruit-GFX-Library.git +[submodule "SD_v2/Makefile_Build/libs/MFRC522"] + path = SD_v2/Makefile_Build/libs/MFRC522 + url = https://github.com/miguelbalboa/rfid.git +[submodule "SD_v2/Makefile_Build/libs/SPI"] + path = SD_v2/Makefile_Build/libs/SPI + url = https://github.com/PaulStoffregen/SPI.git diff --git a/AccessControl/AccessControl.ino b/AccessControl/AccessControl.ino deleted file mode 100644 index 8a5aae5..0000000 --- a/AccessControl/AccessControl.ino +++ /dev/null @@ -1,423 +0,0 @@ -/* - Arduino RFID Access Control - - Security ! - - To keep it simple we are going to use Tag's Unique IDs - as only method of Authenticity. It's simple and not hacker proof. - If you need security, don't use it unless you modify the code - - Copyright (C) 2015 Omer Siar Baysal - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -*/ - -#include // RC522 Module uses SPI protocol -#include // Ethernet Library Wiznet -#include // Library for Mifare RC522 Devices -#include // We are going to read and write PICC's UIDs from/to SD - - -/* - Instead of a Relay maybe you want to use a servo - Servos can lock and unlock door locks too - There are examples out there. -*/ - -// #include - -/* - For visualizing whats going on hardware - we need some leds and - to control door lock a relay and a wipe button - (or some other hardware) - Used common anode led,digitalWriting HIGH turns OFF led - Mind that if you are going to use common cathode led or - just seperate leds, simply comment out #define COMMON_ANODE, - */ - -#define COMMON_ANODE - -#ifdef COMMON_ANODE -#define LED_ON LOW -#define LED_OFF HIGH -#else -#define LED_ON HIGH -#define LED_OFF LOW -#endif - -#define redLed 2 // Set Led Pins -#define greenLed 6 -#define blueLed 5 - -#define relay 3 // Set Relay Pin - -#define sdPin 4 // Set SD Pin - -boolean match = false; // initialize card match to false -boolean programMode = false; // initialize programming mode to false - -int successRead; // Variable integer to keep if we have Successful Read from Reader - -byte readCard[4]; // Stores scanned ID read from RFID Module -byte masterCard[4]; // Stores master card's ID - -char filename[] = "XXXXXXXXXXXXXXX.DAT"; // Stores variable filename -char extension[] = "DAT"; // sometimes the extension gets modified -char dir[] = "/PICCS/"; - - -/* - We need to define MFRC522's pins and create instance - Pin layout should be as follows (on Arduino Uno): - MOSI: Pin 11 / ICSP-4 - MISO: Pin 12 / ICSP-1 - SCK : Pin 13 / ICSP-3 - SDA : (Configurable) - RST : Not Needed - - */ - -#define SS_PIN 9 -#define RST_PIN 8 -MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. - -/************ ETHERNET STUFF ************/ -// Initialize the Ethernet server library -// with the IP address and port you want to use -// (port 80 is default for HTTP): -byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; -IPAddress ip(192, 168, 1, 245); -EthernetServer server(80); - - -///////////////////////////////////////// Setup /////////////////////////////////// -void setup() { - //Arduino Pin Configuration - pinMode(redLed, OUTPUT); - pinMode(greenLed, OUTPUT); - pinMode(blueLed, OUTPUT); - pinMode(relay, OUTPUT); // Be careful how relay circuit behave on while resetting or power-cycling your Arduino - digitalWrite(relay, HIGH); // Make sure door is locked - digitalWrite(redLed, LED_OFF); // Make sure led is off - digitalWrite(greenLed, LED_OFF); // Make sure led is off - digitalWrite(blueLed, LED_OFF); // Make sure led is off - - //Initialize - Serial.begin(9600); // Initialize serial communications with PC - Serial.println(F("Access Control v4.3")); // For debugging purposes - SPI.begin(); // MFRC522 Hardware uses SPI protocol - Ethernet.begin(mac, ip); - server.begin(); - Serial.print("server is at "); - Serial.println(Ethernet.localIP()); - if (!SD.begin(sdPin)) { // Initialize SD Hardware - Serial.println(F("SD initialization failed!")); // Could not initialize - redSolid(); - while (true); // Do not go further - } - Serial.println(F("SD initialization done.")); // Yay all SPI slaves work - mfrc522.PCD_Init(); // Initialize MFRC522 Hardware - ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details - - //If you set Antenna Gain to Max it will increase reading distance - //mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); - - checkMaster(); // Check if masterCard defined - Serial.println(F("Everything Ready")); - Serial.println(F("Waiting PICCs to be scanned")); - cycleLeds(); // Lets give user some feedback that hardware initialized by cycling leds -} - - - -///////////////////////////////////////// Main Loop /////////////////////////////////// -void loop () { - do { - checkClient(); - successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 - if (programMode) { - cycleLeds(); // Program Mode cycles through RGB waiting to read a new card - } - else { - blueSolid(); // Normal mode, blue Power LED is on, all others are off - } - } - while (!successRead); // the program will not go further while you not get a successful read - if (programMode) { - if (isMaster(readCard)) { // If master card scanned again exit program mode - Serial.println(F("Master Card Scanned")); - Serial.println(F("Exiting Program Mode")); - Serial.println(F("-----------------------------")); - programMode = false; - return; - } - else { - if ( findID() ) { // If scanned card is known delete it - Serial.println(F("I know this PICC, removing...")); - removeID(); - Serial.println(F("-----------------------------")); - } - else { // If scanned card is not known add it - Serial.println(F("I do not know this PICC, adding...")); - writeID(); - Serial.println(F("-----------------------------")); - } - } - } - else { - if (isMaster(readCard)) { // If scanned card's ID matches Master Card's ID enter program mode - programMode = true; - Serial.println(F("Hello Master - Entered Program Mode")); - Serial.println(F("Scan a PICC to ADD or REMOVE")); - Serial.println(F("-----------------------------")); - } - else { - if (findID()) { // If not, check if we can find it - Serial.println(F("Welcome, You shall pass")); - granted(300); // Open the door lock for 300 ms - } - else { // If not, show that the ID was not valid - Serial.println(F("You shall not pass")); - denied(); - } - } - } -} - -void checkClient() { - - EthernetClient client = server.available(); // try to get client - if (client) { // got client? - boolean currentLineIsBlank = true; - while (client.connected()) { - if (client.available()) { // client data available to read - char c = client.read(); // read 1 byte (character) from client - // last line of client request is blank and ends with \n - // respond to client only after last line received - if (c == '\n' && currentLineIsBlank) { - // send a standard http response header - client.println("HTTP/1.1 200 OK"); - client.println("Content-Type: text/html"); - client.println("Connection: close"); - client.println(); - client.print("Arduino RFID Access Control

Welcome RFID Access Control 4

Here is the list of Authorized Users


"); - - File dir = SD.open("/PICCS"); - while (true) { - File entry = dir.openNextFile(); - if (! entry) { - // no more files - break; - } - client.print(""); - - } - - client.print("
User NameUID FileRemove
"); - while (entry.available()) { - client.write(entry.read()); - } - entry.close(); - client.print(""); - client.print(entry.name()); - client.print(""); - client.println("
"); - client.println("
"); - client.print("
"); - break; - } - // every line of text received from the client ends with \r\n - if (c == '\n') { - // last character on line of received text - // starting new line with next character read - currentLineIsBlank = true; - } - else if (c != '\r') { - // a text character was received from client - currentLineIsBlank = false; - } - } // end if (client.available()) - } // end while (client.connected()) - delay(1); // give the web browser time to receive the data - client.stop(); // close the connection - } // end if (client) -} - - - - -void getFilename() { // We will store UIDs as files on SD card - sprintf(filename, "%s%02x%02x%02x%02x.%s", dir, readCard[0], readCard[1], // Convert readCard data to char and append extension - readCard[2], readCard[3], extension); -} - -boolean findID () { // Check If we can find UID's specific file - File fileopen = SD.open(filename); - if (fileopen) { - fileopen.close(); // Found it close - return true; - } - else { // If not, return false - } - return false; -} - -void writeID () { - File filewrite = SD.open(filename, FILE_WRITE); - filewrite.close(); - if (SD.exists(filename)) { - Serial.println(F("Succesfully added ID record")); - greenBlink(); - } - else { - Serial.println(F("Failed to add record")); - redBlink(); - } -} - -void removeID () { - SD.remove(filename); - if (SD.exists(filename)) { - Serial.println(F("Failed to remove. Record still exists")); - redBlink(); - } - else { - Serial.println(F("Succesfully removed ID record")); - blueBlink(); - } -} - -///////////////////////////////////////// Access Granted /////////////////////////////////// -void granted (int setDelay) { - digitalWrite(relay, LOW); // Unlock door! - delay(setDelay); // Hold door lock open for given seconds - digitalWrite(relay, HIGH); // Relock door - greenSolid(); -} - -///////////////////////////////////////// Access Denied /////////////////////////////////// -void denied() { - redSolid(); -} - - -///////////////////////////////////////// Get PICC's UID /////////////////////////////////// -int getID() { - // Getting ready for Reading PICCs - if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue - return 0; - } - if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue - return 0; - } - // There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC - // I think we should assume every PICC as they have 4 byte UID - // Until we support 7 byte PICCs - Serial.println(F("Scanned PICC's UID:")); - for (int i = 0; i < 4; i++) { // - readCard[i] = mfrc522.uid.uidByte[i]; - Serial.print(readCard[i], HEX); - } - Serial.println(""); - mfrc522.PICC_HaltA(); // Stop reading - getFilename(); // Get data ready - return 1; -} - -void checkMaster() { - if (SD.exists("/SYS/master.dat")) { // Check if we have master.dat on SD card - Serial.print(F("Master Card's UID: ")); // Since we have it print to serial - File masterfile = SD.open("/SYS/master.dat"); // Open file - for (int i = 0; i < 4; i++) { // Loop 4 times to get 4 bytes - readCard[i] = masterfile.read(); - Serial.print(readCard[i], HEX); // Actual serial printing of each byte - masterCard[i] = readCard[i]; // Prepare bytes for future comparing - } - Serial.println(""); - masterfile.close(); // Close file - } - else { - Serial.println(F("No Master Card Defined")); - Serial.println(F("Scan A PICC to Define as Master Card")); - do { - successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 - blueBlink(); // Visualize Master Card need to be defined - } - while (!successRead); //the program will not go further while you not get a successful read - File masterfile = SD.open("/SYS/master.dat", FILE_WRITE); - if (masterfile) { - Serial.println(F("Writing to master.dat...")); - masterfile.write(readCard, 4); - // close the file: - masterfile.close(); - Serial.println(F("Master Card successfuly defined")); - } else { - // if the file didn't open, print an error: - Serial.println(F("error creating master.dat")); - redBlink(); - } - } -} - - - - -void ShowReaderDetails() { - // Get the MFRC522 software version - byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); - Serial.print(F("MFRC522 Software Version: 0x")); - Serial.print(v, HEX); - if (v == 0x91) - Serial.print(F(" = v1.0")); - else if (v == 0x92) - Serial.print(F(" = v2.0")); - else - Serial.print(F(" (unknown)")); - Serial.println(""); - // When 0x00 or 0xFF is returned, communication probably failed - if ((v == 0x00) || (v == 0xFF)) { - Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?")); - redSolid(); - while (true); // do not go further - } -} - -///////////////////////////////////////// Check Bytes /////////////////////////////////// -boolean checkTwo ( byte a[], byte b[] ) { - if ( a[0] != NULL ) // Make sure there is something in the array first - match = true; // Assume they match at first - for ( int k = 0; k < 4; k++ ) { // Loop 4 times - if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail - match = false; - } - if ( match ) { // Check to see if if match is still true - return true; // Return true - } - else { - return false; // Return false - } -} - -////////////////////// Check readCard IF is masterCard /////////////////////////////////// -// Check to see if the ID passed is the master programing card -boolean isMaster( byte test[] ) { - if ( checkTwo( test, masterCard ) ) - return true; - else - return false; -} - diff --git a/AccessControl/Leds.ino b/AccessControl/Leds.ino deleted file mode 100644 index 2b95093..0000000 --- a/AccessControl/Leds.ino +++ /dev/null @@ -1,95 +0,0 @@ -///////////////////////////////////////// Write Success to EEPROM /////////////////////////////////// -// Flashes the green LED 3 times to indicate a successful write to EEPROM -void greenBlink() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); -} - -///////////////////////////////////////// Write Failed to EEPROM /////////////////////////////////// -// Flashes the red LED 3 times to indicate a failed write to EEPROM -void redBlink() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); -} - -///////////////////////////////////////// Success Remove UID From EEPROM /////////////////////////////////// -// Flashes the blue LED 3 times to indicate a success delete to EEPROM -void blueBlink() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); -} - - -///////////////////////////////////////// Cycle Leds (Program Mode) /////////////////////////////////// -void cycleLeds() { - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); -} - -//////////////////////////////////////// Normal Mode Led /////////////////////////////////// -void blueSolid () { - digitalWrite(blueLed, LED_ON); // Blue LED ON and ready to read card - digitalWrite(redLed, LED_OFF); // Make sure Red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure Green LED is off -} - -void greenSolid () { - digitalWrite(blueLed, LED_OFF); // Turn off blue LED - digitalWrite(redLed, LED_OFF); // Turn off red LED - digitalWrite(greenLed, LED_ON); // Turn on green LED - delay(1000); // Hold green LED on for a second -} - -///////////////////////////////////////// Access Denied /////////////////////////////////// -void redSolid() { - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_ON); // Turn on red LED - delay(1000); -} diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 11a7be8..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,82 +0,0 @@ -# Change Log -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/) -and this project adheres to [Semantic Versioning](http://semver.org/). - -## [0.1.1] - 2016-11-11 -### Added -- Wiping Master Card UID on EEPROM in order to Re-Program on restart - -## [0.1.0] - 2015-05-30 -### Added -- Initial SD Card Version (stores data on SD Card) -- Arduino Flash optimiziation -- Hardware version check -- Initial Ethernet version (WebUI) -- Initial No Serial Version - -### Changed -- Antenna Gain Control disabled by default (stability concers with Chinese clones) - -### Fixed -- Handling PICCs that have 7 bytes UID - -## [0.0.8] - 2014-11-01 -### Added -- A script to Delete a known UID from EEPROM - -### Changed -- Minor Wipe Mode led behaviour change -- Program Mode no longer exit until Master Card scanned again - -## [0.0.7] - 2014-08-27 -### Added -- Support for defining Master Card at first use -(no need to be hard coded on Flash Now) -- Matured Wipe Mode and enabled by default - -## [0.0.6] - 2014-08-12 -### Added -- Experimental Wipe Mode (Wipe EEPROM during startup) - -### Removed -- Gain Control (Now Library supports Gain Control natively) - -## [0.0.5] - 2014-08-10 -### Changed -- Modified RFID library to support Max. Gain (48db) - -## [0.0.4] - 2014-07-27 -### Added -- Leds cycle through in Program Mode - -### Changed -- Minor delay changes to Leds and Relay - -## [0.0.3] - 2014-07-26 -### Added -- Support for Common Anode or Cathode Leds -- Better explanation about project - -### Changed -- Behaviour on exiting Program Mode (Scan Master Card again to Exit) -- Now PICCs that have 7 bytes UID is handled as they have 4 bytes UID -(Code simply does not care last 3 bytes) - -### Removed -- Buzzer support - -## [0.0.2] - 2014-07-25 -### Added -- RC522 RFID hardware support -- Buzzer support - -### Changed -- Better readable code with AStyle - -## [0.0.1] - 2014-07-23 -### Misc -- Fork of http://www.instructables.com/id/Arduino-RFID-Door-Lock/ -- More comments made on Code -- Initial Hardware specific code change (we will use RC522 instead of ID-12) diff --git a/DeleteLostTag/DeleteLostTag.ino b/DeleteLostTag/DeleteLostTag.ino deleted file mode 100644 index a8ecb68..0000000 --- a/DeleteLostTag/DeleteLostTag.ino +++ /dev/null @@ -1,199 +0,0 @@ -/* - This program will delete a Known UID from EEPROM - Since EEPROM records remains between flashing Arduino - this can be used to delete lost PICC's UID, and - reflash main program to continue working. - - Copyright (C) 2015 Omer Siar Baysal - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -byte deleteCard[4] ={0x12,0x34,0x56,0x78}; // Enter your lost card's UID Here - -#include // We are going to read and write PICC's UIDs from/to EEPROM - -#define COMMON_ANODE - -#ifdef COMMON_ANODE -#define LED_ON LOW -#define LED_OFF HIGH -#else -#define LED_ON HIGH -#define LED_OFF LOW -#endif - -#define redLed 7 -#define greenLed 6 -#define blueLed 5 - -boolean match = false; // initialize card match to false -byte storedCard[4]; // Stores an ID read from EEPROM - -void setup() { - //Arduino Pin Configuration - pinMode(redLed, OUTPUT); - pinMode(greenLed, OUTPUT); - pinMode(blueLed, OUTPUT); - digitalWrite(redLed, LED_OFF); // Make sure led is off - digitalWrite(greenLed, LED_OFF); // Make sure led is off - digitalWrite(blueLed, LED_OFF); // Make sure led is off - - //Protocol Configuration - Serial.begin(9600); // Initialize serial communications with PC - - int count = EEPROM.read(0); // Read the first Byte of EEPROM that - Serial.print("I have "); // stores the number of ID's in EEPROM - Serial.print(count); - Serial.print(" record(s) on EEPROM"); - Serial.println(""); - - Serial.println("UID to Delete"); - for (int i = 0; i < 4; i++) { // - Serial.print(deleteCard[i], HEX); - } - Serial.println(""); - - deleteID(deleteCard); //Try to delete - /* - This will find the given UID (deleteCard) from EEPROM - and delete it and Shift remaining records to 4 byte earlier. - Blue Led will flash on success, Red Led will flash on fail. - */ -} - -void loop() { - //Nothing to do in loop -} - - -//////////////////////////////////////// Read an ID from EEPROM ////////////////////////////// -void readID( int number ) { - int start = (number * 4 ) + 2; // Figure out starting position - for ( int i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes - storedCard[i] = EEPROM.read(start+i); // Assign values read from EEPROM to array - } -} - -///////////////////////////////////////// Remove ID from EEPROM /////////////////////////////////// -void deleteID( byte a[] ) { - if ( !findID( a ) ) { // Before we delete from the EEPROM, check to see if we have this card! - failedWrite(); // If not - } - else { - int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards - int slot; // Figure out the slot number of the card - int start;// = ( num * 4 ) + 6; // Figure out where the next slot starts - int looping; // The number of times the loop repeats - int j; - int count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards - slot = findIDSLOT( a ); //Figure out the slot number of the card to delete - start = (slot * 4) + 2; - looping = ((num - slot) * 4); - num--; // Decrement the counter by one - EEPROM.write( 0, num ); // Write the new count to the counter - for ( j = 0; j < looping; j++ ) { // Loop the card shift times - EEPROM.write( start+j, EEPROM.read(start+4+j)); // Shift the array values to 4 places earlier in the EEPROM - } - for ( int k = 0; k < 4; k++ ) { //Shifting loop - EEPROM.write( start+j+k, 0); - } - successDelete(); - } -} - -///////////////////////////////////////// Check Bytes /////////////////////////////////// -boolean checkTwo ( byte a[], byte b[] ) { - if ( a[0] != NULL ) // Make sure there is something in the array first - match = true; // Assume they match at first - for ( int k = 0; k < 4; k++ ) { // Loop 4 times - if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail - match = false; - } - if ( match ) { // Check to see if if match is still true - return true; // Return true - } - else { - return false; // Return false - } -} - -///////////////////////////////////////// Find Slot /////////////////////////////////// -int findIDSLOT( byte find[] ) { - int count = EEPROM.read(0); // Read the first Byte of EEPROM that - for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry - readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] - if( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM - // is the same as the find[] ID card passed - return i; // The slot number of the card - break; // Stop looking we found it - } - } -} - -///////////////////////////////////////// Find ID From EEPROM /////////////////////////////////// -boolean findID( byte find[] ) { - int count = EEPROM.read(0); // Read the first Byte of EEPROM that - for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry - readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] - if( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM - return true; - break; // Stop looking we found it - } - else { // If not, return false - } - } - return false; -} - -///////////////////////////////////////// Write Failed to EEPROM /////////////////////////////////// -// Flashes the red LED 3 times to indicate a failed write to EEPROM -void failedWrite() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - Serial.println("Failed! There is something wrong with ID or bad EEPROM"); -} - -///////////////////////////////////////// Success Remove UID From EEPROM /////////////////////////////////// -// Flashes the blue LED 3 times to indicate a success delete to EEPROM -void successDelete() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - Serial.println("Succesfully removed ID record from EEPROM"); -} diff --git a/EEPROM/EEPROM.ino b/EEPROM/EEPROM.ino deleted file mode 100644 index 0fdb10f..0000000 --- a/EEPROM/EEPROM.ino +++ /dev/null @@ -1,511 +0,0 @@ -/* - Arduino RFID Access Control - - Security ! - - To keep it simple we are going to use Tag's Unique IDs - as only method of Authenticity. It's simple and not hacker proof. - If you need security, don't use it unless you modify the code - - Copyright (C) 2015 Omer Siar Baysal - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -*/ - -#include // We are going to read and write PICC's UIDs from/to EEPROM -#include // RC522 Module uses SPI protocol -#include // Library for Mifare RC522 Devices - -/* - Instead of a Relay maybe you want to use a servo - Servos can lock and unlock door locks too - There are examples out there. -*/ - -// #include - -/* - For visualizing whats going on hardware - we need some leds and - to control door lock a relay and a wipe button - (or some other hardware) - Used common anode led,digitalWriting HIGH turns OFF led - Mind that if you are going to use common cathode led or - just seperate leds, simply comment out #define COMMON_ANODE, -*/ - -#define COMMON_ANODE - -#ifdef COMMON_ANODE -#define LED_ON LOW -#define LED_OFF HIGH -#else -#define LED_ON HIGH -#define LED_OFF LOW -#endif - -#define redLed 7 // Set Led Pins -#define greenLed 6 -#define blueLed 5 - -#define relay 4 // Set Relay Pin -#define wipeB 3 // Button pin for WipeMode - -boolean match = false; // initialize card match to false -boolean programMode = false; // initialize programming mode to false -boolean replaceMaster = false; - -int successRead; // Variable integer to keep if we have Successful Read from Reader - -byte storedCard[4]; // Stores an ID read from EEPROM -byte readCard[4]; // Stores scanned ID read from RFID Module -byte masterCard[4]; // Stores master card's ID read from EEPROM - -/* - We need to define MFRC522's pins and create instance - Pin layout should be as follows (on Arduino Uno): - MOSI: Pin 11 / ICSP-4 - MISO: Pin 12 / ICSP-1 - SCK : Pin 13 / ICSP-3 - SS : Pin 10 (Configurable) - RST : Pin 9 (Configurable) - look MFRC522 Library for - other Arduinos' pin configuration -*/ - -#define SS_PIN 10 -#define RST_PIN 9 -MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. - -///////////////////////////////////////// Setup /////////////////////////////////// -void setup() { - //Arduino Pin Configuration - pinMode(redLed, OUTPUT); - pinMode(greenLed, OUTPUT); - pinMode(blueLed, OUTPUT); - pinMode(wipeB, INPUT_PULLUP); // Enable pin's pull up resistor - pinMode(relay, OUTPUT); - //Be careful how relay circuit behave on while resetting or power-cycling your Arduino - digitalWrite(relay, HIGH); // Make sure door is locked - digitalWrite(redLed, LED_OFF); // Make sure led is off - digitalWrite(greenLed, LED_OFF); // Make sure led is off - digitalWrite(blueLed, LED_OFF); // Make sure led is off - - //Protocol Configuration - Serial.begin(9600); // Initialize serial communications with PC - SPI.begin(); // MFRC522 Hardware uses SPI protocol - mfrc522.PCD_Init(); // Initialize MFRC522 Hardware - - //If you set Antenna Gain to Max it will increase reading distance - //mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); - - Serial.println(F("Access Control v3.4")); // For debugging purposes - ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details - - //Wipe Code if Button Pressed while setup run (powered on) it wipes EEPROM - if (digitalRead(wipeB) == LOW) { // when button pressed pin should get low, button connected to ground - digitalWrite(redLed, LED_ON); // Red Led stays on to inform user we are going to wipe - Serial.println(F("Wipe Button Pressed")); - Serial.println(F("You have 15 seconds to Cancel")); - Serial.println(F("This will be remove all records and cannot be undone")); - delay(15000); // Give user enough time to cancel operation - if (digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM - Serial.println(F("Starting Wiping EEPROM")); - for (int x = 0; x < EEPROM.length(); x = x + 1) { //Loop end of EEPROM address - if (EEPROM.read(x) == 0) { //If EEPROM address 0 - // do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM - } - else { - EEPROM.write(x, 0); // if not write 0 to clear, it takes 3.3mS - } - } - Serial.println(F("EEPROM Successfully Wiped")); - digitalWrite(redLed, LED_OFF); // visualize successful wipe - delay(200); - digitalWrite(redLed, LED_ON); - delay(200); - digitalWrite(redLed, LED_OFF); - delay(200); - digitalWrite(redLed, LED_ON); - delay(200); - digitalWrite(redLed, LED_OFF); - } - else { - Serial.println(F("Wiping Cancelled")); - digitalWrite(redLed, LED_OFF); - } - } - // Check if master card defined, if not let user choose a master card - // This also useful to just redefine Master Card - // You can keep other EEPROM records just write other than 143 to EEPROM address 1 - // EEPROM address 1 should hold magical number which is '143' - if (EEPROM.read(1) != 143) { - Serial.println(F("No Master Card Defined")); - Serial.println(F("Scan A PICC to Define as Master Card")); - do { - successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 - digitalWrite(blueLed, LED_ON); // Visualize Master Card need to be defined - delay(200); - digitalWrite(blueLed, LED_OFF); - delay(200); - } - while (!successRead); // Program will not go further while you not get a successful read - for ( int j = 0; j < 4; j++ ) { // Loop 4 times - EEPROM.write( 2 + j, readCard[j] ); // Write scanned PICC's UID to EEPROM, start from address 3 - } - EEPROM.write(1, 143); // Write to EEPROM we defined Master Card. - Serial.println(F("Master Card Defined")); - } - Serial.println(F("-------------------")); - Serial.println(F("Master Card's UID")); - for ( int i = 0; i < 4; i++ ) { // Read Master Card's UID from EEPROM - masterCard[i] = EEPROM.read(2 + i); // Write it to masterCard - Serial.print(masterCard[i], HEX); - } - Serial.println(""); - Serial.println(F("-------------------")); - Serial.println(F("Everything Ready")); - Serial.println(F("Waiting PICCs to be scanned")); - cycleLeds(); // Everything ready lets give user some feedback by cycling leds -} - - -///////////////////////////////////////// Main Loop /////////////////////////////////// -void loop () { - do { - successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 - if (digitalRead(wipeB) == LOW) { - digitalWrite(redLed, LED_ON); // Make sure led is off - digitalWrite(greenLed, LED_OFF); // Make sure led is off - digitalWrite(blueLed, LED_OFF); // Make sure led is off - Serial.println(F("Wipe Button Pressed")); - Serial.println(F("Master Card will be Erased! in 10 seconds")); - delay(10000); - if (digitalRead(wipeB) == LOW) { - EEPROM.write(1, 0); // Reset Magic Number. - Serial.println(F("Restart device to re-program Master Card")); - while (1); - } - } - if (programMode) { - cycleLeds(); // Program Mode cycles through RGB waiting to read a new card - } - else { - normalModeOn(); // Normal mode, blue Power LED is on, all others are off - } - } - while (!successRead); //the program will not go further while you not get a successful read - if (programMode) { - if ( isMaster(readCard) ) { //If master card scanned again exit program mode - Serial.println(F("Master Card Scanned")); - Serial.println(F("Exiting Program Mode")); - Serial.println(F("-----------------------------")); - programMode = false; - return; - } - else { - if ( findID(readCard) ) { // If scanned card is known delete it - Serial.println(F("I know this PICC, removing...")); - deleteID(readCard); - Serial.println("-----------------------------"); - Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); - } - else { // If scanned card is not known add it - Serial.println(F("I do not know this PICC, adding...")); - writeID(readCard); - Serial.println(F("-----------------------------")); - Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); - } - } - } - else { - if ( isMaster(readCard)) { // If scanned card's ID matches Master Card's ID enter program mode - programMode = true; - Serial.println(F("Hello Master - Entered Program Mode")); - int count = EEPROM.read(0); // Read the first Byte of EEPROM that - Serial.print(F("I have ")); // stores the number of ID's in EEPROM - Serial.print(count); - Serial.print(F(" record(s) on EEPROM")); - Serial.println(""); - Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); - Serial.println(F("Scan Master Card again to Exit Program Mode")); - Serial.println(F("-----------------------------")); - } - else { - if ( findID(readCard) ) { // If not, see if the card is in the EEPROM - Serial.println(F("Welcome, You shall pass")); - granted(300); // Open the door lock for 300 ms - } - else { // If not, show that the ID was not valid - Serial.println(F("You shall not pass")); - denied(); - } - } - } -} - -///////////////////////////////////////// Access Granted /////////////////////////////////// -void granted (int setDelay) { - digitalWrite(blueLed, LED_OFF); // Turn off blue LED - digitalWrite(redLed, LED_OFF); // Turn off red LED - digitalWrite(greenLed, LED_ON); // Turn on green LED - digitalWrite(relay, LOW); // Unlock door! - delay(setDelay); // Hold door lock open for given seconds - digitalWrite(relay, HIGH); // Relock door - delay(1000); // Hold green LED on for a second -} - -///////////////////////////////////////// Access Denied /////////////////////////////////// -void denied() { - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_ON); // Turn on red LED - delay(1000); -} - - -///////////////////////////////////////// Get PICC's UID /////////////////////////////////// -int getID() { - // Getting ready for Reading PICCs - if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue - return 0; - } - if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue - return 0; - } - // There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC - // I think we should assume every PICC as they have 4 byte UID - // Until we support 7 byte PICCs - Serial.println(F("Scanned PICC's UID:")); - for (int i = 0; i < 4; i++) { // - readCard[i] = mfrc522.uid.uidByte[i]; - Serial.print(readCard[i], HEX); - } - Serial.println(""); - mfrc522.PICC_HaltA(); // Stop reading - return 1; -} - -void ShowReaderDetails() { - // Get the MFRC522 software version - byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); - Serial.print(F("MFRC522 Software Version: 0x")); - Serial.print(v, HEX); - if (v == 0x91) - Serial.print(F(" = v1.0")); - else if (v == 0x92) - Serial.print(F(" = v2.0")); - else - Serial.print(F(" (unknown),probably a chinese clone?")); - Serial.println(""); - // When 0x00 or 0xFF is returned, communication probably failed - if ((v == 0x00) || (v == 0xFF)) { - Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?")); - Serial.println(F("SYSTEM HALTED: Check connections.")); - while (true); // do not go further - } -} - -///////////////////////////////////////// Cycle Leds (Program Mode) /////////////////////////////////// -void cycleLeds() { - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); -} - -//////////////////////////////////////// Normal Mode Led /////////////////////////////////// -void normalModeOn () { - digitalWrite(blueLed, LED_ON); // Blue LED ON and ready to read card - digitalWrite(redLed, LED_OFF); // Make sure Red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure Green LED is off - digitalWrite(relay, HIGH); // Make sure Door is Locked -} - -//////////////////////////////////////// Read an ID from EEPROM ////////////////////////////// -void readID( int number ) { - int start = (number * 4 ) + 2; // Figure out starting position - for ( int i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes - storedCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array - } -} - -///////////////////////////////////////// Add ID to EEPROM /////////////////////////////////// -void writeID( byte a[] ) { - if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before! - int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards - int start = ( num * 4 ) + 6; // Figure out where the next slot starts - num++; // Increment the counter by one - EEPROM.write( 0, num ); // Write the new count to the counter - for ( int j = 0; j < 4; j++ ) { // Loop 4 times - EEPROM.write( start + j, a[j] ); // Write the array values to EEPROM in the right position - } - successWrite(); - Serial.println(F("Succesfully added ID record to EEPROM")); - } - else { - failedWrite(); - Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); - } -} - -///////////////////////////////////////// Remove ID from EEPROM /////////////////////////////////// -void deleteID( byte a[] ) { - if ( !findID( a ) ) { // Before we delete from the EEPROM, check to see if we have this card! - failedWrite(); // If not - Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); - } - else { - int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards - int slot; // Figure out the slot number of the card - int start; // = ( num * 4 ) + 6; // Figure out where the next slot starts - int looping; // The number of times the loop repeats - int j; - int count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards - slot = findIDSLOT( a ); // Figure out the slot number of the card to delete - start = (slot * 4) + 2; - looping = ((num - slot) * 4); - num--; // Decrement the counter by one - EEPROM.write( 0, num ); // Write the new count to the counter - for ( j = 0; j < looping; j++ ) { // Loop the card shift times - EEPROM.write( start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM - } - for ( int k = 0; k < 4; k++ ) { // Shifting loop - EEPROM.write( start + j + k, 0); - } - successDelete(); - Serial.println(F("Succesfully removed ID record from EEPROM")); - } -} - -///////////////////////////////////////// Check Bytes /////////////////////////////////// -boolean checkTwo ( byte a[], byte b[] ) { - if ( a[0] != NULL ) // Make sure there is something in the array first - match = true; // Assume they match at first - for ( int k = 0; k < 4; k++ ) { // Loop 4 times - if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail - match = false; - } - if ( match ) { // Check to see if if match is still true - return true; // Return true - } - else { - return false; // Return false - } -} - -///////////////////////////////////////// Find Slot /////////////////////////////////// -int findIDSLOT( byte find[] ) { - int count = EEPROM.read(0); // Read the first Byte of EEPROM that - for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry - readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] - if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM - // is the same as the find[] ID card passed - return i; // The slot number of the card - break; // Stop looking we found it - } - } -} - -///////////////////////////////////////// Find ID From EEPROM /////////////////////////////////// -boolean findID( byte find[] ) { - int count = EEPROM.read(0); // Read the first Byte of EEPROM that - for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry - readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] - if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM - return true; - break; // Stop looking we found it - } - else { // If not, return false - } - } - return false; -} - -///////////////////////////////////////// Write Success to EEPROM /////////////////////////////////// -// Flashes the green LED 3 times to indicate a successful write to EEPROM -void successWrite() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); -} - -///////////////////////////////////////// Write Failed to EEPROM /////////////////////////////////// -// Flashes the red LED 3 times to indicate a failed write to EEPROM -void failedWrite() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); -} - -///////////////////////////////////////// Success Remove UID From EEPROM /////////////////////////////////// -// Flashes the blue LED 3 times to indicate a success delete to EEPROM -void successDelete() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); -} - -////////////////////// Check readCard IF is masterCard /////////////////////////////////// -// Check to see if the ID passed is the master programing card -boolean isMaster( byte test[] ) { - if ( checkTwo( test, masterCard ) ) - return true; - else - return false; -} - diff --git a/EEPROM/README.md b/EEPROM/README.md deleted file mode 100644 index 5a77d50..0000000 --- a/EEPROM/README.md +++ /dev/null @@ -1,51 +0,0 @@ -Arduino RC522 RFID Access Control -======= - -Arduino RFID Access Control using a RC522 RFID -reader with SPI interface on your Arduino -You define a Master Card which is act as Programmer -then you can able to choose card holders -who will granted access or not - - * **Easy User Interface** - -Just one RFID tag needed whether Delete or Add Tags -You can choose to use Leds for output or -Serial LCD module to inform users. Or you can use both - - * **Stores Information on EEPROM** - -Information stored on non volatile Arduino's EEPROM -memory to preserve Users' tag and Master Card -No Information lost if power lost. EEPROM has unlimited -Read cycle but 100,000 limited Write cycle. - - * **Security** - -To keep it simple we are going to use Tag's Unique IDs -It's simple and not hacker proof. - - * **Additional Information** - -MFRC522 Library also lets us to use some authentication -mechanism, writing blocks and reading back -and there is great example and piece of code -about reading and writing PICCs -here > http://makecourse.weebly.com/week10segment1.html - -More info on: -http://forum.arduino.cc/index.php?topic=256260 - - * **Credits** - -Omer Siar Baysal who put together this project - -Idea and most of code from Brett Martin's project -http://www.instructables.com/id/Arduino-RFID-Door-Lock/ - -MFRC522 Library -https://github.com/miguelbalboa/rfid -Created by Miguel Balboa (circuitito.com), Jan, 2012. - -Arduino Forum Member luisilva for His Massive Code Correction -http://forum.arduino.cc/index.php?topic=257036.0 diff --git a/LCD/LCD.ino b/LCD/LCD.ino deleted file mode 100644 index 4ff6537..0000000 --- a/LCD/LCD.ino +++ /dev/null @@ -1,603 +0,0 @@ -/* - * -------------------------------------------------------------------------------------------------------------------- - * Example sketch/program showing An Arduino Door Access Control featuring RFID, EEPROM, Relay - * -------------------------------------------------------------------------------------------------------------------- - * This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid - * - * This example showing a complete Door Access Control System - - Simple Work Flow (not limited to) : - +---------+ -+----------------------------------->READ TAGS+^------------------------------------------+ -| +--------------------+ | -| | | | -| | | | -| +----v-----+ +-----v----+ | -| |MASTER TAG| |OTHER TAGS| | -| +--+-------+ ++-------------+ | -| | | | | -| | | | | -| +-----v---+ +----v----+ +----v------+ | -| +------------+READ TAGS+---+ |KNOWN TAG| |UNKNOWN TAG| | -| | +-+-------+ | +-----------+ +------------------+ | -| | | | | | | -| +----v-----+ +----v----+ +--v--------+ +-v----------+ +------v----+ | -| |MASTER TAG| |KNOWN TAG| |UNKNOWN TAG| |GRANT ACCESS| |DENY ACCESS| | -| +----------+ +---+-----+ +-----+-----+ +-----+------+ +-----+-----+ | -| | | | | | -| +----+ +----v------+ +--v---+ | +---------------> -+-------+EXIT| |DELETE FROM| |ADD TO| | | - +----+ | EEPROM | |EEPROM| | | - +-----------+ +------+ +-------------------------------+ - - * - * Use a Master Card which is act as Programmer then you can able to choose card holders who will granted access or not - * - * **Easy User Interface** - * - * Just one RFID tag needed whether Delete or Add Tags. You can choose to use Leds for output or Serial LCD module to inform users. - * - * **Stores Information on EEPROM** - * - * Information stored on non volatile Arduino's EEPROM memory to preserve Users' tag and Master Card. No Information lost - * if power lost. EEPROM has unlimited Read cycle but roughly 100,000 limited Write cycle. - * - * **Security** - * To keep it simple we are going to use Tag's Unique IDs. It's simple and not hacker proof. - * - * @license Released into the public domain. - * - * Typical pin layout used: - * ----------------------------------------------------------------------------------------- - * MFRC522 Arduino Arduino Arduino Arduino Arduino - * Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro - * Signal Pin Pin Pin Pin Pin Pin - * ----------------------------------------------------------------------------------------- - * RST/Reset RST 9 5 D9 RESET/ICSP-5 RST - * SPI SS SDA(SS) 10 53 D10 10 10 - * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16 - * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14 - * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15 - */ - -#include // We are going to read and write PICC's UIDs from/to EEPROM -#include // RC522 Module uses SPI protocol -#include // Library for Mifare RC522 Devices -#include "ShiftedLCD.h" // Arduino Library for 74HC595 Shift Register using SPI - -/* - Instead of a Relay you may want to use a servo. Servos can lock and unlock door locks too - Relay will be used by default -*/ - -// #include - -/* - For visualizing whats going on hardware we need some leds and to control door lock a relay and a wipe button - (or some other hardware) Used common anode led,digitalWriting HIGH turns OFF led Mind that if you are going - to use common cathode led or just seperate leds, simply comment out #define COMMON_ANODE, -*/ - -#define COMMON_ANODE - -#ifdef COMMON_ANODE -#define LED_ON LOW -#define LED_OFF HIGH -#else -#define LED_ON HIGH -#define LED_OFF LOW -#endif - -#define redLed 7 // Set Led Pins -#define greenLed 6 -#define blueLed 5 - -#define relay 4 // Set Relay Pin -#define wipeB 3 // Button pin for WipeMode - -boolean match = false; // initialize card match to false -boolean programMode = false; // initialize programming mode to false -boolean replaceMaster = false; - -int successRead; // Variable integer to keep if we have Successful Read from Reader - -byte storedCard[4]; // Stores an ID read from EEPROM -byte readCard[4]; // Stores scanned ID read from RFID Module -byte masterCard[4]; // Stores master card's ID read from EEPROM - -// Create MFRC522 instance. -#define SS_PIN 10 -#define RST_PIN 9 -MFRC522 mfrc522(SS_PIN, RST_PIN); - -// Create LCD instance -LiquidCrystal lcd(8); - -///////////////////////////////////////// Setup /////////////////////////////////// -void setup() { - //Arduino Pin Configuration - pinMode(redLed, OUTPUT); - pinMode(greenLed, OUTPUT); - pinMode(blueLed, OUTPUT); - pinMode(wipeB, INPUT_PULLUP); // Enable pin's pull up resistor - pinMode(relay, OUTPUT); - //Be careful how relay circuit behave on while resetting or power-cycling your Arduino - digitalWrite(relay, HIGH); // Make sure door is locked - digitalWrite(redLed, LED_OFF); // Make sure led is off - digitalWrite(greenLed, LED_OFF); // Make sure led is off - digitalWrite(blueLed, LED_OFF); // Make sure led is off - - //Protocol Configuration - Serial.begin(9600); // Initialize serial communications with PC - SPI.begin(); // MFRC522 Hardware uses SPI protocol - mfrc522.PCD_Init(); // Initialize MFRC522 Hardware - // set up the LCD's number of columns and rows: - lcd.begin(16, 2); - - //If you set Antenna Gain to Max it will increase reading distance - //mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); - - Serial.println(F("Access Control Example v0.1")); // For debugging purposes - lcd.print("Access Controlv3"); - ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details - - //Wipe Code - If the Button (wipeB) Pressed while setup run (powered on) it wipes EEPROM - if (digitalRead(wipeB) == LOW) { // when button pressed pin should get low, button connected to ground - lcd.clear(); - lcd.print("WipeB is Pressed"); - digitalWrite(redLed, LED_ON); // Red Led stays on to inform user we are going to wipe - Serial.println(F("Wipe Button Pressed")); - Serial.println(F("You have 15 seconds to Cancel")); - Serial.println(F("This will be remove all records and cannot be undone")); - delay(3000); - lcd.clear(); - lcd.print("EEPROM will be"); - lcd.setCursor(0,1); - lcd.print("Wiped in 15 sec"); - delay(12000); // Give user enough time to cancel operation - if (digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM - lcd.clear(); - lcd.print("Wiping EEPROM.."); - Serial.println(F("Starting Wiping EEPROM")); - for (int x = 0; x < EEPROM.length(); x = x + 1) { //Loop end of EEPROM address - if (EEPROM.read(x) == 0) { //If EEPROM address 0 - // do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM - } - else { - EEPROM.write(x, 0); // if not write 0 to clear, it takes 3.3mS - } - } - lcd.clear(); - lcd.print("EEPROM Wiped"); - Serial.println(F("EEPROM Successfully Wiped")); - digitalWrite(redLed, LED_OFF); // visualize a successful wipe - delay(200); - digitalWrite(redLed, LED_ON); - delay(200); - digitalWrite(redLed, LED_OFF); - delay(200); - digitalWrite(redLed, LED_ON); - delay(200); - digitalWrite(redLed, LED_OFF); - } - else { - lcd.clear(); - lcd.print("Wiping Cancelled"); - Serial.println(F("Wiping Cancelled")); // Show some feedback that the wipe button did not pressed for 15 seconds - digitalWrite(redLed, LED_OFF); - } - } - // Check if master card defined, if not let user choose a master card - // This also useful to just redefine the Master Card - // You can keep other EEPROM records just write other than 143 to EEPROM address 1 - // EEPROM address 1 should hold magical number which is '143' - if (EEPROM.read(1) != 143) { - lcd.clear(); - lcd.print("No Master Card"); - lcd.setCursor(0,1); - lcd.print("Scan to define"); - Serial.println(F("No Master Card Defined")); - Serial.println(F("Scan A PICC to Define as Master Card")); - do { - successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 - digitalWrite(blueLed, LED_ON); // Visualize Master Card need to be defined - delay(200); - digitalWrite(blueLed, LED_OFF); - delay(200); - } - while (!successRead); // Program will not go further while you not get a successful read - for ( int j = 0; j < 4; j++ ) { // Loop 4 times - EEPROM.write( 2 + j, readCard[j] ); // Write scanned PICC's UID to EEPROM, start from address 3 - } - EEPROM.write(1, 143); // Write to EEPROM we defined Master Card. - Serial.println(F("Master Card Defined")); - } - Serial.println(F("-------------------")); - Serial.println(F("Master Card's UID")); - for ( int i = 0; i < 4; i++ ) { // Read Master Card's UID from EEPROM - masterCard[i] = EEPROM.read(2 + i); // Write it to masterCard - Serial.print(masterCard[i], HEX); - } - Serial.println(""); - Serial.println(F("-------------------")); - Serial.println(F("Everything Ready")); - Serial.println(F("Waiting PICCs to be scanned")); - cycleLeds(); // Everything ready lets give user some feedback by cycling leds - lcd.clear(); - lcd.print("System is Ready"); - lcd.setCursor(0, 1); - lcd.print("Waiting PICCs"); -} - - -///////////////////////////////////////// Main Loop /////////////////////////////////// -void loop () { - do { - successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 - // When device is in use if wipe button pressed for 10 seconds initialize Master Card wiping - if (digitalRead(wipeB) == LOW) { // Check if button is pressed - lcd.clear(); - lcd.print("WipeB is Pressed"); - lcd.setCursor(0, 1); - lcd.print("Master Card Wipe"); - // Visualize normal operation is iterrupted by pressing wipe button Red is like more Warning to user - digitalWrite(redLed, LED_ON); // Make sure led is off - digitalWrite(greenLed, LED_OFF); // Make sure led is off - digitalWrite(blueLed, LED_OFF); // Make sure led is off - // Give some feedback - Serial.println(F("Wipe Button Pressed")); - Serial.println(F("Master Card will be Erased! in 10 seconds")); - delay(10000); // Wait 10 seconds to see user still wants to wipe - if (digitalRead(wipeB) == LOW) { - EEPROM.write(1, 0); // Reset Magic Number. - lcd.clear(); - lcd.print("Wiped. Please"); - lcd.setCursor(0, 1); - lcd.print("Reset Device"); - Serial.println(F("Restart device to re-program Master Card")); - while (1); - } - else { - lcd.clear(); - lcd.print("Cancelled"); - lcd.setCursor(0, 1); - lcd.print("Waiting PICCs"); - Serial.println(F("Cancelled")); - } - } - if (programMode) { - cycleLeds(); // Program Mode cycles through Red Green Blue waiting to read a new card - } - else { - normalModeOn(); // Normal mode, blue Power LED is on, all others are off - } - } - while (!successRead); //the program will not go further while you are not getting a successful read - if (programMode) { - if ( isMaster(readCard) ) { //When in program mode check First If master card scanned again to exit program mode - Serial.println(F("Master Card Scanned")); - Serial.println(F("Exiting Program Mode")); - Serial.println(F("-----------------------------")); - lcd.clear(); - lcd.print("Exited from"); - lcd.setCursor(0,1); - lcd.print("Program Mode"); - programMode = false; - return; - } - else { - if ( findID(readCard) ) { // If scanned card is known delete it - Serial.println(F("I know this PICC, removing...")); - deleteID(readCard); - lcd.setCursor(9,1); - lcd.print("Removed"); - Serial.println("-----------------------------"); - Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); - } - else { // If scanned card is not known add it - Serial.println(F("I do not know this PICC, adding...")); - writeID(readCard); - lcd.setCursor(10,1); - lcd.print("Added"); - Serial.println(F("-----------------------------")); - Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); - } - } - } - else { - if ( isMaster(readCard)) { // If scanned card's ID matches Master Card's ID - enter program mode - programMode = true; - lcd.clear(); - lcd.print("Program Mode"); - lcd.setCursor(0,1); - lcd.print("Add/Remove Cards"); - Serial.println(F("Hello Master - Entered Program Mode")); - int count = EEPROM.read(0); // Read the first Byte of EEPROM that - Serial.print(F("I have ")); // stores the number of ID's in EEPROM - Serial.print(count); - Serial.print(F(" record(s) on EEPROM")); - Serial.println(""); - Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); - Serial.println(F("Scan Master Card again to Exit Program Mode")); - Serial.println(F("-----------------------------")); - } - else { - if ( findID(readCard) ) { // If not, see if the card is in the EEPROM - lcd.setCursor(3,1); - lcd.print("XXXXX Granted"); - Serial.println(F("Welcome, You shall pass")); - granted(300); // Open the door lock for 300 ms - } - else { // If not, show that the ID was not valid - lcd.setCursor(10,1); - lcd.print("Denied"); - Serial.println(F("You shall not pass")); - denied(); - } - } - } -} - -///////////////////////////////////////// Access Granted /////////////////////////////////// -void granted (int setDelay) { - digitalWrite(blueLed, LED_OFF); // Turn off blue LED - digitalWrite(redLed, LED_OFF); // Turn off red LED - digitalWrite(greenLed, LED_ON); // Turn on green LED - digitalWrite(relay, LOW); // Unlock door! - delay(setDelay); // Hold door lock open for given seconds - digitalWrite(relay, HIGH); // Relock door - delay(1000); // Hold green LED on for a second -} - -///////////////////////////////////////// Access Denied /////////////////////////////////// -void denied() { - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_ON); // Turn on red LED - delay(1000); -} - - -///////////////////////////////////////// Get PICC's UID /////////////////////////////////// -int getID() { - // Getting ready for Reading PICCs - if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue - return 0; - } - if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue - return 0; - } - // There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC - // I think we should assume every PICC as they have 4 byte UID - // Until we support 7 byte PICCs - Serial.println(F("Scanned PICC's UID:")); - lcd.clear(); - lcd.print("PICC's UID:"); - lcd.setCursor(0,1); - for (int i = 0; i < 4; i++) { // - readCard[i] = mfrc522.uid.uidByte[i]; - Serial.print(readCard[i], HEX); - lcd.print(readCard[i], HEX); - } - Serial.println(""); - mfrc522.PICC_HaltA(); // Stop reading - return 1; -} - -void ShowReaderDetails() { - // Get the MFRC522 software version - byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); - Serial.print(F("MFRC522 Software Version: 0x")); - Serial.print(v, HEX); - if (v == 0x91) - Serial.print(F(" = v1.0")); - else if (v == 0x92) - Serial.print(F(" = v2.0")); - else - Serial.print(F(" (unknown),probably a chinese clone?")); - Serial.println(""); - // When 0x00 or 0xFF is returned, communication probably failed - if ((v == 0x00) || (v == 0xFF)) { - Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?")); - Serial.println(F("SYSTEM HALTED: Check connections.")); - lcd.clear(); - lcd.print("SYSTEM HALTED"); - lcd.setCursor(0, 1); - lcd.print("Check connection"); - // Visualize system is halted - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_ON); // Turn on red LED - while (true); // do not go further - } -} - -///////////////////////////////////////// Cycle Leds (Program Mode) /////////////////////////////////// -void cycleLeds() { - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); -} - -//////////////////////////////////////// Normal Mode Led /////////////////////////////////// -void normalModeOn () { - digitalWrite(blueLed, LED_ON); // Blue LED ON and ready to read card - digitalWrite(redLed, LED_OFF); // Make sure Red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure Green LED is off - digitalWrite(relay, HIGH); // Make sure Door is Locked -} - -//////////////////////////////////////// Read an ID from EEPROM ////////////////////////////// -void readID( int number ) { - int start = (number * 4 ) + 2; // Figure out starting position - for ( int i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes - storedCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array - } -} - -///////////////////////////////////////// Add ID to EEPROM /////////////////////////////////// -void writeID( byte a[] ) { - if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before! - int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards - int start = ( num * 4 ) + 6; // Figure out where the next slot starts - num++; // Increment the counter by one - EEPROM.write( 0, num ); // Write the new count to the counter - for ( int j = 0; j < 4; j++ ) { // Loop 4 times - EEPROM.write( start + j, a[j] ); // Write the array values to EEPROM in the right position - } - successWrite(); - Serial.println(F("Succesfully added ID record to EEPROM")); - } - else { - failedWrite(); - Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); - } -} - -///////////////////////////////////////// Remove ID from EEPROM /////////////////////////////////// -void deleteID( byte a[] ) { - if ( !findID( a ) ) { // Before we delete from the EEPROM, check to see if we have this card! - failedWrite(); // If not - Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); - } - else { - int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards - int slot; // Figure out the slot number of the card - int start; // = ( num * 4 ) + 6; // Figure out where the next slot starts - int looping; // The number of times the loop repeats - int j; - int count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards - slot = findIDSLOT( a ); // Figure out the slot number of the card to delete - start = (slot * 4) + 2; - looping = ((num - slot) * 4); - num--; // Decrement the counter by one - EEPROM.write( 0, num ); // Write the new count to the counter - for ( j = 0; j < looping; j++ ) { // Loop the card shift times - EEPROM.write( start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM - } - for ( int k = 0; k < 4; k++ ) { // Shifting loop - EEPROM.write( start + j + k, 0); - } - successDelete(); - Serial.println(F("Succesfully removed ID record from EEPROM")); - } -} - -///////////////////////////////////////// Check Bytes /////////////////////////////////// -boolean checkTwo ( byte a[], byte b[] ) { - if ( a[0] != 0 ) // Make sure there is something in the array first - match = true; // Assume they match at first - for ( int k = 0; k < 4; k++ ) { // Loop 4 times - if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail - match = false; - } - if ( match ) { // Check to see if if match is still true - return true; // Return true - } - else { - return false; // Return false - } -} - -///////////////////////////////////////// Find Slot /////////////////////////////////// -int findIDSLOT( byte find[] ) { - int count = EEPROM.read(0); // Read the first Byte of EEPROM that - for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry - readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] - if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM - // is the same as the find[] ID card passed - return i; // The slot number of the card - break; // Stop looking we found it - } - } -} - -///////////////////////////////////////// Find ID From EEPROM /////////////////////////////////// -boolean findID( byte find[] ) { - int count = EEPROM.read(0); // Read the first Byte of EEPROM that - for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry - readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] - if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM - return true; - break; // Stop looking we found it - } - else { // If not, return false - } - } - return false; -} - -///////////////////////////////////////// Write Success to EEPROM /////////////////////////////////// -// Flashes the green LED 3 times to indicate a successful write to EEPROM -void successWrite() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); -} - -///////////////////////////////////////// Write Failed to EEPROM /////////////////////////////////// -// Flashes the red LED 3 times to indicate a failed write to EEPROM -void failedWrite() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); -} - -///////////////////////////////////////// Success Remove UID From EEPROM /////////////////////////////////// -// Flashes the blue LED 3 times to indicate a success delete to EEPROM -void successDelete() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); -} - -////////////////////// Check readCard IF is masterCard /////////////////////////////////// -// Check to see if the ID passed is the master programing card -boolean isMaster( byte test[] ) { - if ( checkTwo( test, masterCard ) ) - return true; - else - return false; -} diff --git a/LICENSE b/LICENSE deleted file mode 100644 index d159169..0000000 --- a/LICENSE +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/NoSerial/Leds.ino b/NoSerial/Leds.ino deleted file mode 100644 index 2b95093..0000000 --- a/NoSerial/Leds.ino +++ /dev/null @@ -1,95 +0,0 @@ -///////////////////////////////////////// Write Success to EEPROM /////////////////////////////////// -// Flashes the green LED 3 times to indicate a successful write to EEPROM -void greenBlink() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - delay(200); -} - -///////////////////////////////////////// Write Failed to EEPROM /////////////////////////////////// -// Flashes the red LED 3 times to indicate a failed write to EEPROM -void redBlink() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - delay(200); -} - -///////////////////////////////////////// Success Remove UID From EEPROM /////////////////////////////////// -// Flashes the blue LED 3 times to indicate a success delete to EEPROM -void blueBlink() { - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); -} - - -///////////////////////////////////////// Cycle Leds (Program Mode) /////////////////////////////////// -void cycleLeds() { - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_ON); // Make sure green LED is on - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); - digitalWrite(redLed, LED_OFF); // Make sure red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_ON); // Make sure blue LED is on - delay(200); - digitalWrite(redLed, LED_ON); // Make sure red LED is on - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - delay(200); -} - -//////////////////////////////////////// Normal Mode Led /////////////////////////////////// -void blueSolid () { - digitalWrite(blueLed, LED_ON); // Blue LED ON and ready to read card - digitalWrite(redLed, LED_OFF); // Make sure Red LED is off - digitalWrite(greenLed, LED_OFF); // Make sure Green LED is off -} - -void greenSolid () { - digitalWrite(blueLed, LED_OFF); // Turn off blue LED - digitalWrite(redLed, LED_OFF); // Turn off red LED - digitalWrite(greenLed, LED_ON); // Turn on green LED - delay(1000); // Hold green LED on for a second -} - -///////////////////////////////////////// Access Denied /////////////////////////////////// -void redSolid() { - digitalWrite(greenLed, LED_OFF); // Make sure green LED is off - digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off - digitalWrite(redLed, LED_ON); // Turn on red LED - delay(1000); -} diff --git a/NoSerial/NoSerial.ino b/NoSerial/NoSerial.ino deleted file mode 100644 index 8f0410a..0000000 --- a/NoSerial/NoSerial.ino +++ /dev/null @@ -1,390 +0,0 @@ -/* - Arduino RFID Access Control - - Security ! - - To keep it simple we are going to use Tag's Unique IDs - as only method of Authenticity. It's simple and not hacker proof. - If you need security, don't use it unless you modify the code - - Copyright (C) 2015 Omer Siar Baysal - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -*/ - -#include // RC522 Module uses SPI protocol -#include // Ethernet Library Wiznet -#include // Library for Mifare RC522 Devices -#include // We are going to read and write PICC's UIDs from/to SD - - - -/* - Instead of a Relay maybe you want to use a servo - Servos can lock and unlock door locks too - There are examples out there. -*/ - -// #include - -/* - For visualizing whats going on hardware - we need some leds and - to control door lock a relay and a wipe button - (or some other hardware) - Used common anode led,digitalWriting HIGH turns OFF led - Mind that if you are going to use common cathode led or - just seperate leds, simply comment out #define COMMON_ANODE, - */ - -#define COMMON_ANODE - -#ifdef COMMON_ANODE -#define LED_ON LOW -#define LED_OFF HIGH -#else -#define LED_ON HIGH -#define LED_OFF LOW -#endif - -#define redLed 2 // Set Led Pins -#define greenLed 6 -#define blueLed 5 - -#define relay 3 // Set Relay Pin - -#define sdPin 4 // Set SD Pin - -boolean match = false; // initialize card match to false -boolean programMode = false; // initialize programming mode to false - -int successRead; // Variable integer to keep if we have Successful Read from Reader - -byte readCard[4]; // Stores scanned ID read from RFID Module -byte masterCard[4]; // Stores master card's ID - -char filename[] = "XXXXXXXX.DAT"; // Stores variable filename -char extension[] = "DAT"; // sometimes the extension gets modified - - -/* - We need to define MFRC522's pins and create instance - Pin layout should be as follows (on Arduino Uno): - MOSI: Pin 11 / ICSP-4 - MISO: Pin 12 / ICSP-1 - SCK : Pin 13 / ICSP-3 - SDA : (Configurable) - RST : Not Needed - - */ - -#define SS_PIN 9 -#define RST_PIN 8 -MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. - -/************ ETHERNET STUFF ************/ -// Initialize the Ethernet server library -// with the IP address and port you want to use -// (port 80 is default for HTTP): -byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; -IPAddress ip(192, 168, 1, 245); -EthernetServer server(80); - - -///////////////////////////////////////// Setup /////////////////////////////////// -void setup() { - //Arduino Pin Configuration - pinMode(redLed, OUTPUT); - pinMode(greenLed, OUTPUT); - pinMode(blueLed, OUTPUT); - pinMode(relay, OUTPUT); // Be careful how relay circuit behave on while resetting or power-cycling your Arduino - digitalWrite(relay, HIGH); // Make sure door is locked - digitalWrite(redLed, LED_OFF); // Make sure led is off - digitalWrite(greenLed, LED_OFF); // Make sure led is off - digitalWrite(blueLed, LED_OFF); // Make sure led is off - - //Initialize - - - SPI.begin(); // MFRC522 Hardware uses SPI protocol - Ethernet.begin(mac, ip); - server.begin(); - - - if (!SD.begin(sdPin)) { // Initialize SD Hardware - while (true); // Do not go further - } - mfrc522.PCD_Init(); // Initialize MFRC522 Hardware - //ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details - - //If you set Antenna Gain to Max it will increase reading distance - //mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); - - checkMaster(); // Check if masterCard defined - cycleLeds(); // Lets give user some feedback that hardware initialized by cycling leds -} - - - -///////////////////////////////////////// Main Loop /////////////////////////////////// -void loop () { - do { - checkClient(); - successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 - if (programMode) { - cycleLeds(); // Program Mode cycles through RGB waiting to read a new card - } - else { - blueSolid(); // Normal mode, blue Power LED is on, all others are off - } - } - while (!successRead); // the program will not go further while you not get a successful read - if (programMode) { - if (isMaster(readCard)) { // If master card scanned again exit program mode - - programMode = false; - return; - } - else { - if ( findID() ) { // If scanned card is known delete it - - removeID(); - - } - else { // If scanned card is not known add it - - writeID(); - - } - } - } - else { - if (isMaster(readCard)) { // If scanned card's ID matches Master Card's ID enter program mode - programMode = true; - - } - else { - if (findID()) { // If not, check if we can find it - - granted(300); // Open the door lock for 300 ms - } - else { // If not, show that the ID was not valid - - denied(); - } - } - } -} - -void checkClient() { - - EthernetClient client = server.available(); // try to get client - if (client) { // got client? - boolean currentLineIsBlank = true; - while (client.connected()) { - if (client.available()) { // client data available to read - char c = client.read(); // read 1 byte (character) from client - // last line of client request is blank and ends with \n - // respond to client only after last line received - if (c == '\n' && currentLineIsBlank) { - // send a standard http response header - client.println("HTTP/1.1 200 OK"); - client.println("Content-Type: text/html"); - client.println("Connection: close"); - client.println(); - File webFile = SD.open("/HTML/index.htm"); // open web page file - if (webFile) { - while (webFile.available()) { - client.write(webFile.read()); // send web page to client - } - webFile.close(); - } - break; - } - // every line of text received from the client ends with \r\n - if (c == '\n') { - // last character on line of received text - // starting new line with next character read - currentLineIsBlank = true; - } - else if (c != '\r') { - // a text character was received from client - currentLineIsBlank = false; - } - } // end if (client.available()) - } // end while (client.connected()) - delay(1); // give the web browser time to receive the data - client.stop(); // close the connection - } // end if (client) -} - -void getFilename() { // We will store UIDs as files on SD card - sprintf(filename, "%02x%02x%02x%02x.%s", readCard[0], readCard[1], // Convert readCard data to char and append extension - readCard[2], readCard[3], extension); -} - -boolean findID () { // Check If we can find UID's specific file - File fileopen = SD.open(filename); - if (fileopen) { - fileopen.close(); // Found it close - return true; - } - else { // If not, return false - } - return false; -} - -void writeID () { - File filewrite = SD.open(filename, FILE_WRITE); - filewrite.close(); - if (SD.exists(filename)) { - - greenBlink(); - } - else { - - redBlink(); - } -} - -void removeID () { - SD.remove(filename); - if (SD.exists(filename)) { - - redBlink(); - } - else { - - blueBlink(); - } -} - -///////////////////////////////////////// Access Granted /////////////////////////////////// -void granted (int setDelay) { - - delay(setDelay); // Hold door lock open for given seconds - - greenSolid(); -} - -///////////////////////////////////////// Access Denied /////////////////////////////////// -void denied() { - redSolid(); -} - - -///////////////////////////////////////// Get PICC's UID /////////////////////////////////// -int getID() { - // Getting ready for Reading PICCs - if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue - return 0; - } - if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue - return 0; - } - // There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC - // I think we should assume every PICC as they have 4 byte UID - // Until we support 7 byte PICCs - - for (int i = 0; i < 4; i++) { // - readCard[i] = mfrc522.uid.uidByte[i]; - - } - - mfrc522.PICC_HaltA(); // Stop reading - getFilename(); // Get data ready - return 1; -} - -void checkMaster() { - if (SD.exists("master.dat")) { // Check if we have master.dat on SD card - - File masterfile = SD.open("master.dat"); // Open file - for (int i = 0; i < 4; i++) { // Loop 4 times to get 4 bytes - readCard[i] = masterfile.read(); - - masterCard[i] = readCard[i]; // Prepare bytes for future comparing - } - - masterfile.close(); // Close file - } - else { - - do { - successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 - blueBlink(); // Visualize Master Card need to be defined - } - while (!successRead); //the program will not go further while you not get a successful read - File masterfile = SD.open("master.dat", FILE_WRITE); - if (masterfile) { - - masterfile.write(readCard, 4); - // close the file: - masterfile.close(); - - } else { - // if the file didn't open, print an error: - - } - } -} - -/* -void ShowReaderDetails() { - // Get the MFRC522 software version - byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); - Serial.print(F("MFRC522 Software Version: 0x")); - Serial.print(v, HEX); - if (v == 0x91) - Serial.print(F(" = v1.0")); - else if (v == 0x92) - Serial.print(F(" = v2.0")); - else - Serial.print(F(" (unknown)")); - Serial.println(""); - // When 0x00 or 0xFF is returned, communication probably failed - if ((v == 0x00) || (v == 0xFF)) { - Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?")); - while (true); // do not go further - } -} -*/ - -///////////////////////////////////////// Check Bytes /////////////////////////////////// -boolean checkTwo ( byte a[], byte b[] ) { - if ( a[0] != NULL ) // Make sure there is something in the array first - match = true; // Assume they match at first - for ( int k = 0; k < 4; k++ ) { // Loop 4 times - if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail - match = false; - } - if ( match ) { // Check to see if if match is still true - return true; // Return true - } - else { - return false; // Return false - } -} - -////////////////////// Check readCard IF is masterCard /////////////////////////////////// -// Check to see if the ID passed is the master programing card -boolean isMaster( byte test[] ) { - if ( checkTwo( test, masterCard ) ) - return true; - else - return false; -} - diff --git a/README.md b/README.md deleted file mode 100644 index 87fdcbb..0000000 --- a/README.md +++ /dev/null @@ -1,31 +0,0 @@ -Arduino RC522 RFID Access Control -======= -July/2014 Omer Siar Baysal - --------- - -Arduino RFID Access Control using a RC522 RFID -reader with SPI interface on your Arduino - -For now there is 3 version of Access Control - -**EEPROM Version** - -Storing data on EEPROM, Stable, Basic System - -**SD Version - Work In Progress** - -Storing data on SD Card, more features will be added like -USER management -Tracking with Real Time Clock - -**Embedded System - Work In Progress** - -Complete RFID solution with -Networked Web Interface -USER management -Tracking with Real Time Clock -Cross-Platform Management Application - -More info on: -http://forum.arduino.cc/index.php?topic=256260 \ No newline at end of file diff --git a/SD/AccessControl.ino b/SD/AccessControl.ino deleted file mode 100644 index 1496226..0000000 --- a/SD/AccessControl.ino +++ /dev/null @@ -1,210 +0,0 @@ -/* - Arduino RFID Access Control - - Security ! - - To keep it simple we are going to use Tag's Unique IDs - as only method of Authenticity. It's simple and not hacker proof. - If you need security, don't use it unless you modify the code - - Copyright (C) 2015 Omer Siar Baysal - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -*/ - -#include // RC522 Module uses SPI protocol -#include // Library for Mifare RC522 Devices -#include // We are going to read and write PICC's UIDs from/to SD - -#include "Pinning.h" // Include our Pinnings -#include "Settings.h" // Include our variable Settings - -/* - Maybe you want to use a servo on the output pin - Servos can lock and unlock door locks too - There are examples out there. -*/ - -// #include or -// #include - -boolean match = false; // initialize card match to false -boolean programMode = false; // initialize programming mode to false - -int successRead; // Variable integer to keep if we have Successful Read from Reader - -byte readCard[4]; // Stores scanned ID read from RFID Module -byte masterCard[4]; // Stores master card's ID - -char username[8] = {'\0'}; -char filename[] = "XXXXXXXXXXXXXXX.DAT"; // Stores variable filename -char extension[] = "DAT"; // sometimes the extension gets modified -char dir[] = "/PICCS/"; - -MFRC522 mfrc522(RFID_SS_PIN, RFID_RST_PIN); // Create MFRC522 instance. - -///////////////////////////////////////// Setup /////////////////////////////////// -void setup() { - //Arduino Pin Configuration - pinMode(LED_RED, OUTPUT); - pinMode(LED_GREEN, OUTPUT); - pinMode(LED_BLUE, OUTPUT); - pinMode(OUTPUT_PIN, OUTPUT); // Be careful how output circuit behave on while resetting or power-cycling your Arduino - digitalWrite(OUTPUT_PIN, OUTPUT_OFF); // Make sure output is off - digitalWrite(LED_RED, LED_OFF); // Make sure led is off - digitalWrite(LED_GREEN, LED_OFF); // Make sure green is off - digitalWrite(LED_BLUE, LED_OFF); // Make sure blue is off - - //Initialize - Serial.begin(57600); // Initialize serial communications with PC - Serial.println(F("Access Control v4.6_SD")); // For debugging purposes - SPI.begin(); // MFRC522 and SD Card Hardware uses SPI protocol - if (!SD.begin(SD_SS_PIN)) { // Initialize SD Hardware - Serial.println(F("SD initialization failed!")); // Could not initialize - redSolid(); - while (true); // Do not go further - } - Serial.println(F("SD initialization done.")); // Yay all SPI slaves work - mfrc522.PCD_Init(); // Initialize MFRC522 Hardware - ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details - - //If you set Antenna Gain to Max it will increase reading distance - //mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); - - checkMaster(); // Check if masterCard defined - Serial.println(F("Everything Ready")); - Serial.println(F("Waiting PICCs to be scanned")); - cycleLeds(); // Lets give user some feedback that hardware initialized by cycling leds -} - - - -///////////////////////////////////////// Main Loop /////////////////////////////////// -void loop () { - do { - successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 - if (programMode) { - cycleLeds(); // Program Mode cycles through RGB waiting to read a new card - } - else { - blueSolid(); // Normal mode, blue Power LED is on, all others are off - } - } - while (!successRead); // the program will not go further while you not get a successful read - if (programMode) { - // Print the control menu: - printMenu(); - // Then wait for any serial data to come in: - while (!Serial.available()); - // Once serial data is received, call parseMenu to act on it: - parseMenu(Serial.read()); - } - if (isMaster(readCard)) { // If scanned card's ID matches Master Card's ID enter program mode - Serial.println(F("Hello Master - Entered Program Mode")); - programMode = true; - } - else { - if (findID()) { // If not, check if we can find it - Serial.println(F("Welcome, You shall pass")); - granted(300); // Open the door lock for 300 ms - } - else { // If not, show that the ID was not valid - Serial.println(F("You shall not pass")); - denied(); - } - } -} - -void getFilename() { // We will store UIDs as files on SD card - sprintf(filename, "%s%02x%02x%02x%02x.%s", dir, readCard[0], readCard[1], // Convert readCard data to char and append extension - readCard[2], readCard[3], extension); -} - -boolean findID () { // Check If we can find UID's specific file - File fileopen = SD.open(filename); - if (fileopen) { - fileopen.close(); // Found it close - return true; - } - else { // If not, return false - } - return false; -} - -void writeID (char* user) { - File filewrite = SD.open(filename, FILE_WRITE); - filewrite.print(user); - filewrite.close(); - if (SD.exists(filename)) { - Serial.println(F("Succesfully added ID record")); - greenBlink(3); - } - else { - Serial.println(F("Failed to add record")); - redBlink(3); - } -} - -void removeID () { - SD.remove(filename); - if (SD.exists(filename)) { - Serial.println(F("Failed to remove. Record still exists")); - redBlink(3); - } - else { - Serial.println(F("Succesfully removed ID record")); - blueBlink(3); - } -} - -///////////////////////////////////////// Access Granted /////////////////////////////////// -void granted (int setDelay) { - digitalWrite(OUTPUT_PIN, LOW); // Unlock door! - delay(setDelay); // Hold door lock open for given seconds - digitalWrite(OUTPUT_PIN, HIGH); // Relock door - greenSolid(); -} - -///////////////////////////////////////// Access Denied /////////////////////////////////// -void denied() { - redSolid(); -} - - -///////////////////////////////////////// Check Bytes /////////////////////////////////// -boolean checkTwo ( byte a[], byte b[] ) { - if ( a[0] != NULL ) // Make sure there is something in the array first - match = true; // Assume they match at first - for ( int k = 0; k < 4; k++ ) { // Loop 4 times - if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail - match = false; - } - if ( match ) { // Check to see if if match is still true - return true; // Return true - } - else { - return false; // Return false - } -} - -////////////////////// Check readCard IF is masterCard /////////////////////////////////// -// Check to see if the ID passed is the master programing card -boolean isMaster( byte test[] ) { - if ( checkTwo( test, masterCard ) ) - return true; - else - return false; -} diff --git a/SD/Leds.ino b/SD/Leds.ino deleted file mode 100644 index a165802..0000000 --- a/SD/Leds.ino +++ /dev/null @@ -1,81 +0,0 @@ -///////////////////////////////////////// Write Success to EEPROM /////////////////////////////////// -// Flashes the green LED n-times to indicate a successful write to EEPROM -void greenBlink(uint8_t n) { - digitalWrite(LED_BLUE, LED_OFF); // Make sure blue LED is off - digitalWrite(LED_RED, LED_OFF); // Make sure red LED is off - digitalWrite(LED_GREEN, LED_OFF); // Make sure green LED is off - bool state = true; - for (int i = 0; i < (n*2); i++) { - digitalWrite(LED_BLUE, state); // Toggle green LED - state = !state; - delay(BLINK_DELAY); - } -} - -///////////////////////////////////////// Write Failed to EEPROM /////////////////////////////////// -// Flashes the red LED n-times to indicate a failed write to EEPROM -void redBlink(uint8_t n) { - digitalWrite(LED_BLUE, LED_OFF); // Make sure blue LED is off - digitalWrite(LED_RED, LED_OFF); // Make sure red LED is off - digitalWrite(LED_GREEN, LED_OFF); // Make sure green LED is off - bool state = true; - for (int i = 0; i < (n*2); i++) { - digitalWrite(LED_RED, state); // Toggle red LED - state = !state; - delay(BLINK_DELAY); - } -} - -///////////////////////////////////////// Success Remove UID From EEPROM /////////////////////////////////// -// Flashes the blue LED n-times to indicate a success delete to EEPROM -void blueBlink(uint8_t n) { - digitalWrite(LED_BLUE, LED_OFF); // Make sure blue LED is off - digitalWrite(LED_RED, LED_OFF); // Make sure red LED is off - digitalWrite(LED_GREEN, LED_OFF); // Make sure green LED is off - bool state = true; - for (int i = 0; i < (n*2); i++) { - digitalWrite(LED_BLUE, state); // Toggle blue LED - state = !state; - delay(BLINK_DELAY); - } -} - - -///////////////////////////////////////// Cycle Leds (Program Mode) /////////////////////////////////// -void cycleLeds() { - digitalWrite(LED_RED, LED_OFF); // Make sure red LED is off - digitalWrite(LED_GREEN, LED_ON); // Make sure green LED is on - digitalWrite(LED_BLUE, LED_OFF); // Make sure blue LED is off - delay(CYCLE_DELAY); - digitalWrite(LED_RED, LED_OFF); // Make sure red LED is off - digitalWrite(LED_GREEN, LED_OFF); // Make sure green LED is off - digitalWrite(LED_BLUE, LED_ON); // Make sure blue LED is on - delay(CYCLE_DELAY); - digitalWrite(LED_RED, LED_ON); // Make sure red LED is on - digitalWrite(LED_GREEN, LED_OFF); // Make sure green LED is off - digitalWrite(LED_BLUE, LED_OFF); // Make sure blue LED is off - delay(CYCLE_DELAY); -} - -//////////////////////////////////////// Normal Mode Led /////////////////////////////////// -void blueSolid () { - digitalWrite(LED_BLUE, LED_ON); // Blue LED ON and ready to read card - digitalWrite(LED_RED, LED_OFF); // Make sure Red LED is off - digitalWrite(LED_GREEN, LED_OFF); // Make sure Green LED is off - delay(SOLID_DELAY); // Hold blue LED on -} - -void greenSolid () { - digitalWrite(LED_BLUE, LED_OFF); // Turn off blue LED - digitalWrite(LED_RED, LED_OFF); // Turn off red LED - digitalWrite(LED_GREEN, LED_ON); // Turn on green LED - delay(SOLID_DELAY); // Hold green LED on -} - -///////////////////////////////////////// Access Denied /////////////////////////////////// -void redSolid() { - digitalWrite(LED_GREEN, LED_OFF); // Make sure green LED is off - digitalWrite(LED_BLUE, LED_OFF); // Make sure blue LED is off - digitalWrite(LED_RED, LED_ON); // Turn on red LED - delay(SOLID_DELAY); // Hold red LED on -} diff --git a/SD/Menu.ino b/SD/Menu.ino deleted file mode 100644 index e3a9fa0..0000000 --- a/SD/Menu.ino +++ /dev/null @@ -1,70 +0,0 @@ -void parseMenu(char c) { - switch (c) { - case '1': - Serial.println(F("Scan a PICC and Enter User Name")); - while (!Serial.available()) { - getID(); - } - if (findID()) { // If not, check if we can find it - Serial.println(F("This PICC Already Exists")); - Serial.print(F("User Name: ")); - Serial.println(F("This PICC Already Exists")); - File dataFile = SD.open(filename); - if (dataFile) { - while (dataFile.available()) { - Serial.write(dataFile.read()); - } - dataFile.close(); - } - Serial.println(F("You can change username")); - return; - } - for (byte i = 0; i < 7; i++) { - username[i] = Serial.read(); - } - writeID(username); - break; - case '2': - while (!Serial.available()) - - break; - case '3': - while (!Serial.available()) - - break; - case '4': - while (!Serial.available()) { - - } - break; - case '5': - programMode = false; - Serial.println(F("Quit Programming Mode")); - break; - case '6': - SD.remove("/SYS/master.dat"); - checkMaster(); - programMode = false; - Serial.println(F("Quit Programming Mode")); - checkMaster(); - break; - - } -} - -void printMenu() { - Serial.println(); - Serial.println(F("////////////////////////////////////////////")); - Serial.println(F("// Programming Menu //")); - Serial.println(F("////////////////////////////////////////////")); - Serial.println(); - Serial.println(F("1) Add a PICC")); - Serial.println(F("2) Remove a PICC")); - Serial.println(F("3) Change Username")); - Serial.println(F("4) Set Date and Time /not implemented")); - Serial.println(F("5) Exit Programming Mode")); - Serial.println(); - Serial.println(F("6) Change Master Tag")); - Serial.println(F("X) Delete All Tags /not implemented")); - Serial.println(); -} \ No newline at end of file diff --git a/SD/Pinning.h b/SD/Pinning.h deleted file mode 100644 index ab0ea80..0000000 --- a/SD/Pinning.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - PIN Definitions -*/ - -#define COMMON_ANODE // If Set the LEDs are connected with common anode - -#ifdef COMMON_ANODE -#define LED_ON LOW -#define LED_OFF HIGH -#else -#define LED_ON HIGH -#define LED_OFF LOW -#endif - -/* LED Pins - - For visualizing whats going on hardware - we need some leds and - to control door lock a relay and a wipe button - (or some other hardware) - Used common anode led,digitalWriting HIGH turns OFF led - Mind that if you are going to use common cathode led or - just seperate leds, simply comment out #define COMMON_ANODE, -*/ -#define LED_RED 2 // Set Red Led Pin -#define LED_GREEN 6 // Set Green Led Pin -#define LED_BLUE 5 // Set Blue Led Pin - -/* Output Pins */ -#define OUTPUT_PIN 8 // Set Output Pin (Relay/Servo/...) -#define OUTPUT_ON HIGH// Set Output ON State -#define OUTPUT_OFF LOW // Set Output OFF State - -/* SPI Slave Pins - - We need to define MFRC522's and SD Card pins and create instance - Pin layout should be as follows (on Arduino Uno): - MOSI: Pin 11 / ICSP-4 - MISO: Pin 12 / ICSP-1 - SCK : Pin 13 / ICSP-3 - - Mifare RC522 Reset Pin has to be connected to resolv issues with - broken/incomplete connections to PICCS - -*/ -#define SD_SS_PIN 2 // Set Slave Select Pin from SD Card -#define RFID_SS_PIN 10 // Set Slave Select Pin from Mifare RC522 Reader -#define RFID_RST_PIN 9 // Set Reset Pin from Mifare RC522 Reader - diff --git a/SD/RFID.ino b/SD/RFID.ino deleted file mode 100644 index bb6f19f..0000000 --- a/SD/RFID.ino +++ /dev/null @@ -1,83 +0,0 @@ -///////////////////////////////////////// Get PICC's UID /////////////////////////////////// -int getID() { - // Getting ready for Reading PICCs - if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue - return 0; - } - if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue - return 0; - } - // There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC - // I think we should assume every PICC as they have 4 byte UID - // Until we support 7 byte PICCs - Serial.print(F("Scanned PICC's UID: ")); - for (int i = 0; i < 4; i++) { // - readCard[i] = mfrc522.uid.uidByte[i]; - Serial.print(readCard[i], HEX); - } - Serial.println(""); - mfrc522.PICC_HaltA(); // Stop reading - getFilename(); // Get data ready - return 1; -} - -void checkMaster() { - if (SD.exists("/SYS/master.dat")) { // Check if we have master.dat on SD card - Serial.print(F("Master Card's UID: ")); // Since we have it print to serial - File masterfile = SD.open("/SYS/master.dat"); // Open file - for (int i = 0; i < 4; i++) { // Loop 4 times to get 4 bytes - readCard[i] = masterfile.read(); - Serial.print(readCard[i], HEX); // Actual serial printing of each byte - masterCard[i] = readCard[i]; // Prepare bytes for future comparing - } - Serial.println(""); - masterfile.close(); // Close file - } - else { - Serial.println(F("No Master Card Defined")); - Serial.println(F("Scan A PICC to Define as Master Card")); - do { - successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 - blueBlink(3); // Visualize Master Card need to be defined - } - while (!successRead); //the program will not go further while you not get a successful read - File masterfile = SD.open("/SYS/master.dat", FILE_WRITE); - if (masterfile) { - Serial.println(F("Writing to master.dat...")); - masterfile.write(readCard, 4); - for (int i = 0; i < 4; i++) { // Loop 4 times to get 4 bytes - readCard[i] = masterfile.read(); - - masterCard[i] = readCard[i]; // Prepare bytes for future comparing - } - // close the file: - masterfile.close(); - greenBlink(3); - Serial.println(F("Master Card successfuly defined")); - } else { - // if the file didn't open, print an error: - Serial.println(F("error creating master.dat")); - redBlink(3); - } - } -} - -void ShowReaderDetails() { - // Get the MFRC522 software version - byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); - Serial.print(F("MFRC522 Software Version: 0x")); - Serial.print(v, HEX); - if (v == 0x91) - Serial.print(F(" = v1.0")); - else if (v == 0x92) - Serial.print(F(" = v2.0")); - else - Serial.print(F(" (unknown)")); - Serial.println(""); - // When 0x00 or 0xFF is returned, communication probably failed - if ((v == 0x00) || (v == 0xFF)) { - Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?")); - redSolid(); - while (true); // do not go further - } -} \ No newline at end of file diff --git a/SD/Settings.h b/SD/Settings.h deleted file mode 100644 index 9c68373..0000000 --- a/SD/Settings.h +++ /dev/null @@ -1,4 +0,0 @@ -/* LED Flash, Cycle and Solid State Delays defined here */ -#define BLINK_DELAY 200 // Delay for flashing leds (ms) -#define CYCLE_DELAY 200 // Delay for cycling leds (ms) -#define SOLID_DELAY 1000 // Delay for solid led state at least n milliseconds \ No newline at end of file diff --git a/SD_v2/Makefile_Build/Makefile b/SD_v2/Makefile_Build/Makefile new file mode 100644 index 0000000..ff3140e --- /dev/null +++ b/SD_v2/Makefile_Build/Makefile @@ -0,0 +1,8 @@ +BOARD_TAG = mega2560 +MONITOR_PORT = /dev/ttyACM0 +ARDUINO_LIBS = Wire SD SPI Sodaq_DS3231/src Adafruit_GFX Adafruit_ST3775 MFRC522/src + +LOCAL_CPP_SRCS ?= $(wildcard ./src/*.cpp) +CPPFLAGS += -std=c++11 -I./inc/ -I./libs/ +USER_LIB_PATH += ./libs +include /usr/share/arduino/Arduino.mk diff --git a/SD_v2/Makefile_Build/README.md b/SD_v2/Makefile_Build/README.md new file mode 100644 index 0000000..f759b12 --- /dev/null +++ b/SD_v2/Makefile_Build/README.md @@ -0,0 +1,90 @@ +HARDWARE REQUIREMENTS: + +This project has been implmented with this Hardware, further implementation +for additional HW by future colaborators. + +- Arduino Mega2560 like this: + https://www.arduino.cc/en/Main/ArduinoBoardMega2560 + +- DS_3231 like this: + http://howtomechatronics.com/tutorials/arduino/arduino-ds3231-real-time-clock-tutorial/ + +- SainSmart 1.8 ST7735R TFT LCD Module with MicroSD like this: + https://www.sainsmart.com/sainsmart-1-8-spi-lcd-module-with-microsd-led-backlight-for-arduino-mega-atmel-atmega.html + +- MFRC522 like this: + http://www.instructables.com/id/Arduino-RFID-Reader-MFRC522-Turorial/ + +INSTALATION REQUIREMENTS: + +arduino-core: +Go to the command line and type: + +$ sudo apt-get install arduino-core + +arduino-mk: +Go to the command line and type: + +$ sudo apt-get install arduino-mk + +After you have installed the packages you may need to update your ~/.bashrc file with some new ENV variables. +Please check -> https://github.com/sudar/Arduino-Makefile + +Update the local Makefile: + +A local Makefile has been shipped within this repo, make sure you update the BOARD_TAG, MONITOR_PORT and the include path of ,,Arduino.mk''. +Please note that the project uses C++11 and therefore CPPFLAGS is appended in the local Makefile before including Arduino.mk. +You may need to update your compiler. + +EXTERNAL LIBRARIES: + +All libraries have been packaged as submodules in the folder "./libs" and refer +to their original repository. To clone them go to your command line and type: + +$ git submodule init && git submodule update + +or go to each repo and clone: + +- DS_3231 requires this library: + https://github.com/SodaqMoja/Sodaq_DS3231 + +- 1.8 ST7735R TFT LCD Module with MicroSD requires this libraries: + https://github.com/adafruit/Adafruit-GFX-Library + https://github.com/adafruit/Adafruit-ST7735-Library + +- MFRC522 requires this library: + https://github.com/miguelbalboa/rfid + +Please clone this repos and copy them inside your local ./libs folder: +(Something like ,,my/path/to/this/project/libs/") + +USAGE: + +1- Go to ,,authorized_keys.h" and modify the NUID of your authorized +tags (IN DECIMAL FORMAT) as well as the corresponding Names of each +Tag. More info about how to read a TAG NUID, see the MRFC 522 examples. + +2- Open the file ,,./inc/pin_layout.h" and follow or modify the proposed +connections for the HW. + +3- Open a terminal and go to the base directory of the Makefile_build i.e. + +$ cd /my/path/to/RFID522-Door-Unlock/SD_v2/Makefile_Build + +Now compile the source code by typing: + +$ make + +Finally upload your code to the Arduino Board by typing: + +$ make upload + +try your RFID cards! + +4- Remove the SD card, and read it from a PC, you should find a file +called ,,records.csv". You can open and further use this file in any +spreadsheet program such as ,,LibreOffice Calc". + +TODOs: +Implementation for further HW, probably using Polymorphism (Virtual classes) +Define more TODOs! diff --git a/SD_v2/Makefile_Build/UNLICENSE b/SD_v2/Makefile_Build/UNLICENSE new file mode 100644 index 0000000..00d2e13 --- /dev/null +++ b/SD_v2/Makefile_Build/UNLICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to \ No newline at end of file diff --git a/SD_v2/Makefile_Build/acces_control.ino b/SD_v2/Makefile_Build/acces_control.ino new file mode 100644 index 0000000..5b1d25f --- /dev/null +++ b/SD_v2/Makefile_Build/acces_control.ino @@ -0,0 +1,50 @@ +/******************************************************************************************** + * RFID-based access control and time records storage into SD card * + * Based on: See requirements.txt * + * Author: Juan Reyes, Apr, 2017. * + * Copyright: Unlicense -> For more information, please refer to * + * Usage: See readme.txt * + ********************************************************************************************/ + +#include "pin_layout.h" +#include +#include +#include +#include +#include + +timeState time; // Create a time object acc. to a unique RTC_DS3231 HW +Adafruit_ST7735 tft (LCD_CS, LCD_DC, LCD_RST); // Instantiate an object using HW manufacturer's library +display display_1(&tft); // Create a display object acc to specific HW (this enables the usage of multiple displays) +MFRC522 rfid(RFID_SS, RFID_RST); // Instantiate an object using HW manufacturer's library +rfid_unit rfid_unit_1(&rfid); +tag rfid_tag; // Tag information structure (Key & assigned name) + + +void setup() +{ + time.initializeDS3231 (); // Setup for DS3231 + display_1.initializeTFT_LCD(); // Setup for LCD + rfid_unit_1.initializeRFID(); // Setup for RFID MFRC522 */ + display_1.initialize_SD_storage(); // Setup for records file in SD storage + pinMode(ACC_DENIED, OUTPUT); + pinMode(ACC_GRANTED, OUTPUT); + + // Enable this to adjust the RTC current time (ONLY ONCE) + // rtc.setDateTime (DateTime (2017, 04, 23, 13, 05, 00, 1)); + // DateTime (Year,Month,Date,Hour, Minute, Second, Weekday) --> (Sunday = 1) +} + + +void loop() +{ + display_1.print_date_time(&time); // LCD print current time & date + time.update_time(); // RTC Update current time + display_1.access_default_status(); // Acces denied by default + rfid_tag = rfid_unit_1.check_acces(); // Compare Tag info with authorized keys and parse user name + + if (rfid_unit_1.check_new_card()){ // To avoid recurrent tag loading: Execute only if new card has been loaded + display_1.validate_card(rfid_tag, &time); // Validate and execute access control + rfid_unit_1.clear_nuid(); // Clear RFID NUIDs + } +} diff --git a/SD_v2/Makefile_Build/inc/LCD_module.h b/SD_v2/Makefile_Build/inc/LCD_module.h new file mode 100644 index 0000000..0975fc9 --- /dev/null +++ b/SD_v2/Makefile_Build/inc/LCD_module.h @@ -0,0 +1,34 @@ +#ifndef _TFT_LCD_ +#define _TFT_LCD_ + +#include +#include +#include +#include +#include // Core graphics library for TFT LCD - GREENTAB*! +#include // Hardware-specific library for TFT LCD - GREENTAB*! + //GREENTAB*: Specific implementation for GREENTAB_LCD_HW, refer to Adafruit library documentation. + +#if defined(__SAM3X8E__) + #undef __FlashStringHelper::F(string_literal) + #define F(string_literal) string_literal +#endif + +class display { +public: + display(Adafruit_ST7735* lcd); // Constructor for specific Adafruit Hardware + // display(ANY HARDWARE* lcd); // Can be defined for any other specific HW. (REUSE!) + void initializeTFT_LCD(); // Setup for TFT LCD - GREENTAB*! + void initialize_SD_storage(); + void write_time_register(String name, timeState* myTime); + void access_default_status(); + void print_date_time(timeState* myTime); + bool validate_card(tag my_tag, timeState* my_time); + +private: + Adafruit_ST7735* disp_pntr; + File csv_file; +}; + + +#endif // _TFT_LCD_ diff --git a/SD_v2/Makefile_Build/inc/RFID_module.h b/SD_v2/Makefile_Build/inc/RFID_module.h new file mode 100644 index 0000000..7a18f29 --- /dev/null +++ b/SD_v2/Makefile_Build/inc/RFID_module.h @@ -0,0 +1,27 @@ +#ifndef _RFID_ +#define _RFID_ + +#include +#include +#include + +typedef struct {String name; bool access;} tag; // Declaration of tag info structure + +class rfid_unit{ +public: + rfid_unit(MFRC522* my_rfid); + tag check_acces(); + bool check_new_card(); + void clear_nuid(); + void initializeRFID(); + void RFID_Scan(); + +private: + MFRC522* rfid_pntr; + byte nuidPICC [cols]; // Declaration of global old UID-Key (state memory) +}; + + + + +#endif // _RFID_ diff --git a/SD_v2/Makefile_Build/inc/RTC_module.h b/SD_v2/Makefile_Build/inc/RTC_module.h new file mode 100644 index 0000000..7f85780 --- /dev/null +++ b/SD_v2/Makefile_Build/inc/RTC_module.h @@ -0,0 +1,28 @@ +#ifndef _RTC_DS3231_ +#define _RTC_DS3231_ + +#include +#include +#include // Include required libraries for RTCDS3231 + +//////////////////////////////////////////////////////////////////////// + +class timeState { +public: + void initializeDS3231 (); //Initialize wire transfer and instansiate a RTC DS3231 + void update_time(); + inline DateTime get_current_time() {return current;} + inline String get_week_day() {return weekDay[current.dayOfWeek()-1];} + inline bool get_u_date() {return u_date;} + inline bool get_u_hour() {return u_hour;} + inline bool get_u_minute() {return u_minute;} + inline bool get_u_second() {return u_second;} + +protected: + DateTime current, prev; // Time state variables + char weekDay[8][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; // Define the names of week day for diff languages. + bool u_year, u_month, u_date, u_hour, u_minute, u_second; // Return true if the value has been updated +}; + + +#endif // _RTC_DS3231_ diff --git a/SD_v2/Makefile_Build/inc/authorized_keys.h b/SD_v2/Makefile_Build/inc/authorized_keys.h new file mode 100644 index 0000000..9fd114a --- /dev/null +++ b/SD_v2/Makefile_Build/inc/authorized_keys.h @@ -0,0 +1,24 @@ +#ifndef _AUTHORIZED_KEYS_ +#define _AUTHORIZED_KEYS_ + +const byte authorized_keys [5][4] = { // Authorized tag UIDs [number of tags] [Tag's UID-bytes] + {38,57,140,24}, + {109,234,7,203}, + {109,234,47,203}, + {109,234,47,20}, + {3,57,140,24}, +}; + +const int rows = sizeof(authorized_keys)/sizeof(authorized_keys[0]); +const int cols = sizeof(authorized_keys[0]); + +const String names [rows]={ // Corresponding name of each tag/key + {"JOHN"}, + {"DOE"}, + {"MARCO"}, + {"POLO"}, + {"ARDUINO"}, +}; + + +#endif // _AUTHORIZED_KEYS_ diff --git a/SD_v2/Makefile_Build/inc/pin_layout.h b/SD_v2/Makefile_Build/inc/pin_layout.h new file mode 100644 index 0000000..ae0182b --- /dev/null +++ b/SD_v2/Makefile_Build/inc/pin_layout.h @@ -0,0 +1,47 @@ +#ifndef _PIN_LAYOUT_ +#define _PIN_LAYOUT_ + +/*Fixed pins for Arduino Mega 2560: + * SDA 20 + * SCL 21 + * SPI MOSI 51 + * SPI MISO 50 + * SPI SCK 52 +*/ + + +/* Connections from RTC DS3231 to Arduino Mega 2560: + * VCC 5V + * GND + * SDA 20 + * SCL 21 +*/ + + +/* Connections from SainSmart 1.8 ST7735R TFT LCD Module with MicroSD to Arduino Mega 2560:*/ +#define LCD_CS 46 // SainSmart: CS +#define LCD_DC 47 // SainSmart: RS/DC +#define LCD_RST 48 // SainSmart: RES +#define SD_CS 49 // SainSmart: SD card CS pin +// SD_MISO 50 // SainSmart: SD card MISO pin +// SDA & SD_MOSI 51 // Parallel connection +// SCL & SD_SCLK 52 // Parallel connection + + +/* Connection from MFRC522 to Arduino Mega 2560:*/ +// VCC 3.3V +#define RFID_RST 44 // MFRC522 Connection pin (RST) +#define RFID_SS 45 // MFRC522 Connection pin (SDA) +// MISO 50 // Parallel connection +// MOSI 51 // Parallel connection +// SCK 52 // Parallel connection + + +/* Output Connections */ + +#define ACC_DENIED 42 // Access denied +#define ACC_GRANTED 43 // Access granted + + + +#endif // _PIN_LAYOUT_ diff --git a/SD_v2/Makefile_Build/libs/Adafruit_GFX b/SD_v2/Makefile_Build/libs/Adafruit_GFX new file mode 160000 index 0000000..07f8f65 --- /dev/null +++ b/SD_v2/Makefile_Build/libs/Adafruit_GFX @@ -0,0 +1 @@ +Subproject commit 07f8f65e4072c422f0c1e0e0c2a59dbda3d87bcb diff --git a/SD_v2/Makefile_Build/libs/Adafruit_ST3775 b/SD_v2/Makefile_Build/libs/Adafruit_ST3775 new file mode 160000 index 0000000..d53d4bf --- /dev/null +++ b/SD_v2/Makefile_Build/libs/Adafruit_ST3775 @@ -0,0 +1 @@ +Subproject commit d53d4bf03a4e916668536460d5e1a5c049c4e286 diff --git a/SD_v2/Makefile_Build/libs/MFRC522 b/SD_v2/Makefile_Build/libs/MFRC522 new file mode 160000 index 0000000..7f0f9e7 --- /dev/null +++ b/SD_v2/Makefile_Build/libs/MFRC522 @@ -0,0 +1 @@ +Subproject commit 7f0f9e73175ec5d5d415cd870d129c7aaf8af97b diff --git a/SD_v2/Makefile_Build/libs/SPI b/SD_v2/Makefile_Build/libs/SPI new file mode 160000 index 0000000..a8af486 --- /dev/null +++ b/SD_v2/Makefile_Build/libs/SPI @@ -0,0 +1 @@ +Subproject commit a8af486c7be94edee0854e7673badb7310a691e1 diff --git a/SD_v2/Makefile_Build/libs/Sodaq_DS3231 b/SD_v2/Makefile_Build/libs/Sodaq_DS3231 new file mode 160000 index 0000000..162b718 --- /dev/null +++ b/SD_v2/Makefile_Build/libs/Sodaq_DS3231 @@ -0,0 +1 @@ +Subproject commit 162b71811f1d40323632c2df2700533604a8872f diff --git a/SD_v2/Makefile_Build/src/LCD_module.cpp b/SD_v2/Makefile_Build/src/LCD_module.cpp new file mode 100644 index 0000000..b540d95 --- /dev/null +++ b/SD_v2/Makefile_Build/src/LCD_module.cpp @@ -0,0 +1,141 @@ +#include + +display::display(Adafruit_ST7735* lcd) +{ + disp_pntr = lcd; +} + +void display::initializeTFT_LCD() // Setup for TFT LCD - GREENTAB*! +{ + disp_pntr->initR(INITR_GREENTAB); // initialize a ST7735R chip, green tab + // Specific implementation for GREENTAB_LCD_HW, refer to Adafruit library documentation. + disp_pntr->fillScreen(ST7735_BLACK); // Clear screen + disp_pntr->setTextSize(1); + disp_pntr->setTextColor(ST7735_BLUE); +} + +void display::initialize_SD_storage() +{ + if (!SD.begin(SD_CS)) { // Initialize SD + disp_pntr->fillScreen(ST7735_BLACK); + disp_pntr->setTextSize(2); + disp_pntr->setTextColor(ST7735_RED); + disp_pntr->setCursor(10, 10); + disp_pntr->println("ERROR:"); + disp_pntr->setCursor(10,30); + disp_pntr->println("SD CARD"); + disp_pntr->setCursor(10,50); + disp_pntr->println("DOES NOT"); + disp_pntr->setCursor(10,70); + disp_pntr->println("INITIATE"); + disp_pntr->setCursor(10,90); + disp_pntr->println("CHECK &"); + disp_pntr->setCursor(10,110); + disp_pntr->println("RESET"); + while(1){} // If it breaks here: Something is wrong with the SD card + } + + if (SD.exists("records.csv")) { + } + else { // If file does not exist, create it + csv_file = SD.open("records.csv", FILE_WRITE); + csv_file.println ("USER,DATE,MONTH,YEAR,TIME"); + csv_file.close(); + } +} + +bool display::validate_card(tag my_tag, timeState* my_time) +{ + disp_pntr->fillRect(25, 30, 100, 10, ST7735_BLACK ); // Clear default status from screen (only) + if(my_tag.access == 1){ + disp_pntr->setCursor(40, 30); + disp_pntr->println("WELCOME"); + disp_pntr->fillCircle(60, 120, 20, ST7735_GREEN); + disp_pntr->setCursor(40, 40); + disp_pntr->println(my_tag.name); + digitalWrite(ACC_GRANTED, HIGH); + digitalWrite(ACC_DENIED, LOW); + delay (2000); + disp_pntr->fillRect(00, 30, 110, 21, ST7735_BLACK ); + disp_pntr->fillCircle(60, 120, 20, ST7735_BLACK); + write_time_register(my_tag.name, my_time); // Write to SD records + return true; + } + else { + disp_pntr->setCursor(30, 30); + disp_pntr->println("ACCESS DENIED"); + disp_pntr->setCursor(30, 40); + disp_pntr->println("Try again"); + disp_pntr->fillCircle(60, 120, 20, ST7735_RED); + delay (1000); + disp_pntr->fillRect(00, 30, 110, 21, ST7735_BLACK ); + disp_pntr->fillCircle(60, 120, 20, ST7735_BLACK); + return false; + } +} + +void display::access_default_status() { + disp_pntr->setCursor(25, 30); + disp_pntr->println("PLACE YOUR TAG"); + digitalWrite(ACC_GRANTED, LOW); + digitalWrite(ACC_DENIED, HIGH); +} + +void display::write_time_register(String name, timeState* myTime) { + if (SD.exists("records.csv")) { // Check to see if the file exists: + } + else { // Error: records.csv doesn't exist + disp_pntr->fillScreen(ST7735_BLACK); + disp_pntr->setTextSize(2); + disp_pntr->setTextColor(ST7735_RED); + disp_pntr->setCursor(10, 10); + disp_pntr->println("ERROR:"); + disp_pntr->setCursor(10,30); + disp_pntr->setTextColor(ST7735_GREEN); + disp_pntr->setTextSize(1); + disp_pntr->println("file: records.csv"); + disp_pntr->setCursor(10,50); + disp_pntr->setTextColor(ST7735_RED); + disp_pntr->setTextSize(2); + disp_pntr->println("DOES NOT"); + disp_pntr->setCursor(10,70); + disp_pntr->println("EXIST"); + disp_pntr->setCursor(10,90); + disp_pntr->println("CHECK &"); + disp_pntr->setCursor(10,110); + disp_pntr->println("RESET"); + while(1){} // If it breaks here: Something is wrong with the file initialization prob. Typo! + } + csv_file = SD.open("records.csv", FILE_WRITE); + csv_file.println(name +',' + String(myTime->get_current_time().date(),DEC) +','+ String(myTime->get_current_time().month(),DEC) + ',' + String(myTime->get_current_time().year(),DEC) + ',' + String(myTime->get_current_time().hour(),DEC) + ":" + String(myTime->get_current_time().minute(),DEC) + ":" + String(myTime->get_current_time().second(),DEC)); + csv_file.close(); +} + +void display::print_date_time (timeState* myTime) { + if (myTime->get_u_date()){ + disp_pntr->fillRect(40, 00, 70, 7, ST7735_BLACK ); /* Clear screen only when date changes */ + disp_pntr->fillRect(00, 10, 51, 7, ST7735_BLACK ); /* Clear screen only when date changes */ + disp_pntr->setCursor(10, 0); + disp_pntr->println(String("Date: ") + String(myTime->get_current_time().date(),DEC) +'.'+ String(myTime->get_current_time().month(),DEC) + '.' + String(myTime->get_current_time().year(),DEC)); + disp_pntr->setCursor(10, 10); + disp_pntr->print(myTime->get_week_day()); + } + + if (myTime->get_u_hour()){ + disp_pntr->fillRect(45, 10, 20, 7, ST7735_BLACK ); /* Clear screen only when hour changes */ + disp_pntr->setCursor(45, 10); + disp_pntr->print(String(myTime->get_current_time().hour(),DEC) + ":"); + } + + if (myTime->get_u_minute()){ + disp_pntr->fillRect(65, 10, 20, 7, ST7735_BLACK ); /* Clear screen only when minute changes */ + disp_pntr->setCursor(65, 10); + disp_pntr->print(String(myTime->get_current_time().minute(),DEC) + ':'); + } + + if (myTime->get_u_second()){ + disp_pntr->fillRect(85, 10, 20, 7, ST7735_BLACK ); /* Clear screen only when sec changes */ + disp_pntr->setCursor(85, 10); + disp_pntr->println(myTime->get_current_time().second(),DEC); + } +} diff --git a/SD_v2/Makefile_Build/src/RFID_module.cpp b/SD_v2/Makefile_Build/src/RFID_module.cpp new file mode 100644 index 0000000..db2e1d9 --- /dev/null +++ b/SD_v2/Makefile_Build/src/RFID_module.cpp @@ -0,0 +1,67 @@ +#include + + +rfid_unit::rfid_unit(MFRC522* my_rfid){ + rfid_pntr = my_rfid; +} + + +tag rfid_unit::check_acces() { + RFID_Scan(); + byte count; + tag info; + for (byte n = 0; n < rows; n++) { + count = 0; + for (byte i = 0; i < cols; i++) { + if(rfid_pntr->uid.uidByte[i] == authorized_keys[n][i]) + count ++; + } + if (count == cols) { // If the scanned key matches any of the authorised_keys.h + info.access = true; // Grant access + info.name = names[n]; // Parse User Name + return info; + } + else { + info.access = false; + } + } + return info; +} + +bool rfid_unit::check_new_card() { // returns true if the card is different + for (byte i = 0; i < cols; i++) { + if(rfid_pntr->uid.uidByte[i] != nuidPICC[i]) + { + for (byte j = 0; j < cols; j++) + { // Store NUID into nuidPICC array + nuidPICC[j] = rfid_pntr->uid.uidByte[j]; + } + return 1; + } + else { + return 0; + } + } +} + +void rfid_unit::clear_nuid() { + for (byte i = 0; i < cols; i++) + { + rfid_pntr->uid.uidByte[i] = 0; + nuidPICC[i] = 0; + } +} + +void rfid_unit::RFID_Scan() { + if ( ! rfid_pntr->PICC_IsNewCardPresent()) // Look for new cards + return; + if ( ! rfid_pntr->PICC_ReadCardSerial()) // Verify if the NUID has been readed + return; + rfid_pntr->PICC_HaltA(); // Halt PICC + rfid_pntr->PCD_StopCrypto1(); // Stop encryption on PCD +} + +void rfid_unit::initializeRFID() { + SPI.begin(); // Init SPI bus + rfid_pntr->PCD_Init(); // Init MFRC522 +} diff --git a/SD_v2/Makefile_Build/src/RTC_module.cpp b/SD_v2/Makefile_Build/src/RTC_module.cpp new file mode 100644 index 0000000..9cc8f7f --- /dev/null +++ b/SD_v2/Makefile_Build/src/RTC_module.cpp @@ -0,0 +1,22 @@ +#include + +DateTime current, prev; +bool u_date, u_month, u_year, u_hour, u_minute, u_second; + +void timeState::initializeDS3231 () //Initialize wire transfer and instansiate a RTC DS3231 +{ + Wire.begin(); + rtc.begin(); +} + +void timeState::update_time() +{ + current = rtc.now(); // Get the current date-time + if (current.year() == prev.year()) {u_year = false;} else{u_year = true;} + if (current.month() == prev.month()) {u_month = false;} else{u_month = true;} + if (current.date() == prev.date()) {u_date = false;} else{u_date = true;} + if (current.hour() == prev.hour()) {u_hour = false;} else{u_hour = true;} + if (current.minute() == prev.minute()) {u_minute = false;} else{u_minute = true;} + if (current.second() == prev.second()) {u_second = false;} else {u_second = true;} + prev = current; +} diff --git a/SD_v2/README.md b/SD_v2/README.md new file mode 100644 index 0000000..c29d366 --- /dev/null +++ b/SD_v2/README.md @@ -0,0 +1,13 @@ +This project implements an Arduino based access control solution +including a LCD display, Real Time Clock and time registers on a micro +SD card. The project has been uploaded as a "ready to compile" +version. This means that if your Hardware matches & all requirements +have been properly installed, you won't need to adjust anything else +on the code, except from the specific RFID tag's key. + +There are two versions of the same project, the one uses Arduino IDE +and the other uses the Makefile system (Linux). + +If you want to use the Arduino IDE version go to --> access_control + +If you want to use the Makefile build version go to --> Makefile_Build \ No newline at end of file diff --git a/SD_v2/access_control/HOW_TO_USE.txt b/SD_v2/access_control/HOW_TO_USE.txt new file mode 100644 index 0000000..fce5407 --- /dev/null +++ b/SD_v2/access_control/HOW_TO_USE.txt @@ -0,0 +1,19 @@ +(SEE README.md->INSTALATION REQUIREMENTS). + +HOW TO USE: + +1- Go to ,,authorized_keys.h" and modify the NUID of your authorized +tags (IN DECIMAL FORMAT) as well as the corresponding Names of each +Tag. More info about how to read a TAG NUID, see the MRFC 522 examples. + +2- Open the file ,,pin_layout.h" and follow or modify the proposed +connections for the HW. + +3- Open Your Arduino IDE v.1.8.0 (not tested in any other), verify, +upload and try your cards! + +4- Remove the SD card, and read it from a PC, you should find a file +called ,,records.csv". You can open and further use this file in any +spreadsheet program such as ,,LibreOffice Calc". + +QUESTIONS & BUGS report to the main repo diff --git a/SD_v2/access_control/LCD_module.cpp b/SD_v2/access_control/LCD_module.cpp new file mode 100644 index 0000000..56ab10e --- /dev/null +++ b/SD_v2/access_control/LCD_module.cpp @@ -0,0 +1,141 @@ +#include "LCD_module.h" + +display::display(Adafruit_ST7735* lcd) +{ + disp_pntr = lcd; +} + +void display::initializeTFT_LCD() // Setup for TFT LCD - GREENTAB*! +{ + disp_pntr->initR(INITR_GREENTAB); // initialize a ST7735R chip, green tab + // Specific implementation for GREENTAB_LCD_HW, refer to Adafruit library documentation. + disp_pntr->fillScreen(ST7735_BLACK); // Clear screen + disp_pntr->setTextSize(1); + disp_pntr->setTextColor(ST7735_BLUE); +} + +void display::initialize_SD_storage() +{ + if (!SD.begin(SD_CS)) { // Initialize SD + disp_pntr->fillScreen(ST7735_BLACK); + disp_pntr->setTextSize(2); + disp_pntr->setTextColor(ST7735_RED); + disp_pntr->setCursor(10, 10); + disp_pntr->println("ERROR:"); + disp_pntr->setCursor(10,30); + disp_pntr->println("SD CARD"); + disp_pntr->setCursor(10,50); + disp_pntr->println("DOES NOT"); + disp_pntr->setCursor(10,70); + disp_pntr->println("INITIATE"); + disp_pntr->setCursor(10,90); + disp_pntr->println("CHECK &"); + disp_pntr->setCursor(10,110); + disp_pntr->println("RESET"); + while(1){} // If it breaks here: Something is wrong with the SD card + } + + if (SD.exists("records.csv")) { + } + else { // If file does not exist, create it + csv_file = SD.open("records.csv", FILE_WRITE); + csv_file.println ("USER,DATE,MONTH,YEAR,TIME"); + csv_file.close(); + } +} + +bool display::validate_card(tag my_tag, timeState* my_time) +{ + disp_pntr->fillRect(25, 30, 100, 10, ST7735_BLACK ); // Clear default status from screen (only) + if(my_tag.access == 1){ + disp_pntr->setCursor(40, 30); + disp_pntr->println("WELCOME"); + disp_pntr->fillCircle(60, 120, 20, ST7735_GREEN); + disp_pntr->setCursor(40, 40); + disp_pntr->println(my_tag.name); + digitalWrite(ACC_GRANTED, HIGH); + digitalWrite(ACC_DENIED, LOW); + delay (2000); + disp_pntr->fillRect(00, 30, 110, 21, ST7735_BLACK ); + disp_pntr->fillCircle(60, 120, 20, ST7735_BLACK); + write_time_register(my_tag.name, my_time); // Write to SD records + return true; + } + else { + disp_pntr->setCursor(30, 30); + disp_pntr->println("ACCESS DENIED"); + disp_pntr->setCursor(30, 40); + disp_pntr->println("Try again"); + disp_pntr->fillCircle(60, 120, 20, ST7735_RED); + delay (1000); + disp_pntr->fillRect(00, 30, 110, 21, ST7735_BLACK ); + disp_pntr->fillCircle(60, 120, 20, ST7735_BLACK); + return false; + } +} + +void display::access_default_status() { + disp_pntr->setCursor(25, 30); + disp_pntr->println("PLACE YOUR TAG"); + digitalWrite(ACC_GRANTED, LOW); + digitalWrite(ACC_DENIED, HIGH); +} + +void display::write_time_register(String name, timeState* myTime) { + if (SD.exists("records.csv")) { // Check to see if the file exists: + } + else { // Error: records.csv doesn't exist + disp_pntr->fillScreen(ST7735_BLACK); + disp_pntr->setTextSize(2); + disp_pntr->setTextColor(ST7735_RED); + disp_pntr->setCursor(10, 10); + disp_pntr->println("ERROR:"); + disp_pntr->setCursor(10,30); + disp_pntr->setTextColor(ST7735_GREEN); + disp_pntr->setTextSize(1); + disp_pntr->println("file: records.csv"); + disp_pntr->setCursor(10,50); + disp_pntr->setTextColor(ST7735_RED); + disp_pntr->setTextSize(2); + disp_pntr->println("DOES NOT"); + disp_pntr->setCursor(10,70); + disp_pntr->println("EXIST"); + disp_pntr->setCursor(10,90); + disp_pntr->println("CHECK &"); + disp_pntr->setCursor(10,110); + disp_pntr->println("RESET"); + while(1){} // If it breaks here: Something is wrong with the file initialization prob. Typo! + } + csv_file = SD.open("records.csv", FILE_WRITE); + csv_file.println(name +',' + String(myTime->get_current_time().date(),DEC) +','+ String(myTime->get_current_time().month(),DEC) + ',' + String(myTime->get_current_time().year(),DEC) + ',' + String(myTime->get_current_time().hour(),DEC) + ":" + String(myTime->get_current_time().minute(),DEC) + ":" + String(myTime->get_current_time().second(),DEC)); + csv_file.close(); +} + +void display::print_date_time (timeState* myTime) { + if (myTime->get_u_date()){ + disp_pntr->fillRect(40, 00, 70, 7, ST7735_BLACK ); /* Clear screen only when date changes */ + disp_pntr->fillRect(00, 10, 51, 7, ST7735_BLACK ); /* Clear screen only when date changes */ + disp_pntr->setCursor(10, 0); + disp_pntr->println(String("Date: ") + String(myTime->get_current_time().date(),DEC) +'.'+ String(myTime->get_current_time().month(),DEC) + '.' + String(myTime->get_current_time().year(),DEC)); + disp_pntr->setCursor(10, 10); + disp_pntr->print(myTime->get_week_day()); + } + + if (myTime->get_u_hour()){ + disp_pntr->fillRect(45, 10, 20, 7, ST7735_BLACK ); /* Clear screen only when hour changes */ + disp_pntr->setCursor(45, 10); + disp_pntr->print(String(myTime->get_current_time().hour(),DEC) + ":"); + } + + if (myTime->get_u_minute()){ + disp_pntr->fillRect(65, 10, 20, 7, ST7735_BLACK ); /* Clear screen only when minute changes */ + disp_pntr->setCursor(65, 10); + disp_pntr->print(String(myTime->get_current_time().minute(),DEC) + ':'); + } + + if (myTime->get_u_second()){ + disp_pntr->fillRect(85, 10, 20, 7, ST7735_BLACK ); /* Clear screen only when sec changes */ + disp_pntr->setCursor(85, 10); + disp_pntr->println(myTime->get_current_time().second(),DEC); + } +} diff --git a/SD_v2/access_control/LCD_module.h b/SD_v2/access_control/LCD_module.h new file mode 100644 index 0000000..c246157 --- /dev/null +++ b/SD_v2/access_control/LCD_module.h @@ -0,0 +1,37 @@ +#ifndef _TFT_LCD_ +#define _TFT_LCD_ + +#include "pin_layout.h" +#include "RFID_module.h" +#include "RTC_module.h" +#include +#include // Core graphics library for TFT LCD - GREENTAB*! +#include // Hardware-specific library for TFT LCD - GREENTAB*! + //GREENTAB*: Specific implementation for GREENTAB_LCD_HW, refer to Adafruit library documentation. +#include // Include required libraries for RTCDS3231 + +#if defined(__SAM3X8E__) + #undef __FlashStringHelper::F(string_literal) + #define F(string_literal) string_literal +#endif + +//////////////////////////////////////////////////////////////////////// + +class display { +public: + display(Adafruit_ST7735* lcd); // Constructor for specific Adafruit Hardware + // display(ANY HARDWARE* lcd); // Can be defined for any other specific HW. (REUSE!) + void initializeTFT_LCD(); // Setup for TFT LCD - GREENTAB*! + void initialize_SD_storage(); + void write_time_register(String name, timeState* myTime); + void access_default_status(); + void print_date_time(timeState* myTime); + bool validate_card(tag my_tag, timeState* my_time); + +private: + Adafruit_ST7735* disp_pntr; + File csv_file; +}; + + +#endif // _TFT_LCD_ diff --git a/SD_v2/access_control/README.md b/SD_v2/access_control/README.md new file mode 100644 index 0000000..818e6f2 --- /dev/null +++ b/SD_v2/access_control/README.md @@ -0,0 +1,55 @@ +HARDWARE REQUIREMENTS: + +This project has been implmented with this Hardware, further implementation +for additional HW by future colaborators. + +- Arduino Mega2560 like this: + https://www.arduino.cc/en/Main/ArduinoBoardMega2560 + +- DS_3231 like this: + http://howtomechatronics.com/tutorials/arduino/arduino-ds3231-real-time-clock-tutorial/ + +- SainSmart 1.8 ST7735R TFT LCD Module with MicroSD like this: + https://www.sainsmart.com/sainsmart-1-8-spi-lcd-module-with-microsd-led-backlight-for-arduino-mega-atmel-atmega.html + +- MFRC522 like this: + http://www.instructables.com/id/Arduino-RFID-Reader-MFRC522-Turorial/ + +INSTALATION REQUIREMENTS: + +Arduino IDE: +(Makefile Builds is more convenient and will be available in separate branch) +This project has been tested using Arduino IDE v.1.8.0 and NOT any +other. Please note that the project uses C++11 and therefore an extra +compiling flag has been included in the file ,,platform.local.txt''. +You may need to update your compiler. + +EXTERNAL LIBRARIES: +All libraries have been packaged as submodules in the folder "./libraries" and refer +to their original repository. To clone them go to your command line and type: + +$ git submodule init && git submodule update + +or go to each repo and clone: + +- DS_3231 requires this library: + https://github.com/SodaqMoja/Sodaq_DS3231 + +- 1.8 ST7735R TFT LCD Module with MicroSD requires this libraries: + https://github.com/adafruit/Adafruit-GFX-Library + https://github.com/adafruit/Adafruit-ST7735-Library + +- MFRC522 requires this library: + https://github.com/miguelbalboa/rfid + +Please clone this repos and copy them inside your local sketchbook/libraries folder: +(Something like ,,my/path/to/my/sketchbook/libraries/") +To find the complete path, open Arduino IDE->File->Preferences and look for +,,sketchbook location" + +USAGE: +Read HOW_TO_USE.txt + +TODOs: +Implementation for further HW, probably using Polymorphism (Virtual classes) +Define more TODOs! diff --git a/SD_v2/access_control/RFID_module.cpp b/SD_v2/access_control/RFID_module.cpp new file mode 100644 index 0000000..1bf779f --- /dev/null +++ b/SD_v2/access_control/RFID_module.cpp @@ -0,0 +1,67 @@ +#include "RFID_module.h" + + +rfid_unit::rfid_unit(MFRC522* my_rfid){ + rfid_pntr = my_rfid; +} + + +tag rfid_unit::check_acces() { + RFID_Scan(); + byte count; + tag info; + for (byte n = 0; n < rows; n++) { + count = 0; + for (byte i = 0; i < cols; i++) { + if(rfid_pntr->uid.uidByte[i] == authorized_keys[n][i]) + count ++; + } + if (count == cols) { // If the scanned key matches any of the authorised_keys.h + info.access = true; // Grant access + info.name = names[n]; // Parse User Name + return info; + } + else { + info.access = false; + } + } + return info; +} + +bool rfid_unit::check_new_card() { // returns true if the card is different + for (byte i = 0; i < cols; i++) { + if(rfid_pntr->uid.uidByte[i] != nuidPICC[i]) + { + for (byte j = 0; j < cols; j++) + { // Store NUID into nuidPICC array + nuidPICC[j] = rfid_pntr->uid.uidByte[j]; + } + return 1; + } + else { + return 0; + } + } +} + +void rfid_unit::clear_nuid() { + for (byte i = 0; i < cols; i++) + { + rfid_pntr->uid.uidByte[i] = 0; + nuidPICC[i] = 0; + } +} + +void rfid_unit::RFID_Scan() { + if ( ! rfid_pntr->PICC_IsNewCardPresent()) // Look for new cards + return; + if ( ! rfid_pntr->PICC_ReadCardSerial()) // Verify if the NUID has been readed + return; + rfid_pntr->PICC_HaltA(); // Halt PICC + rfid_pntr->PCD_StopCrypto1(); // Stop encryption on PCD +} + +void rfid_unit::initializeRFID() { + SPI.begin(); // Init SPI bus + rfid_pntr->PCD_Init(); // Init MFRC522 +} diff --git a/SD_v2/access_control/RFID_module.h b/SD_v2/access_control/RFID_module.h new file mode 100644 index 0000000..64d9f89 --- /dev/null +++ b/SD_v2/access_control/RFID_module.h @@ -0,0 +1,29 @@ +#ifndef _RFID_ +#define _RFID_ + +#include "pin_layout.h" +#include "authorized_keys.h" +#include + +typedef struct {String name; bool access;} tag; // Declaration of tag info structure + +//////////////////////////////////////////////////////////////////////// + +class rfid_unit{ +public: + rfid_unit(MFRC522* my_rfid); + tag check_acces(); + bool check_new_card(); + void clear_nuid(); + void initializeRFID(); + void RFID_Scan(); + +private: + MFRC522* rfid_pntr; + byte nuidPICC [cols]; // Declaration of global old UID-Key (state memory) +}; + + + + +#endif // _RFID_ diff --git a/SD_v2/access_control/RTC_module.cpp b/SD_v2/access_control/RTC_module.cpp new file mode 100644 index 0000000..30c771a --- /dev/null +++ b/SD_v2/access_control/RTC_module.cpp @@ -0,0 +1,22 @@ +#include "RTC_module.h" + +DateTime current, prev; +bool u_date, u_month, u_year, u_hour, u_minute, u_second; + +void timeState::initializeDS3231 () //Initialize wire transfer and instansiate a RTC DS3231 +{ + Wire.begin(); + rtc.begin(); +} + +void timeState::update_time() +{ + current = rtc.now(); // Get the current date-time + if (current.year() == prev.year()) {u_year = false;} else{u_year = true;} + if (current.month() == prev.month()) {u_month = false;} else{u_month = true;} + if (current.date() == prev.date()) {u_date = false;} else{u_date = true;} + if (current.hour() == prev.hour()) {u_hour = false;} else{u_hour = true;} + if (current.minute() == prev.minute()) {u_minute = false;} else{u_minute = true;} + if (current.second() == prev.second()) {u_second = false;} else {u_second = true;} + prev = current; +} diff --git a/SD_v2/access_control/RTC_module.h b/SD_v2/access_control/RTC_module.h new file mode 100644 index 0000000..ed02ad8 --- /dev/null +++ b/SD_v2/access_control/RTC_module.h @@ -0,0 +1,28 @@ +#ifndef _RTC_DS3231_ +#define _RTC_DS3231_ + +#include +#include // Include required libraries for RTCDS3231 +#include + +//////////////////////////////////////////////////////////////////////// + +class timeState { +public: + void initializeDS3231 (); //Initialize wire transfer and instansiate a RTC DS3231 + void update_time(); + inline DateTime get_current_time() {return current;} + inline String get_week_day() {return weekDay[current.dayOfWeek()-1];} + inline bool get_u_date() {return u_date;} + inline bool get_u_hour() {return u_hour;} + inline bool get_u_minute() {return u_minute;} + inline bool get_u_second() {return u_second;} + +protected: + DateTime current, prev; // Time state variables + char weekDay[8][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; // Define the names of week day for diff languages. + bool u_year, u_month, u_date, u_hour, u_minute, u_second; // Return true if the value has been updated +}; + + +#endif // _RTC_DS3231_ diff --git a/SD_v2/access_control/UNLICENSE b/SD_v2/access_control/UNLICENSE new file mode 100644 index 0000000..00d2e13 --- /dev/null +++ b/SD_v2/access_control/UNLICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to \ No newline at end of file diff --git a/SD_v2/access_control/access_control.ino b/SD_v2/access_control/access_control.ino new file mode 100644 index 0000000..6177a8e --- /dev/null +++ b/SD_v2/access_control/access_control.ino @@ -0,0 +1,60 @@ + /******************************************************************************************** + * RFID-based access control and time records storage into SD card * + * Based on: See README.md * + * Author: Juan Reyes, Apr, 2017. * + * Copyright: Unlicense -> For more information, please refer to * + * Usage: See README.md * + ********************************************************************************************/ + +#include +#include +#include + +#include +#include +#include // Core graphics library for TFT LCD - GREENTAB*! +#include // Hardware-specific library for TFT LCD - GREENTAB*! + //GREENTAB*: Specific implementation for GREENTAB_LCD_HW, refer to Adafruit library documentation. + +#include "pin_layout.h" +#include "RFID_module.h" +#include "RTC_module.h" +#include "LCD_module.h" + + +timeState time; // Create a time object acc. to a unique RTC_DS3231 HW +Adafruit_ST7735 tft (LCD_CS, LCD_DC, LCD_RST); // Instantiate an object using HW manufacturer's library +display display_1(&tft); // Create a display object acc to specific HW (this enables the usage of multiple displays) +MFRC522 rfid(RFID_SS, RFID_RST); // Instantiate an object using HW manufacturer's library +rfid_unit rfid_unit_1(&rfid); +tag rfid_tag; // Tag information structure (Key & assigned name) + + + +void setup() +{ + time.initializeDS3231 (); // Setup for DS3231 + display_1.initializeTFT_LCD(); // Setup for LCD + rfid_unit_1.initializeRFID(); // Setup for RFID MFRC522 */ + display_1.initialize_SD_storage(); // Setup for records file in SD storage + pinMode(ACC_DENIED, OUTPUT); + pinMode(ACC_GRANTED, OUTPUT); + + // Enable this to adjust the RTC current time (ONLY ONCE) + // rtc.setDateTime (DateTime (2017, 04, 23, 13, 05, 00, 1)); + // DateTime (Year,Month,Date,Hour, Minute, Second, Weekday) --> (Sunday = 1) +} + + +void loop() +{ + display_1.print_date_time(&time); // LCD print current time & date + time.update_time(); // RTC Update current time + display_1.access_default_status(); // Acces denied by default + rfid_tag = rfid_unit_1.check_acces(); // Compare Tag info with authorized keys and parse user name + + if (rfid_unit_1.check_new_card()){ // To avoid recurrent tag loading: Execute only if new card has been loaded + display_1.validate_card(rfid_tag, &time); // Validate and execute access control + rfid_unit_1.clear_nuid(); // Clear RFID NUIDs + } +} diff --git a/SD_v2/access_control/authorized_keys.h b/SD_v2/access_control/authorized_keys.h new file mode 100644 index 0000000..e78fa5b --- /dev/null +++ b/SD_v2/access_control/authorized_keys.h @@ -0,0 +1,26 @@ +#ifndef _AUTHORIZED_KEYS_ +#define _AUTHORIZED_KEYS_ + +#include + +const byte authorized_keys [5][4] = { // Authorized tag UIDs [number of tags] [Tag's UID-bytes] + {00,00,000,00}, // USE the decimal format!! + {00,00,000,00}, + {00,00,000,00}, + {00,00,000,00}, + {00,00,000,00}, +}; + +const int rows = sizeof(authorized_keys)/sizeof(authorized_keys[0]); +const int cols = sizeof(authorized_keys[0]); + +const String names [rows]={ // Corresponding name of each tag/key + {"JOHN"}, + {"DOE"}, + {"MARCO"}, + {"POLO"}, + {"ARDUINO"}, +}; + + +#endif // _AUTHORIZED_KEYS_ diff --git a/SD_v2/access_control/libraries/Adafruit_GFX b/SD_v2/access_control/libraries/Adafruit_GFX new file mode 160000 index 0000000..07f8f65 --- /dev/null +++ b/SD_v2/access_control/libraries/Adafruit_GFX @@ -0,0 +1 @@ +Subproject commit 07f8f65e4072c422f0c1e0e0c2a59dbda3d87bcb diff --git a/SD_v2/access_control/libraries/Adafruit_ST3775 b/SD_v2/access_control/libraries/Adafruit_ST3775 new file mode 160000 index 0000000..d53d4bf --- /dev/null +++ b/SD_v2/access_control/libraries/Adafruit_ST3775 @@ -0,0 +1 @@ +Subproject commit d53d4bf03a4e916668536460d5e1a5c049c4e286 diff --git a/SD_v2/access_control/libraries/MFRC522 b/SD_v2/access_control/libraries/MFRC522 new file mode 160000 index 0000000..7f0f9e7 --- /dev/null +++ b/SD_v2/access_control/libraries/MFRC522 @@ -0,0 +1 @@ +Subproject commit 7f0f9e73175ec5d5d415cd870d129c7aaf8af97b diff --git a/SD_v2/access_control/libraries/Sodaq_DS3231 b/SD_v2/access_control/libraries/Sodaq_DS3231 new file mode 160000 index 0000000..162b718 --- /dev/null +++ b/SD_v2/access_control/libraries/Sodaq_DS3231 @@ -0,0 +1 @@ +Subproject commit 162b71811f1d40323632c2df2700533604a8872f diff --git a/SD_v2/access_control/pin_layout.h b/SD_v2/access_control/pin_layout.h new file mode 100644 index 0000000..694a2d1 --- /dev/null +++ b/SD_v2/access_control/pin_layout.h @@ -0,0 +1,48 @@ +#ifndef _PIN_LAYOUT_ +#define _PIN_LAYOUT_ + +/*Fixed pins for Arduino Mega 2560: + * SDA 20 + * SCL 21 + * SPI MOSI 51 + * SPI MISO 50 + * SPI SCK 52 +*/ + + +/* Connections from RTC DS3231 to Arduino Mega 2560: + * VCC 5V + * GND + * SDA 20 + * SCL 21 +*/ + + +/* Connections from SainSmart 1.8 ST7735R TFT LCD Module with MicroSD to Arduino Mega 2560:*/ +#define LCD_CS 46 // SainSmart: CS +#define LCD_DC 47 // SainSmart: RS/DC +#define LCD_RST 48 // SainSmart: RES +#define SD_CS 49 // SainSmart: SD card CS pin +// SD_MISO 50 // SainSmart: SD card MISO pin +// SDA & SD_MOSI 51 // Parallel connection +// SCL & SD_SCLK 52 // Parallel connection + + +/* Connection from MFRC522 to Arduino Mega 2560:*/ +// VCC 3.3V +#define RFID_RST 44 // MFRC522 Connection pin (RST) +#define RFID_SS 45 // MFRC522 Connection pin (SDA) +// MISO 50 // Parallel connection +// MOSI 51 // Parallel connection +// SCK 52 // Parallel connection + + +/* Output Connections */ + +#define ACC_DENIED 42 // Output / Led Signal for Access denied +#define ACC_GRANTED 43 // Output / Led Signal Access granted + +// If you connect a LED do not forget to add the resistor and GND connection. + + +#endif // _PIN_LAYOUT_ diff --git a/SD_v2/access_control/platform.local.txt b/SD_v2/access_control/platform.local.txt new file mode 100644 index 0000000..8863163 --- /dev/null +++ b/SD_v2/access_control/platform.local.txt @@ -0,0 +1,8 @@ +# These can be overridden in platform.local.txt +compiler.c.extra_flags= +compiler.c.elf.extra_flags= +compiler.S.extra_flags= +compiler.cpp.extra_flags=-std=c++11 +compiler.ar.extra_flags= +compiler.objcopy.eep.extra_flags= +compiler.elf2hex.extra_flags=