Arduino RFID Simulating Simple Access Control System
Just a simple Arduino-based RFID system to control stepper motor in a prototype circuit.
Components and supplies
1
BOOSTXL-ULN2003 ULN2003A Dual Stepper Motor BoosterPack
1
RFID Module (Generic)
1
LED (generic)
1
LCD KeyPad Shield For Arduino
1
Buzzer
1
Arduino UNO
Project description
Code
Simple Arduino RFID access control using adruino onGithub
Simple Arduino RFID access control using adruino
arduino
1#include <LiquidCrystal.h> 2#include <X113647Stepper.h> 3#include <EEPROM.h> // We are going to read and write PICC's UIDs from/to EEPROM 4#include <SPI.h> // RC522 Module uses SPI protocol 5#include <MFRC522.h> // Library for Mifare RC522 Devices 6#define ON HIGH 7#define OFF LOW 8static const int STEPS_PER_REVOLUTION = 64 * 32; // steps per revolution for stepper motor 9int i = 0; // Counter for alarm 10int val = LOW, pre_val = LOW; // Alarming variables 11const int Buzz = A5; 12const int greenLed = A4; 13const int wipeB = 8; // Button pin for WipeMode 14bool programMode = false; // initialize programming mode to false 15 16uint8_t successRead; // Variable integer to keep if we have Successful Read from Reader 17 18byte stobuzzerCard[4]; // Stores an ID read from EEPROM 19byte readCard[4]; // Stores scanned ID read from RFID Module 20byte masterCard[4]; // Stores master card's ID read from EEPROM 21 22// Create MFRC522 Pins. 23constexpr uint8_t RST_PIN = 9; 24constexpr uint8_t SS_PIN = 10; 25 26MFRC522 mfrc522(SS_PIN, RST_PIN); 27LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // LCD Pins connection Rs,E,D4,D5,D6,D7 28X113647Stepper myStepper(STEPS_PER_REVOLUTION, A0, A1, A2, A3); //stepper on pins A0 through A3 29// Creat a set of new characters 30byte smiley[8] = {0b00000, 0b00000, 0b01010, 0b00000, 0b00000, 0b10001, 0b01110, 0b00000}; 31byte armsUp[8] = {0b00100, 0b01010, 0b00100, 0b10101, 0b01110, 0b00100, 0b00100, 0b01010}; 32byte frownie[8] = {0b00000, 0b00000, 0b01010, 0b00000, 0b00000, 0b00000, 0b01110, 0b10001}; 33 34void setup() { 35 pinMode(Buzz, OUTPUT);// Buzzer pin as Output 36 pinMode(greenLed, OUTPUT);// buzzer Led pin as Output 37 digitalWrite(Buzz, OFF); 38 digitalWrite(greenLed, OFF); 39 pinMode(wipeB, INPUT_PULLUP); // Enable pin's pull up resistor 40 myStepper.setSpeed(6.5);// set the speed in rpm 41 42 lcd.begin(16, 2); // initialize the lcd 43 lcd.createChar (0, smiley); // load character to the LCD 44 lcd.createChar (1, armsUp); // load character to the LCD 45 lcd.createChar (2, frownie); // load character to the LCD 46 lcd.home (); // go home 47 lcd.print(" Inter. SUDAN "); 48 lcd.setCursor ( 0, 1 ); // go to the next line 49 lcd.print (" University S&T"); 50 delay(3000); 51 lcd.clear(); 52 lcd.home (); // go home 53 lcd.print("* RFID Access *"); 54 lcd.setCursor ( 0, 1 ); // go to the next line 55 lcd.print ("Control SystemX"); 56 delay(2000); 57 Serial.begin(9600); // Initialize serial communications with PC 58 SPI.begin(); // MFRC522 Hardware uses SPI protocol 59 mfrc522.PCD_Init(); // Initialize MFRC522 Hardware 60 //If you set Antenna Gain to Max it will increase reading distance 61 mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); 62 63 Serial.println(F("RFID Access Control System")); // For debugging purposes 64 // ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details 65 66 //Wipe Code - If the Button (wipeB) Pressed while setup run (powebuzzer on) it wipes EEPROM 67 if (digitalRead(wipeB) == LOW) { // when button pressed pin should get low, button connected to ground 68 lcd.clear(); 69 lcd.home (); // go home 70 lcd.print("Wiping 10 sec"); 71 lcd.setCursor ( 0, 1 ); // go to the next line 72 digitalWrite(Buzz, ON); // buzzer Led stays on to inform user we are going to wipe 73 Serial.println(F("Wipe Button Pressed")); 74 Serial.println(F("You have 10 seconds to Cancel")); 75 Serial.println(F("This will be remove all records and cannot be undone")); 76 bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation 77 if (buttonState == true && digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM 78 Serial.println(F("Starting Wiping EEPROM")); 79 for (uint16_t x = 0; x < EEPROM.length(); x = x + 1) { //Loop end of EEPROM address 80 if (EEPROM.read(x) == 0) { //If EEPROM address 0 81 // do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM 82 } 83 else { 84 EEPROM.write(x, 0); // if not write 0 to clear, it takes 3.3mS 85 } 86 } 87 Serial.println(F("EEPROM Successfully Wiped")); 88 lcd.print("EEPROM Wiped"); 89 lcd.print(char(1)); 90 digitalWrite(Buzz, OFF); // visualize a successful wipe 91 delay(200); 92 digitalWrite(Buzz, ON); 93 delay(200); 94 digitalWrite(Buzz, OFF); 95 delay(200); 96 digitalWrite(Buzz, ON); 97 delay(200); 98 digitalWrite(Buzz, OFF); 99 } 100 else { 101 Serial.println(F("Wiping Cancelled")); // Show some feedback that the wipe button did not pressed for 10 seconds 102 lcd.print("Wiping Cancelled."); 103 digitalWrite(Buzz, OFF); 104 delay(1000); 105 } 106 } 107 // Check if master card defined, if not let user choose a master card 108 // This also useful to just redefine the Master Card 109 // You can keep other EEPROM records just write other than 143 to EEPROM address 1 110 // EEPROM address 1 should hold magical number which is '143' 111 if (EEPROM.read(1) != 143) { 112 Serial.println(F("No Master Card Defined")); 113 Serial.println(F("Scan A PICC to Define as Master Card")); 114 lcd.clear(); 115 lcd.home (); // go home 116 lcd.print("No Admin card"); 117 lcd.setCursor ( 0, 1 ); // go to the next line 118 do { 119 successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 120 digitalWrite(greenLed, ON); // Visualize Master Card need to be defined 121 delay(200); 122 digitalWrite(greenLed, OFF); 123 delay(200); 124 } 125 while (!successRead); // Program will not go further while you not get a successful read 126 for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times 127 EEPROM.write( 2 + j, readCard[j] ); // Write scanned PICC's UID to EEPROM, start from address 3 128 } 129 EEPROM.write(1, 143); // Write to EEPROM we defined Master Card. 130 Serial.println(F("Master Card Defined")); 131 delay(3000); 132 lcd.clear(); 133 lcd.home (); // go home 134 lcd.print("Admin card OK"); 135 delay(1000); 136 } 137 138 Serial.println(F("-------------------")); 139 Serial.println(F("Master Card's UID")); 140 lcd.clear(); 141 lcd.home (); // go home 142 lcd.print("Admin card UID:"); 143 lcd.setCursor ( 0, 1 ); // go to the next line 144 for ( uint8_t i = 0; i < 4; i++ ) { // Read Master Card's UID from EEPROM 145 masterCard[i] = EEPROM.read(2 + i); // Write it to masterCard 146 Serial.print(masterCard[i], HEX); 147 lcd.print(masterCard[i], HEX); 148 } 149 Serial.println(""); 150 Serial.println(F("-------------------")); 151 Serial.println(F("Everything is ready")); 152 Serial.println(F("Waiting PICCs to be scanned")); 153 cycling(); 154 delay(2000); 155 lcd.clear(); 156 lcd.home (); // go home 157 lcd.print("System is Ready"); 158 lcd.setCursor ( 0, 1 ); // go to the next line 159 testing123(); 160 161} 162 163// the loop function runs over and over again forever 164void loop() { 165 do { 166 lcd.clear(); 167 lcd.home (); // go home 168 lcd.print("*Scan or Wipe"); 169 lcd.setCursor ( 0, 1 ); 170 successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 171 // When device is in use if wipe button pressed for 10 seconds initialize Master Card wiping 172 if (digitalRead(wipeB) == LOW) { // Check if button is pressed 173 // Visualize normal operation is iterrupted by pressing wipe button buzzer is like more Warning to user 174 digitalWrite(Buzz, ON); // Make sure led is off 175 digitalWrite(greenLed, OFF); // Make sure led is off 176 // Give some feedback 177 lcd.clear(); 178 lcd.home (); // go home 179 lcd.print("Wiping 10 sec"); 180 lcd.setCursor ( 0, 1 ); // go to the next line 181 Serial.println(F("Wipe Button Pressed")); 182 Serial.println(F("Master Card will be Erased! in 10 seconds")); 183 bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation 184 if (buttonState == true && digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM 185 EEPROM.write(1, 0); // Reset Magic Number. 186 Serial.println(F("Master Card Erased from device")); 187 Serial.println(F("Please reset to re-program Master Card")); 188 lcd.print("*RESET NOW..."); 189 while (1); 190 } 191 Serial.println(F("Master Card Erase Cancelled")); 192 lcd.print("Wiping Cancelled."); 193 } 194 if (programMode) { 195 cycling(); // Program Mode cycles through buzzer Green green waiting to read a new card 196 } 197 else { 198 normalModeOn(); // Normal mode, green Power LED is on, all others are off 199 } 200 } 201 while (!successRead); //the program will not go further while you are not getting a successful read 202 if (programMode) { 203 if ( isMaster(readCard) ) { //When in program mode check First If master card scanned again to exit program mode 204 Serial.println(F("Master Card Scanned")); 205 Serial.println(F("Exiting Program Mode")); 206 Serial.println(F("-----------------------------")); 207 lcd.clear(); 208 lcd.home (); // go home 209 lcd.print("Exit Prog. Mode"); 210 lcd.setCursor ( 0, 1 ); // go to the next line 211 programMode = false; 212 delay(2000); 213 return; 214 } 215 else { 216 if ( findID(readCard) ) { // If scanned card is known delete it 217 Serial.println(F("I know this PICC, removing...")); 218 lcd.clear(); 219 lcd.home (); // go home 220 lcd.print("Removing Card!"); 221 lcd.setCursor ( 0, 1 ); 222 deleteID(readCard); 223 delay(2000); 224 lcd.print("Scanning..."); 225 Serial.println("-----------------------------"); 226 Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); 227 } 228 else { // If scanned card is not known add it 229 Serial.println(F("I do not know this PICC, adding...")); 230 lcd.clear(); 231 lcd.home (); // go home 232 lcd.print("Adding Card!"); 233 lcd.setCursor ( 0, 1 ); 234 writeID(readCard); 235 lcd.print("Scanning..."); 236 Serial.println(F("-----------------------------")); 237 Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); 238 } 239 } 240 } 241 else { 242 if ( isMaster(readCard)) { // If scanned card's ID matches Master Card's ID - enter program mode 243 programMode = true; 244 Serial.println(F("Hello Master - Entebuzzer Program Mode")); 245 lcd.clear(); 246 lcd.home (); // go home 247 lcd.print("Hello Admin A*"); 248 lcd.print(char(0)); 249 lcd.setCursor ( 0, 1 ); 250 uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that 251 lcd.print(String(count)); 252 lcd.print(" cards in"); 253 Serial.print(F("I have ")); // stores the number of ID's in EEPROM 254 Serial.print(count); 255 Serial.print(F(" record(s) on EEPROM")); 256 Serial.println(""); 257 delay(10000); 258 lcd.clear(); 259 lcd.home (); // go home 260 lcd.print("*ADD or REMOVE"); 261 lcd.setCursor ( 0, 1 ); 262 lcd.print("Scan A* to Exit"); 263 Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); 264 Serial.println(F("Scan Master Card again to Exit Program Mode")); 265 Serial.println(F("-----------------------------")); 266 } 267 else { 268 if ( findID(readCard) ) { // If not, see if the card is in the EEPROM 269 Serial.println(F("Welcome, You shall pass")); 270 lcd.clear(); 271 lcd.home (); // go home 272 lcd.print("*YOU ARE WELCOME"); 273 // granted(300); // Open the door lock for 300 ms 274 goooo(); 275 myStepper.step(STEPS_PER_REVOLUTION); // step one revolution in one direction: 276 delay(500); 277 myStepper.step(-STEPS_PER_REVOLUTION); // step one revolution in the other direction: 278 delay(1000); 279 } 280 else { // If not, show that the ID was not valid 281 Serial.println(F("You shall not pass")); 282 lcd.clear(); 283 lcd.home (); // go home 284 lcd.print("*ACCESS DENIED"); 285 // denied(); 286 whooop(); // Run Alarm on 287 } 288 } 289 } 290} 291void testing123() { 292 lcd.clear(); 293 lcd.home (); // go home 294 lcd.print("Testing ..."); 295 lcd.setCursor ( 0, 1 ); 296 myStepper.step(STEPS_PER_REVOLUTION); // step one revolution in one direction: 297 lcd.print("1 "); 298 delay(500); 299 myStepper.step(-STEPS_PER_REVOLUTION); // step one revolution in the other direction: 300 lcd.print("2 "); 301 delay(1000); 302 whooop(); // Run Alarm on 303 lcd.print("3 "); 304 lcd.setCursor ( 15, 1 ); 305 lcd.print (char(2)); 306 delay (2000); 307 lcd.setCursor ( 15, 1 ); 308 lcd.print ( char(1)); 309 delay (2000); 310 lcd.setCursor ( 15, 1 ); 311 lcd.print ( char(0)); 312 delay (2000); 313 lcd.print("4 "); 314 goooo(); 315 delay (2000); 316 lcd.print("5 "); 317} 318void goooo() { 319 for (i = 0; i < 255; i = i + 2) 320 { 321 analogWrite(greenLed, i); 322 analogWrite(Buzz, i); 323 delay(10); 324 } 325 for (i = 255; i > 1; i = i - 2) 326 { 327 analogWrite(greenLed, i); 328 analogWrite(Buzz, i); 329 delay(5); 330 } 331 for (i = 1; i <= 10; i++) 332 { 333 analogWrite(greenLed, 255); 334 analogWrite(Buzz, 200); 335 delay(100); 336 analogWrite(greenLed, 0); 337 analogWrite(Buzz, 25); 338 delay(100); 339 } 340 // pre_val = val; 341} 342void whooop() { 343 for (int j = 0; j < 3; j++) { 344 // Whoop up 345 for (int hz = 440; hz < 1000; hz++) { 346 int light = map(hz, 440, 1000, 0, 255); 347 analogWrite(greenLed, light); 348 tone(Buzz, hz, 30); 349 delay(2); 350 } 351 noTone(Buzz); 352 // Whoop down 353 for (int hz = 1000; hz > 440; hz--) { 354 int light = map(hz, 1000, 440 , 255, 0); 355 analogWrite(greenLed, light); 356 tone(Buzz, hz, 30); 357 delay(2); 358 } 359 noTone(Buzz); 360 } 361} 362void cycling() { 363 digitalWrite(Buzz, OFF); // Make sure buzzer LED is off 364 digitalWrite(greenLed, ON); // Make sure green LED is on 365 delay(200); 366 digitalWrite(Buzz, ON); // Make sure buzzer LED is off 367 digitalWrite(greenLed, OFF); // Make sure green LED is off 368 delay(200); 369 digitalWrite(Buzz, OFF); // Make sure buzzer LED is on 370 digitalWrite(greenLed, OFF); // Make sure green LED is off 371 delay(200); 372} 373bool monitorWipeButton(uint32_t interval) { 374 uint32_t now = (uint32_t)millis(); 375 while ((uint32_t)millis() - now < interval) { 376 // check on every half a second 377 if (((uint32_t)millis() % 500) == 0) { 378 if (digitalRead(wipeB) != LOW) 379 return false; 380 } 381 } 382 return true; 383} 384///////////////////////////////////////// Get UID /////////////////////////////////// 385uint8_t getID() { 386 // Getting ready for Reading PICCs 387 if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue 388 return 0; 389 } 390 if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue 391 return 0; 392 } 393 // There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC 394 // I think we should assume every PICC as they have 4 byte UID 395 // Until we support 7 byte PICCs 396 Serial.println(F("Scanned PICC's UID:")); 397 lcd.clear(); 398 lcd.home (); // go home 399 lcd.print("Scanned UID:"); 400 lcd.setCursor ( 0, 1 ); 401 for ( uint8_t i = 0; i < 4; i++) { // 402 readCard[i] = mfrc522.uid.uidByte[i]; 403 Serial.print(readCard[i], HEX); 404 lcd.print(readCard[i], HEX); 405 } 406 Serial.println(""); 407 mfrc522.PICC_HaltA(); // Stop reading 408 return 1; 409} 410void normalModeOn () { 411 digitalWrite(Buzz, OFF); // Make sure buzzer LED is off 412 digitalWrite(greenLed, OFF); // Make sure Green LED is off 413} 414///////////////////////////////////////// Check Bytes /////////////////////////////////// 415bool checkTwo ( byte a[], byte b[] ) { 416 for ( uint8_t k = 0; k < 4; k++ ) { // Loop 4 times 417 if ( a[k] != b[k] ) { // IF a != b then false, because: one fails, all fail 418 return false; 419 } 420 } 421 return true; 422} 423////////////////////// Check readCard IF is masterCard /////////////////////////////////// 424// Check to see if the ID passed is the master programing card 425bool isMaster( byte test[] ) { 426 return checkTwo(test, masterCard); 427} 428///////////////////////////////////////// Find Slot /////////////////////////////////// 429uint8_t findIDSLOT( byte find[] ) { 430 uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that 431 for ( uint8_t i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry 432 readID(i); // Read an ID from EEPROM, it is stobuzzer in stobuzzerCard[4] 433 if ( checkTwo( find, stobuzzerCard ) ) { // Check to see if the stobuzzerCard read from EEPROM 434 // is the same as the find[] ID card passed 435 return i; // The slot number of the card 436 } 437 } 438} 439///////////////////////////////////////// Find ID From EEPROM /////////////////////////////////// 440bool findID( byte find[] ) { 441 uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that 442 for ( uint8_t i = 1; i < count; i++ ) { // Loop once for each EEPROM entry 443 readID(i); // Read an ID from EEPROM, it is stobuzzer in stobuzzerCard[4] 444 if ( checkTwo( find, stobuzzerCard ) ) { // Check to see if the stobuzzerCard read from EEPROM 445 return true; 446 } 447 else { // If not, return false 448 } 449 } 450 return false; 451} 452///////////////////////////////////////// Remove ID from EEPROM /////////////////////////////////// 453void deleteID( byte a[] ) { 454 if ( !findID( a ) ) { // Before we delete from the EEPROM, check to see if we have this card! 455 failedWrite(); // If not 456 Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); 457 } 458 else { 459 uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards 460 uint8_t slot; // Figure out the slot number of the card 461 uint8_t start; // = ( num * 4 ) + 6; // Figure out where the next slot starts 462 uint8_t looping; // The number of times the loop repeats 463 uint8_t j; 464 uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards 465 slot = findIDSLOT( a ); // Figure out the slot number of the card to delete 466 start = (slot * 4) + 2; 467 looping = ((num - slot) * 4); 468 num--; // Decrement the counter by one 469 EEPROM.write( 0, num ); // Write the new count to the counter 470 for ( j = 0; j < looping; j++ ) { // Loop the card shift times 471 EEPROM.write( start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM 472 } 473 for ( uint8_t k = 0; k < 4; k++ ) { // Shifting loop 474 EEPROM.write( start + j + k, 0); 475 } 476 successDelete(); 477 Serial.println(F("Succesfully removed ID record from EEPROM")); 478 } 479} 480//////////////////////////////////////// Read an ID from EEPROM ////////////////////////////// 481void readID( uint8_t number ) { 482 uint8_t start = (number * 4 ) + 2; // Figure out starting position 483 for ( uint8_t i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes 484 stobuzzerCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array 485 } 486} 487///////////////////////////////////////// Add ID to EEPROM /////////////////////////////////// 488void writeID( byte a[] ) { 489 if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before! 490 uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards 491 uint8_t start = ( num * 4 ) + 6; // Figure out where the next slot starts 492 num++; // Increment the counter by one 493 EEPROM.write( 0, num ); // Write the new count to the counter 494 for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times 495 EEPROM.write( start + j, a[j] ); // Write the array values to EEPROM in the right position 496 } 497 successWrite(); 498 Serial.println(F("Succesfully added ID record to EEPROM")); 499 } 500 else { 501 failedWrite(); 502 Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); 503 } 504} 505///////////////////////////////////////// Access Granted /////////////////////////////////// 506//void granted ( uint16_t setDelay) { 507// digitalWrite(Buzz, OFF); // Turn off buzzer LED 508// digitalWrite(greenLed, ON); // Turn on green LED 509// delay(1000); // Hold green LED on for a second 510//} 511//////////////////////////////////////////////////////////////////////////// 512///////////////////////////////////////// Access Denied /////////////////////////////////// 513//void denied() { 514// digitalWrite(greenLed, OFF); // Make sure green LED is off 515// digitalWrite(Buzz, ON); // Turn on buzzer LED 516// delay(1000); 517//} 518//////////////////////////////////////////////////////////////////////////// 519///////////////////////////////////////// Write Failed to EEPROM //////////////////////// 520// Flashes the buzzer LED 3 times to indicate a failed write to EEPROM 521void failedWrite() { 522 digitalWrite(Buzz, OFF); // Make sure buzzer is off 523 digitalWrite(greenLed, OFF); // Make sure green LED is off 524 delay(200); 525 digitalWrite(Buzz, ON); // Make sure buzzer is on 526 delay(200); 527 digitalWrite(Buzz, OFF); // Make sure buzzer is off 528 delay(200); 529 digitalWrite(Buzz, ON); // Make sure buzzer is on 530 delay(200); 531 digitalWrite(Buzz, OFF); // Make sure buzzer is off 532 delay(200); 533 digitalWrite(Buzz, ON); // Make sure buzzer is on 534 delay(200); 535} 536///////////////////////////////////////// Success Remove UID From EEPROM /////////////////////////////////// 537// Flashes the Green LED & Buzzer 3 times to indicate a success delete to EEPROM 538void successDelete() { 539 digitalWrite(Buzz, OFF); // Make sure buzzeris off 540 digitalWrite(greenLed, OFF); // Make sure green LED is off 541 delay(200); 542 digitalWrite(Buzz, ON); // Make sure buzzer is on 543 digitalWrite(greenLed, ON); // Make sure green LED is on 544 delay(200); 545 digitalWrite(Buzz, OFF); // Make sure buzzer is OFF 546 digitalWrite(greenLed, OFF); // Make sure green LED is off 547 delay(200); 548 digitalWrite(Buzz, ON); // Make sure buzzer is on 549 digitalWrite(greenLed, ON); // Make sure green LED is on 550 delay(200); 551 digitalWrite(Buzz, OFF); // Make sure buzzer is OFF 552 digitalWrite(greenLed, OFF); // Make sure green LED is off 553 delay(200); 554 digitalWrite(Buzz, ON); // Make sure buzzer is on 555 digitalWrite(greenLed, ON); // Make sure green LED is on 556 delay(200); 557} 558///////////////////////////////////////// Write Success to EEPROM /////////////////////////////////// 559// Flashes the green LED 3 times to indicate a successful write to EEPROM 560void successWrite() { 561 digitalWrite(Buzz, OFF); // Make sure buzzer is off 562 digitalWrite(greenLed, OFF); // Make sure green LED is on 563 delay(200); 564 digitalWrite(greenLed, ON); // Make sure green LED is on 565 delay(200); 566 digitalWrite(greenLed, OFF); // Make sure green LED is off 567 delay(200); 568 digitalWrite(greenLed, ON); // Make sure green LED is on 569 delay(200); 570 digitalWrite(greenLed, OFF); // Make sure green LED is off 571 delay(200); 572 digitalWrite(greenLed, ON); // Make sure green LED is on 573 delay(200); 574} 575
Simple Arduino RFID access control using adruino onGithub
Simple Arduino RFID access control using adruino
arduino
1#include <LiquidCrystal.h> 2#include <X113647Stepper.h> 3#include <EEPROM.h> // We are going to read and write PICC's UIDs from/to EEPROM 4#include <SPI.h> // RC522 Module uses SPI protocol 5#include <MFRC522.h> // Library for Mifare RC522 Devices 6#define ON HIGH 7#define OFF LOW 8static const int STEPS_PER_REVOLUTION = 64 * 32; // steps per revolution for stepper motor 9int i = 0; // Counter for alarm 10int val = LOW, pre_val = LOW; // Alarming variables 11const int Buzz = A5; 12const int greenLed = A4; 13const int wipeB = 8; // Button pin for WipeMode 14bool programMode = false; // initialize programming mode to false 15 16uint8_t successRead; // Variable integer to keep if we have Successful Read from Reader 17 18byte stobuzzerCard[4]; // Stores an ID read from EEPROM 19byte readCard[4]; // Stores scanned ID read from RFID Module 20byte masterCard[4]; // Stores master card's ID read from EEPROM 21 22// Create MFRC522 Pins. 23constexpr uint8_t RST_PIN = 9; 24constexpr uint8_t SS_PIN = 10; 25 26MFRC522 mfrc522(SS_PIN, RST_PIN); 27LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // LCD Pins connection Rs,E,D4,D5,D6,D7 28X113647Stepper myStepper(STEPS_PER_REVOLUTION, A0, A1, A2, A3); //stepper on pins A0 through A3 29// Creat a set of new characters 30byte smiley[8] = {0b00000, 0b00000, 0b01010, 0b00000, 0b00000, 0b10001, 0b01110, 0b00000}; 31byte armsUp[8] = {0b00100, 0b01010, 0b00100, 0b10101, 0b01110, 0b00100, 0b00100, 0b01010}; 32byte frownie[8] = {0b00000, 0b00000, 0b01010, 0b00000, 0b00000, 0b00000, 0b01110, 0b10001}; 33 34void setup() { 35 pinMode(Buzz, OUTPUT);// Buzzer pin as Output 36 pinMode(greenLed, OUTPUT);// buzzer Led pin as Output 37 digitalWrite(Buzz, OFF); 38 digitalWrite(greenLed, OFF); 39 pinMode(wipeB, INPUT_PULLUP); // Enable pin's pull up resistor 40 myStepper.setSpeed(6.5);// set the speed in rpm 41 42 lcd.begin(16, 2); // initialize the lcd 43 lcd.createChar (0, smiley); // load character to the LCD 44 lcd.createChar (1, armsUp); // load character to the LCD 45 lcd.createChar (2, frownie); // load character to the LCD 46 lcd.home (); // go home 47 lcd.print(" Inter. SUDAN "); 48 lcd.setCursor ( 0, 1 ); // go to the next line 49 lcd.print (" University S&T"); 50 delay(3000); 51 lcd.clear(); 52 lcd.home (); // go home 53 lcd.print("* RFID Access *"); 54 lcd.setCursor ( 0, 1 ); // go to the next line 55 lcd.print ("Control SystemX"); 56 delay(2000); 57 Serial.begin(9600); // Initialize serial communications with PC 58 SPI.begin(); // MFRC522 Hardware uses SPI protocol 59 mfrc522.PCD_Init(); // Initialize MFRC522 Hardware 60 //If you set Antenna Gain to Max it will increase reading distance 61 mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); 62 63 Serial.println(F("RFID Access Control System")); // For debugging purposes 64 // ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details 65 66 //Wipe Code - If the Button (wipeB) Pressed while setup run (powebuzzer on) it wipes EEPROM 67 if (digitalRead(wipeB) == LOW) { // when button pressed pin should get low, button connected to ground 68 lcd.clear(); 69 lcd.home (); // go home 70 lcd.print("Wiping 10 sec"); 71 lcd.setCursor ( 0, 1 ); // go to the next line 72 digitalWrite(Buzz, ON); // buzzer Led stays on to inform user we are going to wipe 73 Serial.println(F("Wipe Button Pressed")); 74 Serial.println(F("You have 10 seconds to Cancel")); 75 Serial.println(F("This will be remove all records and cannot be undone")); 76 bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation 77 if (buttonState == true && digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM 78 Serial.println(F("Starting Wiping EEPROM")); 79 for (uint16_t x = 0; x < EEPROM.length(); x = x + 1) { //Loop end of EEPROM address 80 if (EEPROM.read(x) == 0) { //If EEPROM address 0 81 // do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM 82 } 83 else { 84 EEPROM.write(x, 0); // if not write 0 to clear, it takes 3.3mS 85 } 86 } 87 Serial.println(F("EEPROM Successfully Wiped")); 88 lcd.print("EEPROM Wiped"); 89 lcd.print(char(1)); 90 digitalWrite(Buzz, OFF); // visualize a successful wipe 91 delay(200); 92 digitalWrite(Buzz, ON); 93 delay(200); 94 digitalWrite(Buzz, OFF); 95 delay(200); 96 digitalWrite(Buzz, ON); 97 delay(200); 98 digitalWrite(Buzz, OFF); 99 } 100 else { 101 Serial.println(F("Wiping Cancelled")); // Show some feedback that the wipe button did not pressed for 10 seconds 102 lcd.print("Wiping Cancelled."); 103 digitalWrite(Buzz, OFF); 104 delay(1000); 105 } 106 } 107 // Check if master card defined, if not let user choose a master card 108 // This also useful to just redefine the Master Card 109 // You can keep other EEPROM records just write other than 143 to EEPROM address 1 110 // EEPROM address 1 should hold magical number which is '143' 111 if (EEPROM.read(1) != 143) { 112 Serial.println(F("No Master Card Defined")); 113 Serial.println(F("Scan A PICC to Define as Master Card")); 114 lcd.clear(); 115 lcd.home (); // go home 116 lcd.print("No Admin card"); 117 lcd.setCursor ( 0, 1 ); // go to the next line 118 do { 119 successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 120 digitalWrite(greenLed, ON); // Visualize Master Card need to be defined 121 delay(200); 122 digitalWrite(greenLed, OFF); 123 delay(200); 124 } 125 while (!successRead); // Program will not go further while you not get a successful read 126 for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times 127 EEPROM.write( 2 + j, readCard[j] ); // Write scanned PICC's UID to EEPROM, start from address 3 128 } 129 EEPROM.write(1, 143); // Write to EEPROM we defined Master Card. 130 Serial.println(F("Master Card Defined")); 131 delay(3000); 132 lcd.clear(); 133 lcd.home (); // go home 134 lcd.print("Admin card OK"); 135 delay(1000); 136 } 137 138 Serial.println(F("-------------------")); 139 Serial.println(F("Master Card's UID")); 140 lcd.clear(); 141 lcd.home (); // go home 142 lcd.print("Admin card UID:"); 143 lcd.setCursor ( 0, 1 ); // go to the next line 144 for ( uint8_t i = 0; i < 4; i++ ) { // Read Master Card's UID from EEPROM 145 masterCard[i] = EEPROM.read(2 + i); // Write it to masterCard 146 Serial.print(masterCard[i], HEX); 147 lcd.print(masterCard[i], HEX); 148 } 149 Serial.println(""); 150 Serial.println(F("-------------------")); 151 Serial.println(F("Everything is ready")); 152 Serial.println(F("Waiting PICCs to be scanned")); 153 cycling(); 154 delay(2000); 155 lcd.clear(); 156 lcd.home (); // go home 157 lcd.print("System is Ready"); 158 lcd.setCursor ( 0, 1 ); // go to the next line 159 testing123(); 160 161} 162 163// the loop function runs over and over again forever 164void loop() { 165 do { 166 lcd.clear(); 167 lcd.home (); // go home 168 lcd.print("*Scan or Wipe"); 169 lcd.setCursor ( 0, 1 ); 170 successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 171 // When device is in use if wipe button pressed for 10 seconds initialize Master Card wiping 172 if (digitalRead(wipeB) == LOW) { // Check if button is pressed 173 // Visualize normal operation is iterrupted by pressing wipe button buzzer is like more Warning to user 174 digitalWrite(Buzz, ON); // Make sure led is off 175 digitalWrite(greenLed, OFF); // Make sure led is off 176 // Give some feedback 177 lcd.clear(); 178 lcd.home (); // go home 179 lcd.print("Wiping 10 sec"); 180 lcd.setCursor ( 0, 1 ); // go to the next line 181 Serial.println(F("Wipe Button Pressed")); 182 Serial.println(F("Master Card will be Erased! in 10 seconds")); 183 bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation 184 if (buttonState == true && digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM 185 EEPROM.write(1, 0); // Reset Magic Number. 186 Serial.println(F("Master Card Erased from device")); 187 Serial.println(F("Please reset to re-program Master Card")); 188 lcd.print("*RESET NOW..."); 189 while (1); 190 } 191 Serial.println(F("Master Card Erase Cancelled")); 192 lcd.print("Wiping Cancelled."); 193 } 194 if (programMode) { 195 cycling(); // Program Mode cycles through buzzer Green green waiting to read a new card 196 } 197 else { 198 normalModeOn(); // Normal mode, green Power LED is on, all others are off 199 } 200 } 201 while (!successRead); //the program will not go further while you are not getting a successful read 202 if (programMode) { 203 if ( isMaster(readCard) ) { //When in program mode check First If master card scanned again to exit program mode 204 Serial.println(F("Master Card Scanned")); 205 Serial.println(F("Exiting Program Mode")); 206 Serial.println(F("-----------------------------")); 207 lcd.clear(); 208 lcd.home (); // go home 209 lcd.print("Exit Prog. Mode"); 210 lcd.setCursor ( 0, 1 ); // go to the next line 211 programMode = false; 212 delay(2000); 213 return; 214 } 215 else { 216 if ( findID(readCard) ) { // If scanned card is known delete it 217 Serial.println(F("I know this PICC, removing...")); 218 lcd.clear(); 219 lcd.home (); // go home 220 lcd.print("Removing Card!"); 221 lcd.setCursor ( 0, 1 ); 222 deleteID(readCard); 223 delay(2000); 224 lcd.print("Scanning..."); 225 Serial.println("-----------------------------"); 226 Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); 227 } 228 else { // If scanned card is not known add it 229 Serial.println(F("I do not know this PICC, adding...")); 230 lcd.clear(); 231 lcd.home (); // go home 232 lcd.print("Adding Card!"); 233 lcd.setCursor ( 0, 1 ); 234 writeID(readCard); 235 lcd.print("Scanning..."); 236 Serial.println(F("-----------------------------")); 237 Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); 238 } 239 } 240 } 241 else { 242 if ( isMaster(readCard)) { // If scanned card's ID matches Master Card's ID - enter program mode 243 programMode = true; 244 Serial.println(F("Hello Master - Entebuzzer Program Mode")); 245 lcd.clear(); 246 lcd.home (); // go home 247 lcd.print("Hello Admin A*"); 248 lcd.print(char(0)); 249 lcd.setCursor ( 0, 1 ); 250 uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that 251 lcd.print(String(count)); 252 lcd.print(" cards in"); 253 Serial.print(F("I have ")); // stores the number of ID's in EEPROM 254 Serial.print(count); 255 Serial.print(F(" record(s) on EEPROM")); 256 Serial.println(""); 257 delay(10000); 258 lcd.clear(); 259 lcd.home (); // go home 260 lcd.print("*ADD or REMOVE"); 261 lcd.setCursor ( 0, 1 ); 262 lcd.print("Scan A* to Exit"); 263 Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM")); 264 Serial.println(F("Scan Master Card again to Exit Program Mode")); 265 Serial.println(F("-----------------------------")); 266 } 267 else { 268 if ( findID(readCard) ) { // If not, see if the card is in the EEPROM 269 Serial.println(F("Welcome, You shall pass")); 270 lcd.clear(); 271 lcd.home (); // go home 272 lcd.print("*YOU ARE WELCOME"); 273 // granted(300); // Open the door lock for 300 ms 274 goooo(); 275 myStepper.step(STEPS_PER_REVOLUTION); // step one revolution in one direction: 276 delay(500); 277 myStepper.step(-STEPS_PER_REVOLUTION); // step one revolution in the other direction: 278 delay(1000); 279 } 280 else { // If not, show that the ID was not valid 281 Serial.println(F("You shall not pass")); 282 lcd.clear(); 283 lcd.home (); // go home 284 lcd.print("*ACCESS DENIED"); 285 // denied(); 286 whooop(); // Run Alarm on 287 } 288 } 289 } 290} 291void testing123() { 292 lcd.clear(); 293 lcd.home (); // go home 294 lcd.print("Testing ..."); 295 lcd.setCursor ( 0, 1 ); 296 myStepper.step(STEPS_PER_REVOLUTION); // step one revolution in one direction: 297 lcd.print("1 "); 298 delay(500); 299 myStepper.step(-STEPS_PER_REVOLUTION); // step one revolution in the other direction: 300 lcd.print("2 "); 301 delay(1000); 302 whooop(); // Run Alarm on 303 lcd.print("3 "); 304 lcd.setCursor ( 15, 1 ); 305 lcd.print (char(2)); 306 delay (2000); 307 lcd.setCursor ( 15, 1 ); 308 lcd.print ( char(1)); 309 delay (2000); 310 lcd.setCursor ( 15, 1 ); 311 lcd.print ( char(0)); 312 delay (2000); 313 lcd.print("4 "); 314 goooo(); 315 delay (2000); 316 lcd.print("5 "); 317} 318void goooo() { 319 for (i = 0; i < 255; i = i + 2) 320 { 321 analogWrite(greenLed, i); 322 analogWrite(Buzz, i); 323 delay(10); 324 } 325 for (i = 255; i > 1; i = i - 2) 326 { 327 analogWrite(greenLed, i); 328 analogWrite(Buzz, i); 329 delay(5); 330 } 331 for (i = 1; i <= 10; i++) 332 { 333 analogWrite(greenLed, 255); 334 analogWrite(Buzz, 200); 335 delay(100); 336 analogWrite(greenLed, 0); 337 analogWrite(Buzz, 25); 338 delay(100); 339 } 340 // pre_val = val; 341} 342void whooop() { 343 for (int j = 0; j < 3; j++) { 344 // Whoop up 345 for (int hz = 440; hz < 1000; hz++) { 346 int light = map(hz, 440, 1000, 0, 255); 347 analogWrite(greenLed, light); 348 tone(Buzz, hz, 30); 349 delay(2); 350 } 351 noTone(Buzz); 352 // Whoop down 353 for (int hz = 1000; hz > 440; hz--) { 354 int light = map(hz, 1000, 440 , 255, 0); 355 analogWrite(greenLed, light); 356 tone(Buzz, hz, 30); 357 delay(2); 358 } 359 noTone(Buzz); 360 } 361} 362void cycling() { 363 digitalWrite(Buzz, OFF); // Make sure buzzer LED is off 364 digitalWrite(greenLed, ON); // Make sure green LED is on 365 delay(200); 366 digitalWrite(Buzz, ON); // Make sure buzzer LED is off 367 digitalWrite(greenLed, OFF); // Make sure green LED is off 368 delay(200); 369 digitalWrite(Buzz, OFF); // Make sure buzzer LED is on 370 digitalWrite(greenLed, OFF); // Make sure green LED is off 371 delay(200); 372} 373bool monitorWipeButton(uint32_t interval) { 374 uint32_t now = (uint32_t)millis(); 375 while ((uint32_t)millis() - now < interval) { 376 // check on every half a second 377 if (((uint32_t)millis() % 500) == 0) { 378 if (digitalRead(wipeB) != LOW) 379 return false; 380 } 381 } 382 return true; 383} 384///////////////////////////////////////// Get UID /////////////////////////////////// 385uint8_t getID() { 386 // Getting ready for Reading PICCs 387 if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue 388 return 0; 389 } 390 if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue 391 return 0; 392 } 393 // There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC 394 // I think we should assume every PICC as they have 4 byte UID 395 // Until we support 7 byte PICCs 396 Serial.println(F("Scanned PICC's UID:")); 397 lcd.clear(); 398 lcd.home (); // go home 399 lcd.print("Scanned UID:"); 400 lcd.setCursor ( 0, 1 ); 401 for ( uint8_t i = 0; i < 4; i++) { // 402 readCard[i] = mfrc522.uid.uidByte[i]; 403 Serial.print(readCard[i], HEX); 404 lcd.print(readCard[i], HEX); 405 } 406 Serial.println(""); 407 mfrc522.PICC_HaltA(); // Stop reading 408 return 1; 409} 410void normalModeOn () { 411 digitalWrite(Buzz, OFF); // Make sure buzzer LED is off 412 digitalWrite(greenLed, OFF); // Make sure Green LED is off 413} 414///////////////////////////////////////// Check Bytes /////////////////////////////////// 415bool checkTwo ( byte a[], byte b[] ) { 416 for ( uint8_t k = 0; k < 4; k++ ) { // Loop 4 times 417 if ( a[k] != b[k] ) { // IF a != b then false, because: one fails, all fail 418 return false; 419 } 420 } 421 return true; 422} 423////////////////////// Check readCard IF is masterCard /////////////////////////////////// 424// Check to see if the ID passed is the master programing card 425bool isMaster( byte test[] ) { 426 return checkTwo(test, masterCard); 427} 428///////////////////////////////////////// Find Slot /////////////////////////////////// 429uint8_t findIDSLOT( byte find[] ) { 430 uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that 431 for ( uint8_t i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry 432 readID(i); // Read an ID from EEPROM, it is stobuzzer in stobuzzerCard[4] 433 if ( checkTwo( find, stobuzzerCard ) ) { // Check to see if the stobuzzerCard read from EEPROM 434 // is the same as the find[] ID card passed 435 return i; // The slot number of the card 436 } 437 } 438} 439///////////////////////////////////////// Find ID From EEPROM /////////////////////////////////// 440bool findID( byte find[] ) { 441 uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that 442 for ( uint8_t i = 1; i < count; i++ ) { // Loop once for each EEPROM entry 443 readID(i); // Read an ID from EEPROM, it is stobuzzer in stobuzzerCard[4] 444 if ( checkTwo( find, stobuzzerCard ) ) { // Check to see if the stobuzzerCard read from EEPROM 445 return true; 446 } 447 else { // If not, return false 448 } 449 } 450 return false; 451} 452///////////////////////////////////////// Remove ID from EEPROM /////////////////////////////////// 453void deleteID( byte a[] ) { 454 if ( !findID( a ) ) { // Before we delete from the EEPROM, check to see if we have this card! 455 failedWrite(); // If not 456 Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); 457 } 458 else { 459 uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards 460 uint8_t slot; // Figure out the slot number of the card 461 uint8_t start; // = ( num * 4 ) + 6; // Figure out where the next slot starts 462 uint8_t looping; // The number of times the loop repeats 463 uint8_t j; 464 uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards 465 slot = findIDSLOT( a ); // Figure out the slot number of the card to delete 466 start = (slot * 4) + 2; 467 looping = ((num - slot) * 4); 468 num--; // Decrement the counter by one 469 EEPROM.write( 0, num ); // Write the new count to the counter 470 for ( j = 0; j < looping; j++ ) { // Loop the card shift times 471 EEPROM.write( start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM 472 } 473 for ( uint8_t k = 0; k < 4; k++ ) { // Shifting loop 474 EEPROM.write( start + j + k, 0); 475 } 476 successDelete(); 477 Serial.println(F("Succesfully removed ID record from EEPROM")); 478 } 479} 480//////////////////////////////////////// Read an ID from EEPROM ////////////////////////////// 481void readID( uint8_t number ) { 482 uint8_t start = (number * 4 ) + 2; // Figure out starting position 483 for ( uint8_t i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes 484 stobuzzerCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array 485 } 486} 487///////////////////////////////////////// Add ID to EEPROM /////////////////////////////////// 488void writeID( byte a[] ) { 489 if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before! 490 uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards 491 uint8_t start = ( num * 4 ) + 6; // Figure out where the next slot starts 492 num++; // Increment the counter by one 493 EEPROM.write( 0, num ); // Write the new count to the counter 494 for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times 495 EEPROM.write( start + j, a[j] ); // Write the array values to EEPROM in the right position 496 } 497 successWrite(); 498 Serial.println(F("Succesfully added ID record to EEPROM")); 499 } 500 else { 501 failedWrite(); 502 Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); 503 } 504} 505///////////////////////////////////////// Access Granted /////////////////////////////////// 506//void granted ( uint16_t setDelay) { 507// digitalWrite(Buzz, OFF); // Turn off buzzer LED 508// digitalWrite(greenLed, ON); // Turn on green LED 509// delay(1000); // Hold green LED on for a second 510//} 511//////////////////////////////////////////////////////////////////////////// 512///////////////////////////////////////// Access Denied /////////////////////////////////// 513//void denied() { 514// digitalWrite(greenLed, OFF); // Make sure green LED is off 515// digitalWrite(Buzz, ON); // Turn on buzzer LED 516// delay(1000); 517//} 518//////////////////////////////////////////////////////////////////////////// 519///////////////////////////////////////// Write Failed to EEPROM //////////////////////// 520// Flashes the buzzer LED 3 times to indicate a failed write to EEPROM 521void failedWrite() { 522 digitalWrite(Buzz, OFF); // Make sure buzzer is off 523 digitalWrite(greenLed, OFF); // Make sure green LED is off 524 delay(200); 525 digitalWrite(Buzz, ON); // Make sure buzzer is on 526 delay(200); 527 digitalWrite(Buzz, OFF); // Make sure buzzer is off 528 delay(200); 529 digitalWrite(Buzz, ON); // Make sure buzzer is on 530 delay(200); 531 digitalWrite(Buzz, OFF); // Make sure buzzer is off 532 delay(200); 533 digitalWrite(Buzz, ON); // Make sure buzzer is on 534 delay(200); 535} 536///////////////////////////////////////// Success Remove UID From EEPROM /////////////////////////////////// 537// Flashes the Green LED & Buzzer 3 times to indicate a success delete to EEPROM 538void successDelete() { 539 digitalWrite(Buzz, OFF); // Make sure buzzeris off 540 digitalWrite(greenLed, OFF); // Make sure green LED is off 541 delay(200); 542 digitalWrite(Buzz, ON); // Make sure buzzer is on 543 digitalWrite(greenLed, ON); // Make sure green LED is on 544 delay(200); 545 digitalWrite(Buzz, OFF); // Make sure buzzer is OFF 546 digitalWrite(greenLed, OFF); // Make sure green LED is off 547 delay(200); 548 digitalWrite(Buzz, ON); // Make sure buzzer is on 549 digitalWrite(greenLed, ON); // Make sure green LED is on 550 delay(200); 551 digitalWrite(Buzz, OFF); // Make sure buzzer is OFF 552 digitalWrite(greenLed, OFF); // Make sure green LED is off 553 delay(200); 554 digitalWrite(Buzz, ON); // Make sure buzzer is on 555 digitalWrite(greenLed, ON); // Make sure green LED is on 556 delay(200); 557} 558///////////////////////////////////////// Write Success to EEPROM /////////////////////////////////// 559// Flashes the green LED 3 times to indicate a successful write to EEPROM 560void successWrite() { 561 digitalWrite(Buzz, OFF); // Make sure buzzer is off 562 digitalWrite(greenLed, OFF); // Make sure green LED is on 563 delay(200); 564 digitalWrite(greenLed, ON); // Make sure green LED is on 565 delay(200); 566 digitalWrite(greenLed, OFF); // Make sure green LED is off 567 delay(200); 568 digitalWrite(greenLed, ON); // Make sure green LED is on 569 delay(200); 570 digitalWrite(greenLed, OFF); // Make sure green LED is off 571 delay(200); 572 digitalWrite(greenLed, ON); // Make sure green LED is on 573 delay(200); 574} 575
Downloadable files
Circuit Schematic
Circuit Schematic

Documentation
Fritzing Schmatic
Fritzing Schmatic
Fritzing Schmatic
Fritzing Schmatic
Comments
Only logged in users can leave comments