Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
tum_yil_icin_arduino_mufredati_36.2
#include <SPI.h>
#include <MFRC522.h>
#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);
#define RST_PIN 9
#define SS_PIN 10
#define Role 7
MFRC522 mfrc522(SS_PIN, RST_PIN);
String lastRfid = "";
String kart1 = "";
String kart2 = "";
MFRC522::MIFARE_Key key;
void setup()
{
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
lcd.begin();
lcd.backlight();
// Ekrana yazdırılacak metin
lcd.setCursor(0,0);
lcd.print("RFID Kapi");
lcd.setCursor(0,1);
lcd.print("Kilit Sistemi");
delay(5000);
lcd.clear();
pinMode(Role, OUTPUT);
Serial.println("RFID KART OKUMA UYGULAMASI");
Serial.println("--------------------------");
Serial.println();
//EEPROM'dan kart bilgisini oku
readEEPROM();
}
void loop()
{
//yeni kart okununmadıkça devam etme
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//kartın UID'sini oku, rfid isimli string'e kaydet
String rfid = "";
for (byte i = 0; i < mfrc522.uid.size; i++)
{
rfid += mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ";
rfid += String(mfrc522.uid.uidByte[i], HEX);
}
//string'in boyutunu ayarla ve tamamını büyük harfe çevir
rfid.trim();
rfid.toUpperCase();
if (rfid == lastRfid)
return;
lastRfid = rfid;
Serial.print("Kart 1: ");
Serial.println(kart1);
Serial.print("Kart 2: ");
Serial.println(kart2);
Serial.print("Okunan: ");
Serial.println(rfid);
Serial.println();
//1 nolu kart okunduysa LED'i yak, 2 nolu kart okunduysa LED'i söndür
if (rfid == kart1)
{
digitalWrite(Role,HIGH);
Serial.println("Kart1 Tarafindan Kapi Acildi");
lcd.setCursor(0,0);
lcd.print("Kart1 Tarafindan");
lcd.setCursor(0,1);
lcd.print("KAPI Acildi");
delay(2500);
digitalWrite(Role,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("IYI GUNLER");
lcd.setCursor(0,1);
lcd.print("TAG'i Okutun");
}
if (rfid == kart2)
{
digitalWrite(Role, HIGH);
Serial.println("Kart2 Tarafindan KAPI Acildi.");
lcd.setCursor(0,0);
lcd.print("Kart2 Tarafindan");
lcd.setCursor(0,1);
lcd.print("KAPI Acildi");
delay(2500);
digitalWrite(Role,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("IYI GUNLER");
lcd.setCursor(0,1);
lcd.print("TAG'i Okutun");
}
Serial.println();
delay(200);
}
void readEEPROM()
{
//EEPROM'dan ilk kartın UID'sini oku (ilk 4 byte)
for (int i = 0 ; i < 4 ; i++)
{
kart1 += EEPROM.read(i) < 0x10 ? " 0" : " ";
kart1 += String(EEPROM.read(i), HEX);
}
//EEPROM'dan ikinci kartın UID'sini oku
for (int i = 4 ; i < 8 ; i++)
{
kart2 += EEPROM.read(i) < 0x10 ? " 0" : " ";
kart2 += String(EEPROM.read(i), HEX);
}
//Okunan stringleri düzenle
kart1.trim();
kart1.toUpperCase();
kart2.trim();
kart2.toUpperCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.