0% found this document useful (0 votes)
8 views3 pages

Listing Program

The document contains an Arduino program that utilizes RFID technology to control a servo lock based on scanned UID cards. It initializes an LCD display and prompts the user to scan a card, checking if the scanned UID matches a predefined list of valid UIDs to either unlock or lock a door. The program also provides feedback on the LCD display regarding the status of the door and any invalid card scans.

Uploaded by

jihanayu436
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Listing Program

The document contains an Arduino program that utilizes RFID technology to control a servo lock based on scanned UID cards. It initializes an LCD display and prompts the user to scan a card, checking if the scanned UID matches a predefined list of valid UIDs to either unlock or lock a door. The program also provides feedback on the LCD display regarding the status of the door and any invalid card scans.

Uploaded by

jihanayu436
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

LISTING PROGRAM

#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
String validUIDs[] = {"CB5C3C03", "F9BDC701"};
byte lock = 0;
Servo servo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 rfid(SS_PIN, RST_PIN);
void setup() {
Serial.begin(9600);
servo.write(70);
lcd.init();
lcd.backlight();
servo.attach(3);
SPI.begin();
rfid.PCD_Init();
lcd.setCursor(0, 0);
lcd.print("Tempelkan Kartu");
}
void loop() {
if (!rfid.PICC_IsNewCardPresent()) {
return; }
if (!rfid.PICC_ReadCardSerial()) {

8
return; }
8
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Scanning");
String scannedUID = "";
for (byte i = 0; i < rfid.uid.size; i++) {
// Memastikan bahwa UID diproses dalam format HEX
scannedUID.concat(String(rfid.uid.uidByte[i] < 0x10 ? "0" : ""));
scannedUID.concat(String(rfid.uid.uidByte[i], HEX));
delay(300);
}
// Convert UID to uppercase for consistency
scannedUID.toUpperCase(); // Pastikan huruf kapital
Serial.print("Scanned UID: ");
Serial.println(scannedUID); // Cek UID yang dipindai
bool isValidUID = false;
for (int i = 0; i < 2; i++) {
if (scannedUID == validUIDs[i]) {
isValidUID = true;
break; }
}
if (isValidUID && lock == 0) {
servo.write(160); // Buka pintu
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("PINTU TERBUKA");

9
delay(1500);
lcd.clear();
lock = 1;
} else if (isValidUID && lock == 1) {
servo.write(70); // Kunci pintu
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("PINTU TERKUNCI");
delay(1500);
lcd.clear();
lock = 0;
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SALAH KARTU");
delay(1500);
lcd.clear();
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TEMPELKAN KARTU");
delay(1500);
}

10

You might also like