Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Studant Tag ---> 29 EC 2A B9
- //Dr Card #1 ---> 22 AC 75 34
- //Dr Card #2 ---> B6 BC 72 2B
- //Dr Card #3 ---> C0 6B BB 32
- //Dr Card #4 ---> C0 BD B6 32
- /*
- RFID Cards x5 [All Open] ✔
- Button [To Enter with No CARD] ✔
- LCD 20*4 [Show (IN#)+(OUT#)+(Current#)] ✔
- IR Sensor [Exit] ✔
- Servo_IN ✔
- Servo_OUT ✔
- */
- #include <SPI.h>
- #include <Wire.h>
- #include <Servo.h>
- #include <MFRC522.h>
- #include <LiquidCrystal_I2C.h>
- #define SS_PIN 10
- #define RST_PIN 9
- #define button_PIN 8
- #define exit_PIN 7
- Servo servoIN; //5
- Servo servoOUT; //6
- MFRC522 mfrc522(SS_PIN, RST_PIN);
- LiquidCrystal_I2C lcd(0x27, 20, 4);
- int INcount = 0;
- int OUTcount = 0;
- int CurrentCount = 0;
- int exit_status = 0;
- int button_status = 0;
- void setup() {
- Serial.begin(9600);
- pinMode(button_PIN, INPUT);
- pinMode(exit_PIN, INPUT);
- SPI.begin();
- mfrc522.PCD_Init();
- servoIN.attach(5);
- servoOUT.attach(6);
- servoIN.write(0);
- servoOUT.write(0);
- lcd.init();
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("Starting...");
- delay(1000);
- lcd.setCursor(0, 0);
- lcd.print("Total Inside: ");
- lcd.print(CurrentCount);
- lcd.setCursor(0, 1);
- lcd.print("Total IN: ");
- lcd.print(INcount);
- lcd.setCursor(0, 2);
- lcd.print("Total OUT: ");
- lcd.print(OUTcount);
- }
- void loop() {
- lcd.setCursor(0, 0);
- lcd.print("Total Inside: ");
- lcd.print(CurrentCount);
- lcd.print(" ");
- lcd.setCursor(0, 1);
- lcd.print("Total IN: ");
- lcd.print(INcount);
- lcd.print(" ");
- lcd.setCursor(0, 2);
- lcd.print("Total OUT: ");
- lcd.print(OUTcount);
- lcd.print(" ");
- button_status = digitalRead(button_PIN);
- exit_status = digitalRead(exit_PIN);
- if ( button_status > 0) {
- // Open IN Gate
- INcount = INcount + 1;
- CurrentCount = INcount - OUTcount;
- servoIN.write(90);
- delay(3000);
- servoIN.write(0);
- }
- if (exit_status == 0) {
- // Open OUT Gate
- OUTcount = OUTcount + 1;
- CurrentCount = INcount - OUTcount;
- if (CurrentCount < 0) {
- CurrentCount = 0;
- OUTcount = OUTcount - 1;
- }
- servoOUT.write(90);
- delay(3000);
- servoOUT.write(0);
- }
- if ( ! mfrc522.PICC_IsNewCardPresent()) {
- return;
- }
- if ( ! mfrc522.PICC_ReadCardSerial() ) {
- return;
- }
- String content = "";
- byte letter;
- for (byte i = 0; i < mfrc522.uid.size; i++) {
- Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
- Serial.print(mfrc522.uid.uidByte[i], HEX);
- content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
- content.concat(String(mfrc522.uid.uidByte[i], HEX));
- }
- Serial.println();
- content.toUpperCase();
- //Studant Tag ---> 29 EC 2A B9
- //Dr Card #1 ---> 22 AC 75 34
- //Dr Card #2 ---> B6 BC 72 2B
- //Dr Card #3 ---> C0 6B BB 32
- //Dr Card #4 ---> C0 BD B6 32
- // 1 2 3 4 5
- if (content.substring(1) == "29 EC 2A B9" || content.substring(1) == "22 AC 75 34" || content.substring(1) == "B6 BC 72 2B" || content.substring(1) == "C0 BD B6 32" || content.substring(1) == "C0 6B BB 32")
- {
- // Open IN Gate
- INcount = INcount + 1;
- CurrentCount = INcount - OUTcount;
- servoIN.write(90);
- delay(3000);
- servoIN.write(0);
- }
- else
- {
- // Don't Open IN Gate
- servoIN.write(0);
- }
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment