diff --git a/RFID.ino b/RFID.ino new file mode 100644 index 0000000..3a7b68b --- /dev/null +++ b/RFID.ino @@ -0,0 +1,91 @@ +#include +#include +#include +#include + +#define SS_PIN 10 +#define RST_PIN 9 +#define LED_G 5 //Pin Led Hijau +#define LED_R 4 //Pin Led Merah +#define BUZZER 2 //Pin Buzzer +MFRC522 mfrc522(SS_PIN, RST_PIN); // deklarasi RFID +Servo myServo; //Nama Servo +LiquidCrystal_I2C lcd(0x3F ,2,1,0,4,5,6,7,3, POSITIVE); + +void setup() +{ + myServo.write(0); + delay(1000); + Serial.begin(9600); //Komunikasi baud rate + SPI.begin(); + mfrc522.PCD_Init(); + myServo.attach(3); + pinMode(LED_G, OUTPUT); + pinMode(LED_R, OUTPUT); + pinMode(BUZZER, OUTPUT); + noTone(BUZZER); + lcd.begin(16,2); + lcd.setCursor(4,0); + lcd.print("DEKATKAN"); + lcd.setCursor(5,1); + lcd.print("KARTU"); + +} +void loop() +{ + if ( ! mfrc522.PICC_IsNewCardPresent()) + { + return; + } + if ( ! mfrc522.PICC_ReadCardSerial()) + { + return; + + 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(); + Serial.print("Message : "); + content.toUpperCase(); + if (content.substring(1) == "04 16 62 9A EF 2C 80" || content.substring(1) == "7D 8F 63 D3" || content.substring(1) == "04 5C 8C 2A 59 28 80") //Ganti UID TAG DENGAN PUNYA MAS-NYA + { + lcd.clear(); + lcd.setCursor(5, 0); + lcd.print("AKSES"); + lcd.setCursor(4, 1); + lcd.print("DI TERIMA"); + delay(500); + digitalWrite(LED_G, HIGH); + tone(BUZZER, 500); + delay(300); + tone(BUZZER, 400); + delay(300); + tone(BUZZER, 300); + delay(300); + noTone(BUZZER); + digitalWrite(LED_G, LOW); + myServo.write(0); + delay(5000); + myServo.write(70); + } + + else { + lcd.clear(); + lcd.setCursor(5, 0); + lcd.print("AKSES"); + lcd.setCursor(4, 1); + lcd.print("DI TOLAK"); + digitalWrite(LED_R, HIGH); + tone(BUZZER, 300); + delay(1000); + digitalWrite(LED_R, LOW); + noTone(BUZZER); + } + lcd.clear(); + lcd.setCursor(4,0); + lcd.print("DEKATKAN"); + lcd.setCursor(5,1); + lcd.print("KARTU"); +}