#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <Keypad.h>
int servoPin = 6;
int Sensorpin =2;
int State = LOW;
int value = 0;
Servo myservo;
// Password Length
const int Password_Length = 4;
// Character to hold password input
String Data;
// Password
String pass= "ABCD";
// Counter for character entries
byte data_count = 0;
// Character to hold key input
char customKey;
// Constants for row and column sizes
const byte ROWS = 4;
const byte COLS = 4;
// Array to represent keys on keypad
char keymap[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// Connections to Arduino
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 1};
// Create keypad object
Keypad customKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define DHTPIN 13
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Setup LCD with backlight and initialize
lcd.init();
lcd.backlight();
myservo.attach(11);
pinMode(servoPin, OUTPUT);
pinMode(Sensorpin,INPUT);
}
void loop() {
// Initialize LCD and print
lcd.setCursor(0, 0);
lcd.print("Enter the Pass:");
// Look for keypress
customKey = customKeypad.getKey();
if (customKey) {
// Enter keypress into array and increment counter
Data += customKey;
lcd.setCursor(data_count, 1);
lcd.print(Data[data_count]);
data_count++;
}
// See if we have reached the password length
if (data_count == Password_Length) {
lcd.clear();
if (Data == pass) {
float Temperature = dht.readTemperature();
float Humidity = dht.readHumidity();
lcd.setCursor(0, 0);
lcd.print("Humidity: ");
lcd.print(Humidity);
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(Temperature);
delay(5000);
lcd.clear();
}
else {
// Incorrect Password
lcd.print("Wrong the pass");
delay(500);
lcd.clear();
lcd.print("Enter the password:");
}
// Clear data and LCD display
lcd.clear();
clearData();
}
value = digitalRead(Sensorpin); //
if (value == HIGH) { // check if the input is HIGH
myservo.write(90);
if (State == LOW) {
State = HIGH;
}
} else {
myservo.write(0);
if (State == HIGH) {
State = LOW;
}
}
}
void clearData() {
//Reset data_count
data_count = 0;
//Reset Data
Data ="";
}