#include<LiquidCrystal_I2C.h>
#include<DHT.h>
#include<Keypad.h>
#define red 14
#define green 15
#define DHTPIN 4
#define push 13
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,16,2);
String c_p="Press 'C' to confirm password reset..";
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]={23,19,18,5};
byte colPins[COLS]={32,33,25,26};
Keypad keypad =Keypad(makeKeymap(keys),rowPins,colPins,ROWS,COLS);
void scrollMessage(int row, String message, int delayTime, int totalColumns) {
for (int i=0; i < totalColumns; i++) {
message = " " + message;
}
message = message + " ";
for (int position = 0; position < message.length(); position++) {
lcd.setCursor(0, row);
lcd.print(message.substring(position, position + totalColumns));
delay(delayTime);
}
}
void setup() {
pinMode(push,INPUT);
pinMode(green,OUTPUT);
pinMode(red, OUTPUT);
lcd.init();
lcd.clear();
lcd.backlight();
lcd.setCursor(0,0);
dht.begin();
lcd.begin(16,2);
}
void loop() {
float t=dht.readTemperature();
float h=dht.readHumidity();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp:");
lcd.print(t);
lcd.print(" C");
lcd.setCursor(0,1);
lcd.print("Hum:");
lcd.print(h);
lcd.print(" %");
char k = keypad.getKey();
char p=keypad.waitForKey();
if(p=='A')
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("enter password:");
char password[4]={'0','0','0','0'};
char code[4];
int i = 0;
while (i < 4) {
char key = keypad.getKey();
if (key != NO_KEY) {
code[i++] = key;
lcd.setCursor(i-1, 1);
lcd.print("*");
}
}
if (memcmp(code,password,4) == 0) {
lcd.setCursor(0,0);
lcd.clear();
lcd.print("Access granted");
digitalWrite(green,HIGH);
delay(1000);
digitalWrite(green,LOW);
} else {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Access denied");
digitalWrite(red,HIGH);
delay(1000);
digitalWrite(red,LOW);
}
}
delay(10);
}