Knock Door - 090017
Knock Door - 090017
Knock Door - 090017
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
Servo lockServo;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Address 0x27, 16 columns, 2 rows
const int knockThreshold = 400; // Adjust this threshold based on your environment
int knockCount = 0;
unsigned long lastKnockTime = 0;
const int knockTimeout = 300; // Timeout between knocks in milliseconds
void setup() {
lockServo.attach(9);
lcd.init();
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Knock Me!");
lcd.setCursor(3,1);
lcd.print("To Enter");
}
void loop() {
int soundValue = analogRead(soundSensorPin);
if (knockCount < 5) {
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Knock Me!");
lcd.setCursor(3,1);
lcd.print("To Enter");
void lockDoor() {
lockServo.write(0);
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Knock Me!");
lcd.setCursor(3,1);
lcd.print("To Enter");
isLocked = true;
}
void unlockDoor() {
lockServo.write(90);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Welcome Home!");
lcd.setCursor(6,1);
lcd.print("Pogi");
isLocked = false;
unlockTime = millis(); // Record the time when the door was unlocked
}