├── ARDUINO CODE.C ├── ARDUINO CODE.txt ├── ENERGY CONSERVATION USING AURDUINO.png ├── MATERIAL REQUIRED.txt └── rtc codes (1).txt /ARDUINO CODE.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | LiquidCrystal_PCF8574 lcd(0x3F); // set the LCD address to 0x27 for a 16 chars and 2 line display 7 | 8 | #define RST_PIN 5 // Configurable, see typical pin layout above 9 | #define SS_PIN 53 // Configurable, see typical pin layout above 10 | 11 | #include "RTClib.h" 12 | String otpstring = ""; 13 | 14 | RTC_DS1307 rtc; 15 | int hr=0; 16 | int mi=0; 17 | int cnt1=0; 18 | int p1=0; 19 | int a=0; 20 | int b=0; 21 | MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance 22 | String uid1 = "8A 8F 05 09"; 23 | String uid2 = "FA CA 7A 08"; 24 | String uid3 = "E7 F6 F4 3D"; 25 | String uid4 = "29 42 95 83"; 26 | 27 | #include 28 | const byte ROWS = 4; 29 | const byte COLS = 4; 30 | char hexaKeys[ROWS][COLS] = { 31 | {'1', '2', '3', 'A'}, 32 | {'4', '5', '6', 'B'}, 33 | {'7', '8', '9', 'C'}, 34 | {'*', '0', '#', 'D'} 35 | }; 36 | byte rowPins[ROWS] = {22,24,26,28}; 37 | byte colPins[COLS] = {30,32,34,36}; 38 | Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 39 | 40 | void getotp() 41 | { 42 | String y = ""; 43 | int a = y.length(); 44 | while (a < 4) 45 | { 46 | char customKey = customKeypad.getKey(); 47 | if (customKey) { 48 | lcd.setCursor(0, 1); 49 | y = y + customKey; 50 | lcd.print(y); 51 | a = y.length(); 52 | } 53 | } 54 | Serial.print("Entered OTP is "); 55 | Serial.println(y); 56 | if (y == "1234") 57 | { 58 | digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level) 59 | lcd.setCursor(13,0); 60 | lcd.print("ON "); 61 | } 62 | 63 | } 64 | 65 | 66 | void setup() 67 | { 68 | char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 69 | // initialize digital pin LED_BUILTIN as an output. 70 | pinMode(2, OUTPUT); 71 | digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level) 72 | pinMode(3, OUTPUT); 73 | digitalWrite(3, LOW); // turn the LED on (HIGH is the voltage level) 74 | 75 | Wire.begin(); 76 | Wire.beginTransmission(0x3F); 77 | lcd.begin(16, 2); // initialize the lcd 78 | lcd.setBacklight(255); 79 | Serial.begin(9600); // Initiate a serial communication 80 | SPI.begin(); // Initiate SPI bus 81 | mfrc522.PCD_Init(); // Initiate MFRC522 82 | Serial.println("Approximate your card to the reader..."); 83 | Serial.println(); 84 | if (! rtc.begin()) { 85 | Serial.println("Couldn't find RTC"); 86 | Serial.flush(); 87 | abort(); 88 | lcd.clear(); 89 | } 90 | if (! rtc.isrunning()) { 91 | Serial.println("RTC is NOT running, let's set the time!"); 92 | // When time needs to be set on a new device, or after a power loss, the 93 | // following line sets the RTC to the date & time this sketch was compiled 94 | // rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 95 | // This line sets the RTC with an explicit date & time, for example to set 96 | // January 21, 2014 at 3am you would call: 97 | // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 98 | } 99 | 100 | } 101 | void loop() 102 | { 103 | 104 | if(cnt1<=0) 105 | { 106 | digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level) 107 | lcd.setCursor(13,0); 108 | lcd.print("OFF"); 109 | } 110 | if(cnt1>0) 111 | { 112 | digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level) 113 | lcd.setCursor(13,0); 114 | lcd.print("ON "); 115 | } 116 | 117 | DateTime now = rtc.now(); 118 | hr=now.hour(); 119 | mi=now.minute(); 120 | lcd.setCursor(0,1); 121 | lcd.print(hr); 122 | lcd.setCursor(2,1); 123 | lcd.print(":"); 124 | lcd.setCursor(3,1); 125 | lcd.print(mi); 126 | 127 | lcd.setCursor(0,0); 128 | lcd.print("Scan Tag "); 129 | if((hr>9 && hr<=12) || (hr>13 && hr<16) ) 130 | { 131 | lcd.setCursor(8,1); 132 | lcd.print("CL"); 133 | } 134 | if((hr==13) || (hr>16) ) 135 | { 136 | lcd.setCursor(8,1); 137 | lcd.print("BR"); 138 | } 139 | 140 | // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle. 141 | if ( ! mfrc522.PICC_IsNewCardPresent()) 142 | { 143 | return; 144 | } 145 | // Select one of the cards 146 | // if((hr>9 && hr<13) || (hr>14 && hr<16)) 147 | if(hr>16) 148 | 149 | { 150 | if ( ! mfrc522.PICC_ReadCardSerial()) 151 | { 152 | return; 153 | } 154 | //Show UID on serial monitor 155 | Serial.print("UID tag :"); 156 | String content= ""; 157 | byte letter; 158 | for (byte i = 0; i < mfrc522.uid.size; i++) 159 | { 160 | Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); 161 | Serial.print(mfrc522.uid.uidByte[i], HEX); 162 | content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 163 | content.concat(String(mfrc522.uid.uidByte[i], HEX)); 164 | } 165 | lcd.clear(); 166 | Serial.println(); 167 | Serial.print("Message : "); 168 | content.toUpperCase(); 169 | if (content.substring(1) == uid1) //change here the UID of the card/cards that you want to give access 170 | { 171 | digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level) 172 | delay(500); 173 | digitalWrite(3, LOW); // turn the LED on (HIGH is the voltage level) 174 | 175 | Serial.println("Authorized access"); 176 | Serial.println(); 177 | lcd.setCursor(0,0); 178 | lcd.print("STUDENT 1"); 179 | a=!a; 180 | // lcd.setCursor(12,0); 181 | /// lcd.print(a); 182 | if(a==1) 183 | { 184 | cnt1=cnt1+1; 185 | } 186 | if(a==0) 187 | { 188 | cnt1=cnt1-1; 189 | } 190 | lcd.setCursor(14,1); 191 | lcd.print(cnt1); 192 | delay(2000); 193 | 194 | } 195 | 196 | else if (content.substring(1) == uid2) //change here the UID of the card/cards that you want to give access 197 | { 198 | digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level) 199 | delay(500); 200 | digitalWrite(3, LOW); // turn the LED on (HIGH is the voltage level) 201 | Serial.println("Authorized access"); 202 | Serial.println(); 203 | lcd.setCursor(0,0); 204 | lcd.print("STUDENT 2"); 205 | b=!b; 206 | // lcd.setCursor(12,0); 207 | // lcd.print(b); 208 | if(b==1) 209 | { 210 | cnt1=cnt1+1; 211 | } 212 | if(b==0) 213 | { 214 | cnt1=cnt1-1; 215 | } 216 | lcd.setCursor(14,1); 217 | lcd.print(cnt1); 218 | delay(2000); 219 | } 220 | else if (content.substring(1) == uid3) //change here the UID of the card/cards that you want to give access 221 | { 222 | Serial.println("Authorized access"); 223 | Serial.println(); 224 | lcd.setCursor(0,0); 225 | lcd.print("TEACHER"); 226 | getotp(); 227 | delay(2000); 228 | } 229 | 230 | /*else if (content.substring(1) == uid4) //change here the UID of the card/cards that you want to give access 231 | { 232 | Serial.println("Authorized access"); 233 | Serial.println(); 234 | lcd.setCursor(0,0); 235 | lcd.print("Tag 04"); 236 | lcd.setCursor(0,1); 237 | lcd.print("Authorized access"); 238 | delay(3000); 239 | lcd.clear(); 240 | }*/ 241 | else { 242 | Serial.println(" Access Denied"); 243 | lcd.setCursor(3,0); 244 | lcd.clear(); 245 | lcd.print("Unknown"); 246 | lcd.setCursor(0,1); 247 | lcd.print("Access Denied"); 248 | delay(3000); 249 | lcd.clear(); 250 | } 251 | } 252 | } -------------------------------------------------------------------------------- /ARDUINO CODE.txt: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | LiquidCrystal_PCF8574 lcd(0x3F); // set the LCD address to 0x27 for a 16 chars and 2 line display 7 | 8 | #define RST_PIN 5 // Configurable, see typical pin layout above 9 | #define SS_PIN 53 // Configurable, see typical pin layout above 10 | 11 | #include "RTClib.h" 12 | String otpstring = ""; 13 | 14 | RTC_DS1307 rtc; 15 | int hr=0; 16 | int mi=0; 17 | int cnt1=0; 18 | int p1=0; 19 | int a=0; 20 | int b=0; 21 | MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance 22 | String uid1 = "8A 8F 05 09"; 23 | String uid2 = "FA CA 7A 08"; 24 | String uid3 = "E7 F6 F4 3D"; 25 | String uid4 = "29 42 95 83"; 26 | 27 | #include 28 | const byte ROWS = 4; 29 | const byte COLS = 4; 30 | char hexaKeys[ROWS][COLS] = { 31 | {'1', '2', '3', 'A'}, 32 | {'4', '5', '6', 'B'}, 33 | {'7', '8', '9', 'C'}, 34 | {'*', '0', '#', 'D'} 35 | }; 36 | byte rowPins[ROWS] = {22,24,26,28}; 37 | byte colPins[COLS] = {30,32,34,36}; 38 | Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 39 | 40 | void getotp() 41 | { 42 | String y = ""; 43 | int a = y.length(); 44 | while (a < 4) 45 | { 46 | char customKey = customKeypad.getKey(); 47 | if (customKey) { 48 | lcd.setCursor(0, 1); 49 | y = y + customKey; 50 | lcd.print(y); 51 | a = y.length(); 52 | } 53 | } 54 | Serial.print("Entered OTP is "); 55 | Serial.println(y); 56 | if (y == "1234") 57 | { 58 | digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level) 59 | lcd.setCursor(13,0); 60 | lcd.print("ON "); 61 | } 62 | 63 | } 64 | 65 | 66 | void setup() 67 | { 68 | char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 69 | // initialize digital pin LED_BUILTIN as an output. 70 | pinMode(2, OUTPUT); 71 | digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level) 72 | pinMode(3, OUTPUT); 73 | digitalWrite(3, LOW); // turn the LED on (HIGH is the voltage level) 74 | 75 | Wire.begin(); 76 | Wire.beginTransmission(0x3F); 77 | lcd.begin(16, 2); // initialize the lcd 78 | lcd.setBacklight(255); 79 | Serial.begin(9600); // Initiate a serial communication 80 | SPI.begin(); // Initiate SPI bus 81 | mfrc522.PCD_Init(); // Initiate MFRC522 82 | Serial.println("Approximate your card to the reader..."); 83 | Serial.println(); 84 | if (! rtc.begin()) { 85 | Serial.println("Couldn't find RTC"); 86 | Serial.flush(); 87 | abort(); 88 | lcd.clear(); 89 | } 90 | if (! rtc.isrunning()) { 91 | Serial.println("RTC is NOT running, let's set the time!"); 92 | // When time needs to be set on a new device, or after a power loss, the 93 | // following line sets the RTC to the date & time this sketch was compiled 94 | // rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 95 | // This line sets the RTC with an explicit date & time, for example to set 96 | // January 21, 2014 at 3am you would call: 97 | // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 98 | } 99 | 100 | } 101 | void loop() 102 | { 103 | 104 | if(cnt1<=0) 105 | { 106 | digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level) 107 | lcd.setCursor(13,0); 108 | lcd.print("OFF"); 109 | } 110 | if(cnt1>0) 111 | { 112 | digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level) 113 | lcd.setCursor(13,0); 114 | lcd.print("ON "); 115 | } 116 | 117 | DateTime now = rtc.now(); 118 | hr=now.hour(); 119 | mi=now.minute(); 120 | lcd.setCursor(0,1); 121 | lcd.print(hr); 122 | lcd.setCursor(2,1); 123 | lcd.print(":"); 124 | lcd.setCursor(3,1); 125 | lcd.print(mi); 126 | 127 | lcd.setCursor(0,0); 128 | lcd.print("Scan Tag "); 129 | if((hr>9 && hr<=12) || (hr>13 && hr<16) ) 130 | { 131 | lcd.setCursor(8,1); 132 | lcd.print("CL"); 133 | } 134 | if((hr==13) || (hr>16) ) 135 | { 136 | lcd.setCursor(8,1); 137 | lcd.print("BR"); 138 | } 139 | 140 | // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle. 141 | if ( ! mfrc522.PICC_IsNewCardPresent()) 142 | { 143 | return; 144 | } 145 | // Select one of the cards 146 | // if((hr>9 && hr<13) || (hr>14 && hr<16)) 147 | if(hr>16) 148 | 149 | { 150 | if ( ! mfrc522.PICC_ReadCardSerial()) 151 | { 152 | return; 153 | } 154 | //Show UID on serial monitor 155 | Serial.print("UID tag :"); 156 | String content= ""; 157 | byte letter; 158 | for (byte i = 0; i < mfrc522.uid.size; i++) 159 | { 160 | Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); 161 | Serial.print(mfrc522.uid.uidByte[i], HEX); 162 | content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 163 | content.concat(String(mfrc522.uid.uidByte[i], HEX)); 164 | } 165 | lcd.clear(); 166 | Serial.println(); 167 | Serial.print("Message : "); 168 | content.toUpperCase(); 169 | if (content.substring(1) == uid1) //change here the UID of the card/cards that you want to give access 170 | { 171 | digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level) 172 | delay(500); 173 | digitalWrite(3, LOW); // turn the LED on (HIGH is the voltage level) 174 | 175 | Serial.println("Authorized access"); 176 | Serial.println(); 177 | lcd.setCursor(0,0); 178 | lcd.print("STUDENT 1"); 179 | a=!a; 180 | // lcd.setCursor(12,0); 181 | /// lcd.print(a); 182 | if(a==1) 183 | { 184 | cnt1=cnt1+1; 185 | } 186 | if(a==0) 187 | { 188 | cnt1=cnt1-1; 189 | } 190 | lcd.setCursor(14,1); 191 | lcd.print(cnt1); 192 | delay(2000); 193 | 194 | } 195 | 196 | else if (content.substring(1) == uid2) //change here the UID of the card/cards that you want to give access 197 | { 198 | digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level) 199 | delay(500); 200 | digitalWrite(3, LOW); // turn the LED on (HIGH is the voltage level) 201 | Serial.println("Authorized access"); 202 | Serial.println(); 203 | lcd.setCursor(0,0); 204 | lcd.print("STUDENT 2"); 205 | b=!b; 206 | // lcd.setCursor(12,0); 207 | // lcd.print(b); 208 | if(b==1) 209 | { 210 | cnt1=cnt1+1; 211 | } 212 | if(b==0) 213 | { 214 | cnt1=cnt1-1; 215 | } 216 | lcd.setCursor(14,1); 217 | lcd.print(cnt1); 218 | delay(2000); 219 | } 220 | else if (content.substring(1) == uid3) //change here the UID of the card/cards that you want to give access 221 | { 222 | Serial.println("Authorized access"); 223 | Serial.println(); 224 | lcd.setCursor(0,0); 225 | lcd.print("TEACHER"); 226 | getotp(); 227 | delay(2000); 228 | } 229 | 230 | /*else if (content.substring(1) == uid4) //change here the UID of the card/cards that you want to give access 231 | { 232 | Serial.println("Authorized access"); 233 | Serial.println(); 234 | lcd.setCursor(0,0); 235 | lcd.print("Tag 04"); 236 | lcd.setCursor(0,1); 237 | lcd.print("Authorized access"); 238 | delay(3000); 239 | lcd.clear(); 240 | }*/ 241 | else { 242 | Serial.println(" Access Denied"); 243 | lcd.setCursor(3,0); 244 | lcd.clear(); 245 | lcd.print("Unknown"); 246 | lcd.setCursor(0,1); 247 | lcd.print("Access Denied"); 248 | delay(3000); 249 | lcd.clear(); 250 | } 251 | } 252 | } -------------------------------------------------------------------------------- /ENERGY CONSERVATION USING AURDUINO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THARUN1526/Energy-conservation-using-aurduino/20b5dfd5062d743681f775bcc574502e486eea43/ENERGY CONSERVATION USING AURDUINO.png -------------------------------------------------------------------------------- /MATERIAL REQUIRED.txt: -------------------------------------------------------------------------------- 1 | MATERIAL REQUIRED: 2 | 1.ARDUINO 3 | 2.RFID READER 4 | 3.LCD DISPLAY 5 | 4.KEYPAD 6 | 5.RTC MODULE 7 | 6.I2C MODULE 8 | 7.GSM MODULE 9 | 8.JUMPER WIRE 10 | 9.BUZZER 11 | 10.SOFTWARE -------------------------------------------------------------------------------- /rtc codes (1).txt: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | LiquidCrystal_PCF8574 lcd(0x3F); // set the LCD address to 0x27 for a 16 chars and 2 line display 7 | 8 | #define RST_PIN 5 // Configurable, see typical pin layout above 9 | #define SS_PIN 53 // Configurable, see typical pin layout above 10 | 11 | #include "RTClib.h" 12 | String otpstring = ""; 13 | 14 | RTC_DS1307 rtc; 15 | int hr=0; 16 | int mi=0; 17 | int cnt1=0; 18 | int p1=0; 19 | int a=0; 20 | int b=0; 21 | MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance 22 | String uid1 = "8A 8F 05 09"; 23 | String uid2 = "FA CA 7A 08"; 24 | String uid3 = "E7 F6 F4 3D"; 25 | String uid4 = "29 42 95 83"; 26 | 27 | #include 28 | const byte ROWS = 4; 29 | const byte COLS = 4; 30 | char hexaKeys[ROWS][COLS] = { 31 | {'1', '2', '3', 'A'}, 32 | {'4', '5', '6', 'B'}, 33 | {'7', '8', '9', 'C'}, 34 | {'*', '0', '#', 'D'} 35 | }; 36 | byte rowPins[ROWS] = {22,24,26,28}; 37 | byte colPins[COLS] = {30,32,34,36}; 38 | Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 39 | 40 | void getotp() 41 | { 42 | String y = ""; 43 | int a = y.length(); 44 | while (a < 4) 45 | { 46 | char customKey = customKeypad.getKey(); 47 | if (customKey) { 48 | lcd.setCursor(0, 1); 49 | y = y + customKey; 50 | lcd.print(y); 51 | a = y.length(); 52 | } 53 | } 54 | Serial.print("Entered OTP is "); 55 | Serial.println(y); 56 | if (y == "1234") 57 | { 58 | digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level) 59 | lcd.setCursor(13,0); 60 | lcd.print("ON "); 61 | } 62 | 63 | } 64 | 65 | 66 | void setup() 67 | { 68 | char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 69 | // initialize digital pin LED_BUILTIN as an output. 70 | pinMode(2, OUTPUT); 71 | digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level) 72 | pinMode(3, OUTPUT); 73 | digitalWrite(3, LOW); // turn the LED on (HIGH is the voltage level) 74 | 75 | Wire.begin(); 76 | Wire.beginTransmission(0x3F); 77 | lcd.begin(16, 2); // initialize the lcd 78 | lcd.setBacklight(255); 79 | Serial.begin(9600); // Initiate a serial communication 80 | SPI.begin(); // Initiate SPI bus 81 | mfrc522.PCD_Init(); // Initiate MFRC522 82 | Serial.println("Approximate your card to the reader..."); 83 | Serial.println(); 84 | if (! rtc.begin()) { 85 | Serial.println("Couldn't find RTC"); 86 | Serial.flush(); 87 | abort(); 88 | lcd.clear(); 89 | } 90 | if (! rtc.isrunning()) { 91 | Serial.println("RTC is NOT running, let's set the time!"); 92 | // When time needs to be set on a new device, or after a power loss, the 93 | // following line sets the RTC to the date & time this sketch was compiled 94 | // rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 95 | // This line sets the RTC with an explicit date & time, for example to set 96 | // January 21, 2014 at 3am you would call: 97 | // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 98 | } 99 | 100 | } 101 | void loop() 102 | { 103 | 104 | if(cnt1<=0) 105 | { 106 | digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level) 107 | lcd.setCursor(13,0); 108 | lcd.print("OFF"); 109 | } 110 | if(cnt1>0) 111 | { 112 | digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level) 113 | lcd.setCursor(13,0); 114 | lcd.print("ON "); 115 | } 116 | 117 | DateTime now = rtc.now(); 118 | hr=now.hour(); 119 | mi=now.minute(); 120 | lcd.setCursor(0,1); 121 | lcd.print(hr); 122 | lcd.setCursor(2,1); 123 | lcd.print(":"); 124 | lcd.setCursor(3,1); 125 | lcd.print(mi); 126 | 127 | lcd.setCursor(0,0); 128 | lcd.print("Scan Tag "); 129 | if((hr>9 && hr<=12) || (hr>13 && hr<16) ) 130 | { 131 | lcd.setCursor(8,1); 132 | lcd.print("CL"); 133 | } 134 | if((hr==13) || (hr>16) ) 135 | { 136 | lcd.setCursor(8,1); 137 | lcd.print("BR"); 138 | } 139 | 140 | // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle. 141 | if ( ! mfrc522.PICC_IsNewCardPresent()) 142 | { 143 | return; 144 | } 145 | // Select one of the cards 146 | // if((hr>9 && hr<13) || (hr>14 && hr<16)) 147 | if(hr>16) 148 | 149 | { 150 | if ( ! mfrc522.PICC_ReadCardSerial()) 151 | { 152 | return; 153 | } 154 | //Show UID on serial monitor 155 | Serial.print("UID tag :"); 156 | String content= ""; 157 | byte letter; 158 | for (byte i = 0; i < mfrc522.uid.size; i++) 159 | { 160 | Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); 161 | Serial.print(mfrc522.uid.uidByte[i], HEX); 162 | content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 163 | content.concat(String(mfrc522.uid.uidByte[i], HEX)); 164 | } 165 | lcd.clear(); 166 | Serial.println(); 167 | Serial.print("Message : "); 168 | content.toUpperCase(); 169 | if (content.substring(1) == uid1) //change here the UID of the card/cards that you want to give access 170 | { 171 | digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level) 172 | delay(500); 173 | digitalWrite(3, LOW); // turn the LED on (HIGH is the voltage level) 174 | 175 | Serial.println("Authorized access"); 176 | Serial.println(); 177 | lcd.setCursor(0,0); 178 | lcd.print("STUDENT 1"); 179 | a=!a; 180 | // lcd.setCursor(12,0); 181 | /// lcd.print(a); 182 | if(a==1) 183 | { 184 | cnt1=cnt1+1; 185 | } 186 | if(a==0) 187 | { 188 | cnt1=cnt1-1; 189 | } 190 | lcd.setCursor(14,1); 191 | lcd.print(cnt1); 192 | delay(2000); 193 | 194 | } 195 | 196 | else if (content.substring(1) == uid2) //change here the UID of the card/cards that you want to give access 197 | { 198 | digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level) 199 | delay(500); 200 | digitalWrite(3, LOW); // turn the LED on (HIGH is the voltage level) 201 | Serial.println("Authorized access"); 202 | Serial.println(); 203 | lcd.setCursor(0,0); 204 | lcd.print("STUDENT 2"); 205 | b=!b; 206 | // lcd.setCursor(12,0); 207 | // lcd.print(b); 208 | if(b==1) 209 | { 210 | cnt1=cnt1+1; 211 | } 212 | if(b==0) 213 | { 214 | cnt1=cnt1-1; 215 | } 216 | lcd.setCursor(14,1); 217 | lcd.print(cnt1); 218 | delay(2000); 219 | } 220 | else if (content.substring(1) == uid3) //change here the UID of the card/cards that you want to give access 221 | { 222 | Serial.println("Authorized access"); 223 | Serial.println(); 224 | lcd.setCursor(0,0); 225 | lcd.print("TEACHER"); 226 | getotp(); 227 | delay(2000); 228 | } 229 | 230 | /*else if (content.substring(1) == uid4) //change here the UID of the card/cards that you want to give access 231 | { 232 | Serial.println("Authorized access"); 233 | Serial.println(); 234 | lcd.setCursor(0,0); 235 | lcd.print("Tag 04"); 236 | lcd.setCursor(0,1); 237 | lcd.print("Authorized access"); 238 | delay(3000); 239 | lcd.clear(); 240 | }*/ 241 | else { 242 | Serial.println(" Access Denied"); 243 | lcd.setCursor(3,0); 244 | lcd.clear(); 245 | lcd.print("Unknown"); 246 | lcd.setCursor(0,1); 247 | lcd.print("Access Denied"); 248 | delay(3000); 249 | lcd.clear(); 250 | } 251 | } 252 | } --------------------------------------------------------------------------------