Components and supplies
5 mm LED: Green
5 mm LED: Red
RFID Module (Generic)
Jumper wires (generic)
RFID Module (Generic)
Arduino UNO
Breadboard (generic)
Apps and platforms
Arduino IDE
Project description
Code
untitled
c_cpp
1#include <SPI.h> 2#include <MFRC522.h> 3 4#define SS_PIN 10 5#define RST_PIN 9 6#define RED 2 7#define Green 3 8MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. 9 10void setup() 11{ 12 Serial.begin(9600); // Initiate a serial communication 13 SPI.begin(); // Initiate SPI bus 14 mfrc522.PCD_Init(); // Initiate MFRC522 15 Serial.println("Approximate your card to the reader..."); 16 Serial.println(); 17 pinMode(LED_BUILTIN, OUTPUT); 18 digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW 19 digitalWrite(Green, LOW); 20 digitalWrite(RED, LOW); 21 22} 23void loop() 24{ 25 // Look for new cards 26 if ( ! mfrc522.PICC_IsNewCardPresent()) 27 { 28 return; 29 } 30 // Select one of the cards 31 if ( ! mfrc522.PICC_ReadCardSerial()) 32 { 33 return; 34 } 35 //Show UID on serial monitor 36 Serial.print("UID tag :"); 37 String content= ""; 38 byte letter; 39 for (byte i = 0; i < mfrc522.uid.size; i++) 40 { 41 Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); 42 Serial.print(mfrc522.uid.uidByte[i], HEX); 43 content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 44 content.concat(String(mfrc522.uid.uidByte[i], HEX)); 45 } 46 Serial.println(); 47 Serial.print("Message : "); 48 content.toUpperCase(); 49 if ((content.substring(1) == "1A 7C 78 30") || (content.substring(1) == "CC CC A3 16") ) //change here the UID of the card/cards that you want to give access 50 { 51 Serial.println("Authorized access"); 52 Serial.println(); 53 digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) 54 digitalWrite(Green, HIGH); 55 delay(10000); 56 digitalWrite(Green, LOW); 57 } 58 59 else { 60 61 Serial.println(" Access denied"); 62 digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW 63 digitalWrite(RED, HIGH); 64 delay(10000); 65 digitalWrite(RED, LOW); 66 67 } 68}
untitled
c_cpp
1#include <SPI.h> 2#include <MFRC522.h> 3 4#define SS_PIN 10 5#define 6 RST_PIN 9 7#define RED 2 8#define Green 3 9MFRC522 mfrc522(SS_PIN, RST_PIN); 10 // Create MFRC522 instance. 11 12void setup() 13{ 14 Serial.begin(9600); 15 // Initiate a serial communication 16 SPI.begin(); // Initiate SPI bus 17 18 mfrc522.PCD_Init(); // Initiate MFRC522 19 Serial.println("Approximate your 20 card to the reader..."); 21 Serial.println(); 22 pinMode(LED_BUILTIN, OUTPUT); 23 24 digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage 25 LOW 26 digitalWrite(Green, LOW); 27 digitalWrite(RED, LOW); 28 29} 30void 31 loop() 32{ 33 // Look for new cards 34 if ( ! mfrc522.PICC_IsNewCardPresent()) 35 36 { 37 return; 38 } 39 // Select one of the cards 40 if ( ! mfrc522.PICC_ReadCardSerial()) 41 42 { 43 return; 44 } 45 //Show UID on serial monitor 46 Serial.print("UID 47 tag :"); 48 String content= ""; 49 byte letter; 50 for (byte i = 0; i < 51 mfrc522.uid.size; i++) 52 { 53 Serial.print(mfrc522.uid.uidByte[i] < 0x10 54 ? " 0" : " "); 55 Serial.print(mfrc522.uid.uidByte[i], HEX); 56 content.concat(String(mfrc522.uid.uidByte[i] 57 < 0x10 ? " 0" : " ")); 58 content.concat(String(mfrc522.uid.uidByte[i], 59 HEX)); 60 } 61 Serial.println(); 62 Serial.print("Message : "); 63 content.toUpperCase(); 64 65 if ((content.substring(1) == "1A 7C 78 30") || (content.substring(1) == "CC 66 CC A3 16") ) //change here the UID of the card/cards that you want to give access 67 68 { 69 Serial.println("Authorized access"); 70 Serial.println(); 71 digitalWrite(LED_BUILTIN, 72 HIGH); // turn the LED on (HIGH is the voltage level) 73 digitalWrite(Green, 74 HIGH); 75 delay(10000); 76 digitalWrite(Green, LOW); 77 } 78 79 else 80 { 81 82 Serial.println(" Access denied"); 83 digitalWrite(LED_BUILTIN, 84 LOW); // turn the LED off by making the voltage LOW 85 digitalWrite(RED, 86 HIGH); 87 delay(10000); 88 digitalWrite(RED, LOW); 89 90 } 91}
Downloadable files
rfid_card_sensor_wiring_POtdYr4LAd.png
rfid_card_sensor_wiring_POtdYr4LAd.png
rfid_card_sensor_wiring_POtdYr4LAd.png
rfid_card_sensor_wiring_POtdYr4LAd.png
Comments
Only logged in users can leave comments