#include <Keypad.h>
#define LED_PIN 12 // LED'i bu pine bağlayın
// Keypad tuş haritası (4x4 matris)
const byte ROWS = 4; // Satır sayısı
const byte COLS = 4; // Sütun sayısı
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; // Örnek: D8, D7, D6, D5
byte colPins[COLS] = {4, 3, 2, 1}; // Örnek: D4, D3, D2, D1
// Keypad nesnesini oluştur
Keypad customKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Doğru şifre
String correctPassword = "1456#"; // Şifrenizi burada değiştirebilirsiniz
// Girilen şifreyi tutacak değişken
String enteredPassword = "";
void setup() {
Serial.begin(9600);
Serial.println("Sifre ile LED Yakma Kontrolu (4x4 Keypad)");
Serial.print("Dogru Sifre: ");
Serial.println(correctPassword);
Serial.println("Sifrenizi girin ve sonuna '#' tusuna basin.");
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
}
void loop() {
// Keypad'den basılan tuşu oku
char customKey = customKeypad.getKey();
// Eğer bir tuşa basıldıysa
if (customKey) {
// Basılan tuşu seri ekrana yazdır
Serial.print("Basilan Tus: ");
Serial.println(customKey);
// Basılan tuşu girilen şifreye ekle
enteredPassword += customKey;
// Eğer basılan tuş '#' ise (şifre girişinin sonu)
if (customKey == '#') {
Serial.print("Girilen Sifre: ");
Serial.println(enteredPassword);
// Girilen şifre doğru mu kontrol et
if (enteredPassword == correctPassword) {
Serial.println("Sifre Dogru! LED yaniyor...");
digitalWrite(LED_PIN, HIGH); // LED'i yak
delay(2000);
digitalWrite(LED_PIN, LOW); // LED'i söndür
Serial.println("LED sondu.");
} else {
Serial.println("Sifre Yanlış! Lütfen tekrar deneyin.");
}
// Girilen şifreyi sıfırla, yeni bir giriş için hazır ol
enteredPassword = "";
}
// Şifrenin doğru şifre uzunluğunu aşmasını önlemek için basit bir kontrol
// '#' tuşuna basılmadan çok uzun bir giriş olursa şifreyi sıfırla
else if (enteredPassword.length() > correctPassword.length()) {
Serial.println("Geçersiz giriş uzunlugu. Sifirlaniyor...");
enteredPassword = ""; // Şifre uzunluğu aştığında sıfırla
}
}
}