You are on page 1of 4

#include <LiquidCrystal.

h>

// LCD Pins

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// Potansiyometre Pin

const int potPin = A0;

// Buzzer

const int buzzerPin = 10;

// De?i?kenler

int selectedNumber = 0; // Seçilen say?

bool isUnlocked = false; // Kilit durumu

void setup() {

lcd.begin(16, 2);

pinMode(potPin, INPUT);
pinMode(buzzerPin, OUTPUT);

lcd.print("Enter Password:");

void loop() {

if (!isUnlocked) {

int potValue = analogRead(potPin); // Potansiyometre de?erini oku (0-1023 aras?)

selectedNumber = map(potValue, 0, 1023, 0, 9); // 0 ile 9 aras?nda say?ya dönü?tür

lcd.setCursor(0, 1);

lcd.print("Selected: ");

lcd.print(selectedNumber);

if (digitalRead(2) == LOW) { // Butona bas?ld???nda

checkPassword(selectedNumber); // ?ifreyi kontrol et

} else {

// ?ifre do?ruysa geri say?m

countdown();

}
void checkPassword(int number) {

// Burada ?ifrenin do?rulu?unu kontrol edebilirsiniz

if (number == 4 && !isUnlocked) { // Örnek bir ?ifre (4)

isUnlocked = true;

lcd.clear();

lcd.print("Unlocked");

} else {

// Yanl?? ?ifre durumu

lcd.clear();

lcd.print("Wrong Password");

delay(2000);

lcd.clear();

lcd.print("Enter Password:");

void countdown() {

static unsigned long lastTime = 0;

static int countdownValue = 40; // K?r?lma geri say?m süresi


if (millis() - lastTime > 1000) { // Her saniye azalt

lastTime = millis();

countdownValue--;

if (countdownValue <= 0) {

// Buzzer sesi

tone(buzzerPin, 1000);

lcd.clear();

lcd.print("Alarm!");

while (true); // Sonsuz döngüde kal

lcd.setCursor(0, 1);

lcd.print("Countdown: ");

lcd.print(countdownValue);

You might also like