Components and supplies
Alphanumeric LCD, 16 x 2
Male/Female Jumper Wires
Arduino Mega 2560
RFID Module (Generic)
Project description
Code
Auto Clear After Half A Second
cpp
Please replace RFID numbers with your own.
1#include <SPI.h> 2#include <MFRC522.h> 3 4#define SS_PIN 53 5#define RST_PIN 9 6 7MFRC522 mfrc522(SS_PIN, RST_PIN); 8 9// for a led 10int 11 lock = 6; 12 13int serrure = 3; 14 15 16char st[20]; 17 18#include <LiquidCrystal.h> 19#define I2C_ADDR 20 21// initialize the library by associating any needed LCD interface 22// with the arduino pin number it is connected to 23const int rs = A3, en 24 = A5, d4 = A9, d5 = A10, d6 = A11, d7 = A12; 25LiquidCrystal lcd(rs, en, d4, d5, 26 d6, d7); 27void setup() 28{ 29 pinMode(lock, OUTPUT); 30 31 pinMode (serrure, 32 OUTPUT); 33 34 35 Serial.begin(9600); 36 SPI.begin(); 37 mfrc522.PCD_Init(); 38 39 Serial.println("Access test via RFID tag"); 40 Serial.println(); 41 pinMode(A14,OUTPUT); 42 43 pinMode(A13,OUTPUT); 44 pinMode(A4,OUTPUT); 45 pinMode(A0,OUTPUT); 46 pinMode(A2,OUTPUT); 47 48 pinMode(A1,OUTPUT); 49 digitalWrite(A14,LOW); 50 digitalWrite(A13,HIGH); 51 52 digitalWrite(A4,LOW); 53 digitalWrite(A0,LOW); 54 digitalWrite(A2,LOW); 55 56 digitalWrite(A1,HIGH); 57 lcd.begin(16, 2); 58} 59 60void loop() 61{ 62 63 int sensorReading = analogRead(A0); 64 // map the result to 200 - 1000: 65 66 int delayTime = map(sensorReading, 0, 1023, 200, 1000); 67 if ( ! mfrc522.PICC_IsNewCardPresent()) 68 69 { 70 return; 71 } 72 if ( ! mfrc522.PICC_ReadCardSerial()) 73 { 74 75 return; 76 } 77 Serial.print("Tag :"); 78 String tag= ""; 79 byte 80 caractere; 81 for (byte i = 0; i < mfrc522.uid.size; i++) 82 { 83 Serial.print(mfrc522.uid.uidByte[i] 84 < 0x10 ? " 0" : " "); 85 Serial.print(mfrc522.uid.uidByte[i], HEX); 86 87 tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 88 tag.concat(String(mfrc522.uid.uidByte[i], 89 HEX)); 90 } 91 Serial.println(); 92 Serial.print("Message : "); 93 tag.toUpperCase(); 94 95 96 97 98 99 if (tag.substring(1) == "13 3E 9F 0D" || tag.substring(1) 100 == "04 1D 87 62 7F 71 81" || tag.substring(1) == "03 02 5E 11") 101 { 102 103 digitalWrite(lock, HIGH); 104 lcd.print("Access Allowed!!"); 105 Serial.println("TAG checked - Access allow !"); 106 Serial.println(); 107 delay(500); 108 digitalWrite(lock, 109 LOW); 110 111 digitalWrite(serrure, LOW); 112 lcd.clear(); 113 } 114 115 else 116 117 118 { 119 lcd.clear(); 120 lcd.print(" Access denied!"); 121 Serial.println("Unknown tag - Access refused !!!"); 122 Serial.println(); 123 124 for (int i= 1; 125 i<5 ; i++) 126 { 127 128 digitalWrite(lock, HIGH); 129 delay(200); 130 131 digitalWrite(lock, LOW); 132 delay(200); 133 } 134 } 135 delay(100); 136 lcd.clear(); 137}
Auto Clear After A Second
cpp
Again, please replace RFID numbers with your own
1#include <SPI.h> 2#include <MFRC522.h> 3 4#define SS_PIN 53 5#define 6 RST_PIN 9 7 8MFRC522 mfrc522(SS_PIN, RST_PIN); 9 10// for a led 11int 12 lock = 6; 13 14int serrure = 3; 15 16 17char st[20]; 18 19#include <LiquidCrystal.h> 20#define 21 I2C_ADDR 22 23// initialize the library by associating any needed LCD interface 24 pin 25// with the arduino pin number it is connected to 26const int rs = A3, en 27 = A5, d4 = A9, d5 = A10, d6 = A11, d7 = A12; 28LiquidCrystal lcd(rs, en, d4, d5, 29 d6, d7); 30void setup() 31{ 32 pinMode(lock, OUTPUT); 33 34 pinMode (serrure, 35 OUTPUT); 36 37 38 Serial.begin(9600); 39 SPI.begin(); 40 mfrc522.PCD_Init(); 41 42 Serial.println("Access test via RFID tag"); 43 Serial.println(); 44 pinMode(A14,OUTPUT); 45 46 pinMode(A13,OUTPUT); 47 pinMode(A4,OUTPUT); 48 pinMode(A0,OUTPUT); 49 pinMode(A2,OUTPUT); 50 51 pinMode(A1,OUTPUT); 52 digitalWrite(A14,LOW); 53 digitalWrite(A13,HIGH); 54 55 digitalWrite(A4,LOW); 56 digitalWrite(A0,LOW); 57 digitalWrite(A2,LOW); 58 59 digitalWrite(A1,HIGH); 60 lcd.begin(16, 2); 61} 62 63void loop() 64{ 65 66 int sensorReading = analogRead(A0); 67 // map the result to 200 - 1000: 68 69 int delayTime = map(sensorReading, 0, 1023, 200, 1000); 70 if ( ! mfrc522.PICC_IsNewCardPresent()) 71 72 { 73 return; 74 } 75 if ( ! mfrc522.PICC_ReadCardSerial()) 76 { 77 78 return; 79 } 80 Serial.print("Tag :"); 81 String tag= ""; 82 byte 83 caractere; 84 for (byte i = 0; i < mfrc522.uid.size; i++) 85 { 86 Serial.print(mfrc522.uid.uidByte[i] 87 < 0x10 ? " 0" : " "); 88 Serial.print(mfrc522.uid.uidByte[i], HEX); 89 90 tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 91 tag.concat(String(mfrc522.uid.uidByte[i], 92 HEX)); 93 } 94 Serial.println(); 95 Serial.print("Message : "); 96 tag.toUpperCase(); 97 98 99 100 101 102 if (tag.substring(1) == "13 3E 9F 0D") 103 { 104 lcd.setCursor(0, 105 0); 106 lcd.clear(); 107 digitalWrite(lock, HIGH); 108 lcd.print("Access 109 Allowed!!"); 110 lcd.setCursor(0, 1); 111 lcd.print("13 3E 9F 0D"); 112 113 Serial.println("TAG checked - Access allow !"); 114 Serial.println(); 115 116 delay(500); 117 digitalWrite(lock, LOW); 118 119 digitalWrite(serrure, 120 LOW); 121 122 } 123 else if (tag.substring(1) == "04 1D 87 62 7F 71 81") 124 125 { 126 lcd.setCursor(0, 0); 127 lcd.clear(); 128 digitalWrite(lock, HIGH); 129 130 lcd.print("Access Allowed!!"); 131 lcd.setCursor(0, 1); 132 lcd.print("041D87627F7181"); 133 134 Serial.println("TAG checked - Access allow !"); 135 Serial.println(); 136 137 delay(500); 138 digitalWrite(lock, LOW); 139 140 digitalWrite(serrure, 141 LOW); 142} 143else if (tag.substring(1) == "03 02 5E 11") 144{ 145 lcd.setCursor(0, 146 0); 147 lcd.clear(); 148 digitalWrite(lock, HIGH); 149 lcd.print("Access 150 Allowed!!"); 151 lcd.setCursor(0, 1); 152 lcd.print("03 02 5E 11"); 153 154 Serial.println("TAG checked - Access allow !"); 155 Serial.println(); 156 157 delay(500); 158 digitalWrite(lock, LOW); 159 160 digitalWrite(serrure, 161 LOW); 162} 163 else 164 165 { 166 lcd.setCursor(0, 0); 167 lcd.clear(); 168 169 lcd.print(" Access denied!"); 170 Serial.println("Unknown tag - Access 171 refused !!!"); 172 Serial.println(); 173 174 for (int i= 1; i<5 ; i++) 175 176 { 177 178 digitalWrite(lock, HIGH); 179 delay(200); 180 digitalWrite(lock, 181 LOW); 182 delay(200); 183 } 184 } 185 delay(1000); 186}
Don't Auto Clear
cpp
You will have to push the reset button every time.
1#include <SPI.h> 2#include <MFRC522.h> 3 4#define SS_PIN 53 5#define 6 RST_PIN 9 7 8MFRC522 mfrc522(SS_PIN, RST_PIN); 9 10// for a led 11int 12 lock = 6; 13 14int serrure = 3; 15 16 17char st[20]; 18 19#include <LiquidCrystal.h> 20#define 21 I2C_ADDR 22 23// initialize the library by associating any needed LCD interface 24 pin 25// with the arduino pin number it is connected to 26const int rs = A3, en 27 = A5, d4 = A9, d5 = A10, d6 = A11, d7 = A12; 28LiquidCrystal lcd(rs, en, d4, d5, 29 d6, d7); 30void setup() 31{ 32 pinMode(lock, OUTPUT); 33 34 pinMode (serrure, 35 OUTPUT); 36 37 38 Serial.begin(9600); 39 SPI.begin(); 40 mfrc522.PCD_Init(); 41 lcd.clear(); 42 Serial.println("Access test via RFID tag"); 43 Serial.println(); 44 pinMode(A14,OUTPUT); 45 46 pinMode(A13,OUTPUT); 47 pinMode(A4,OUTPUT); 48 pinMode(A0,OUTPUT); 49 pinMode(A2,OUTPUT); 50 51 pinMode(A1,OUTPUT); 52 digitalWrite(A14,LOW); 53 digitalWrite(A13,HIGH); 54 55 digitalWrite(A4,LOW); 56 digitalWrite(A0,LOW); 57 digitalWrite(A2,LOW); 58 59 digitalWrite(A1,HIGH); 60 lcd.begin(16, 2); 61} 62 63void loop() 64{ 65 66 int sensorReading = analogRead(A0); 67 // map the result to 200 - 1000: 68 69 int delayTime = map(sensorReading, 0, 1023, 200, 1000); 70 if ( ! mfrc522.PICC_IsNewCardPresent()) 71 72 { 73 return; 74 } 75 if ( ! mfrc522.PICC_ReadCardSerial()) 76 { 77 78 return; 79 } 80 Serial.print("Tag :"); 81 String tag= ""; 82 byte 83 caractere; 84 for (byte i = 0; i < mfrc522.uid.size; i++) 85 { 86 Serial.print(mfrc522.uid.uidByte[i] 87 < 0x10 ? " 0" : " "); 88 Serial.print(mfrc522.uid.uidByte[i], HEX); 89 90 tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 91 tag.concat(String(mfrc522.uid.uidByte[i], 92 HEX)); 93 } 94 Serial.println(); 95 Serial.print("Message : "); 96 tag.toUpperCase(); 97 98 99 100 101 102 if (tag.substring(1) == "13 3E 9F 0D") 103 { 104 lcd.setCursor(0, 105 0); 106 digitalWrite(lock, HIGH); 107 lcd.print("Access 108 Allowed!!"); 109 lcd.setCursor(0, 1); 110 lcd.print("13 3E 9F 0D"); 111 112 Serial.println("TAG checked - Access allow !"); 113 Serial.println(); 114 115 delay(500); 116 digitalWrite(lock, LOW); 117 118 digitalWrite(serrure, 119 LOW); 120 121 } 122 else if (tag.substring(1) == "04 1D 87 62 7F 71 81") 123 124 { 125 lcd.setCursor(0, 0); 126 digitalWrite(lock, HIGH); 127 128 lcd.print("Access Allowed!!"); 129 lcd.setCursor(0, 1); 130 lcd.print("041D87627F7181"); 131 132 Serial.println("TAG checked - Access allow !"); 133 Serial.println(); 134 135 delay(500); 136 digitalWrite(lock, LOW); 137 138 digitalWrite(serrure, 139 LOW); 140} 141else if (tag.substring(1) == "03 02 5E 11") 142{ 143 lcd.setCursor(0, 144 0); 145 digitalWrite(lock, HIGH); 146 lcd.print("Access Allowed!!"); 147 lcd.setCursor(0, 1); 148 lcd.print("03 02 5E 11"); 149 150 Serial.println("TAG checked - Access allow !"); 151 Serial.println(); 152 153 delay(500); 154 digitalWrite(lock, LOW); 155 156 digitalWrite(serrure, 157 LOW); 158} 159 else 160 161 { 162 lcd.setCursor(0, 0); 163 164 lcd.print(" Access denied!"); 165 Serial.println("Unknown tag - Access 166 refused !!!"); 167 Serial.println(); 168 169 for (int i= 1; i<5 ; i++) 170 171 { 172 173 digitalWrite(lock, HIGH); 174 delay(200); 175 digitalWrite(lock, 176 LOW); 177 delay(200); 178 } 179 } 180 delay(600); 181}
If you want to take it a step further
c_cpp
Again, please replace RFID numbers with your own
1#include <SPI.h> 2#include <MFRC522.h> 3 4#define SS_PIN 53 5#define RST_PIN 9 6 7MFRC522 mfrc522(SS_PIN, RST_PIN); 8 9// for a led 10int lock = 6; 11 12int serrure = 3; 13 14 15char st[20]; 16 17#include <LiquidCrystal.h> 18#define I2C_ADDR 19 20// initialize the library by associating any needed LCD interface pin 21// with the arduino pin number it is connected to 22const int rs = A3, en = A5, d4 = A9, d5 = A10, d6 = A11, d7 = A12; 23LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 24void setup() 25{ 26 pinMode(lock, OUTPUT); 27 28 pinMode (serrure, OUTPUT); 29 30 31 Serial.begin(9600); 32 SPI.begin(); 33 mfrc522.PCD_Init(); 34 Serial.println("Access test via RFID tag"); 35 Serial.println(); 36 pinMode(A14,OUTPUT); 37 pinMode(A13,OUTPUT); 38 pinMode(A4,OUTPUT); 39 pinMode(A0,OUTPUT); 40 pinMode(A2,OUTPUT); 41 pinMode(A1,OUTPUT); 42 digitalWrite(A14,LOW); 43 digitalWrite(A13,HIGH); 44 digitalWrite(A4,LOW); 45 digitalWrite(A0,LOW); 46 digitalWrite(A2,LOW); 47 digitalWrite(A1,HIGH); 48 lcd.begin(16, 2); 49} 50 51void loop() 52{ 53 int sensorReading = analogRead(A0); 54 // map the result to 200 - 1000: 55 int delayTime = map(sensorReading, 0, 1023, 200, 1000); 56 if ( ! mfrc522.PICC_IsNewCardPresent()) 57 { 58 return; 59 } 60 if ( ! mfrc522.PICC_ReadCardSerial()) 61 { 62 return; 63 } 64 Serial.print("Tag :"); 65 String tag= ""; 66 byte caractere; 67 for (byte i = 0; i < mfrc522.uid.size; i++) 68 { 69 Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); 70 Serial.print(mfrc522.uid.uidByte[i], HEX); 71 tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 72 tag.concat(String(mfrc522.uid.uidByte[i], HEX)); 73 } 74 Serial.println(); 75 Serial.print("Message : "); 76 tag.toUpperCase(); 77 78 79 80 81 if (tag.substring(1) == "13 3E 9F 0D") 82 { 83 lcd.setCursor(0, 0); 84 lcd.clear(); 85 digitalWrite(lock, HIGH); 86 lcd.print("Access Allowed!!"); 87 lcd.setCursor(0, 1); 88 lcd.print("13 3E 9F 0D"); 89 Serial.println("TAG checked - Access allow !"); 90 Serial.println(); 91 delay(500); 92 digitalWrite(lock, LOW); 93 94 digitalWrite(serrure, LOW); 95 96 } 97 else if (tag.substring(1) == "04 1D 87 62 7F 71 81") 98 { 99 lcd.setCursor(0, 0); 100 lcd.clear(); 101 digitalWrite(lock, HIGH); 102 lcd.print("Access Allowed!!"); 103 lcd.setCursor(0, 1); 104 lcd.print("041D87627F7181"); 105 Serial.println("TAG checked - Access allow !"); 106 Serial.println(); 107 delay(500); 108 digitalWrite(lock, LOW); 109 110 digitalWrite(serrure, LOW); 111} 112else if (tag.substring(1) == "03 02 5E 11") 113{ 114 lcd.setCursor(0, 0); 115 lcd.clear(); 116 digitalWrite(lock, HIGH); 117 lcd.print("Access Allowed!!"); 118 lcd.setCursor(0, 1); 119 lcd.print("03 02 5E 11"); 120 Serial.println("TAG checked - Access allow !"); 121 Serial.println(); 122 delay(500); 123 digitalWrite(lock, LOW); 124 125 digitalWrite(serrure, LOW); 126} 127 else 128 129 { 130 lcd.setCursor(0, 0); 131 lcd.clear(); 132 lcd.print(" Access denied!"); 133 Serial.println("Unknown tag - Access refused !!!"); 134 Serial.println(); 135 136 for (int i= 1; i<5 ; i++) 137 { 138 139 digitalWrite(lock, HIGH); 140 delay(200); 141 digitalWrite(lock, LOW); 142 delay(200); 143 } 144 } 145 delay(1000); 146}
Code For Simple Project
c_cpp
Please replace RFID numbers with your own.
1#include <SPI.h> 2#include <MFRC522.h> 3 4#define SS_PIN 53 5#define RST_PIN 9 6 7MFRC522 mfrc522(SS_PIN, RST_PIN); 8 9// for a led 10int lock = 6; 11 12int serrure = 3; 13 14 15char st[20]; 16 17#include <LiquidCrystal.h> 18#define I2C_ADDR 19 20// initialize the library by associating any needed LCD interface pin 21// with the arduino pin number it is connected to 22const int rs = A3, en = A5, d4 = A9, d5 = A10, d6 = A11, d7 = A12; 23LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 24void setup() 25{ 26 pinMode(lock, OUTPUT); 27 28 pinMode (serrure, OUTPUT); 29 30 31 Serial.begin(9600); 32 SPI.begin(); 33 mfrc522.PCD_Init(); 34 Serial.println("Access test via RFID tag"); 35 Serial.println(); 36 pinMode(A14,OUTPUT); 37 pinMode(A13,OUTPUT); 38 pinMode(A4,OUTPUT); 39 pinMode(A0,OUTPUT); 40 pinMode(A2,OUTPUT); 41 pinMode(A1,OUTPUT); 42 digitalWrite(A14,LOW); 43 digitalWrite(A13,HIGH); 44 digitalWrite(A4,LOW); 45 digitalWrite(A0,LOW); 46 digitalWrite(A2,LOW); 47 digitalWrite(A1,HIGH); 48 lcd.begin(16, 2); 49} 50 51void loop() 52{ 53 int sensorReading = analogRead(A0); 54 // map the result to 200 - 1000: 55 int delayTime = map(sensorReading, 0, 1023, 200, 1000); 56 if ( ! mfrc522.PICC_IsNewCardPresent()) 57 { 58 return; 59 } 60 if ( ! mfrc522.PICC_ReadCardSerial()) 61 { 62 return; 63 } 64 Serial.print("Tag :"); 65 String tag= ""; 66 byte caractere; 67 for (byte i = 0; i < mfrc522.uid.size; i++) 68 { 69 Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); 70 Serial.print(mfrc522.uid.uidByte[i], HEX); 71 tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 72 tag.concat(String(mfrc522.uid.uidByte[i], HEX)); 73 } 74 Serial.println(); 75 Serial.print("Message : "); 76 tag.toUpperCase(); 77 78 79 80 81 if (tag.substring(1) == "13 3E 9F 0D" || tag.substring(1) == "04 1D 87 62 7F 71 81" || tag.substring(1) == "03 02 5E 11") 82 { 83 lcd.clear(); 84 digitalWrite(lock, HIGH); 85 lcd.print("Access Allowed!!"); 86 Serial.println("TAG checked - Access allow !"); 87 Serial.println(); 88 delay(500); 89 digitalWrite(lock, LOW); 90 91 digitalWrite(serrure, LOW); 92 93 } 94 95 else 96 97 { 98 lcd.clear(); 99 lcd.print(" Access denied!"); 100 Serial.println("Unknown tag - Access refused !!!"); 101 Serial.println(); 102 103 for (int i= 1; i<5 ; i++) 104 { 105 106 digitalWrite(lock, HIGH); 107 delay(200); 108 digitalWrite(lock, LOW); 109 delay(200); 110 } 111 } 112 delay(1000); 113}
Downloadable files
Wiring Diagram
Wiring Diagram
Schematic
Schematic
Comments
Only logged in users can leave comments
ardwindow
0 Followers
•1 Projects
0
0