#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>
#include <Servo.h>
// LCD kijelző beállításai
LiquidCrystal_I2C lcd(0x27, 16, 2);
// PIN-kód beállítása
const String correctPIN = "1234";
String enteredPIN = "";
int btn_value=0;
// Keypad beállításai
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const int ledPin = 10;
const int buzzerPin = 13;
int receiver_pin = 12;
IRrecv receiver(receiver_pin);
// Szervómotor beállítása
Servo servoMotor;
const int servoPin = 11; // Szervómotor csatlakozás
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("PIN: ");
servoMotor.attach(servoPin); // Szervó inicializálása
servoMotor.write(0);
receiver.enableIRIn();
}
void loop() {
char key = keypad.getKey();
if (key) {
handleKeypadInput(key);
}
if (receiver.decode())
{
translateIR();
} receiver.resume();
}
void handleKeypadInput(char key) {
if (key == '#') {
if (enteredPIN == correctPIN) {
lcd.clear();
lcd.print("Access Granted");
activateServo();
} else {
lcd.clear();
lcd.print("Access Denied");
triggerAlarm();
}
enteredPIN = "";
lcd.clear();
lcd.print("PIN: ");
} else if (key == '*') {
enteredPIN = "";
lcd.clear();
lcd.print("PIN: ");
} else {
enteredPIN += key;
lcd.setCursor(enteredPIN.length() + 3, 0);
lcd.print('*');
}
}
int translateIR(){
btn_value = receiver.decodedIRData.command;
Serial.println(btn_value);
if(btn_value == 162){
lcd.print("IR Access Granted");
activateServo();
delay(3000);
}
else {lcd.print("Unknown IR Code");}
delay(1000);
lcd.clear();
lcd.print("PIN: ");
}
void activateServo() {
servoMotor.write(90); // Szervómotor 90 fokba állítása (pl. ajtó nyitása)
delay(5000); // 5 másodpercig nyitva
servoMotor.write(0); // Szervómotor visszaállítása 0 fokra (pl. ajtó zárása)
}
// Riasztás indítása
void triggerAlarm() {
for (int i = 0; i < 5; i++) {
tone(buzzerPin, 1000,200); // 1000 Hz-es hang indítása
delay(100); // 100 ms-ig tart a hang
noTone(buzzerPin); // Hang leállítása
delay(100); // 100 ms szünet
}
lcd.clear();
lcd.print("PIN: ");
}