// LCD1602 to Arduino Uno connection example
#include <LiquidCrystal.h>
#include "DHT.h"
#include <Servo.h>
Servo servo1;
const int servoPin1 = 3;
int val = 0;
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
const int numRows = 4;
const int numCols = 4;
const int debounceTime = 20;
const char keymap[numRows][numCols] = {
{ '1', '2', '3','A' } ,
{ '4', '5', '6','B' } ,
{ '7', '8', '9','C' } ,
{ '*', '0', '#','D' }
};
const int rowPins[numRows] = { 7, 2, 3, 6 };
const int colPins[numCols] = { 5, 8, 4, 9 };
void setup() {
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
lcd.print("Enter the password!");
Serial.begin(9600);
for (int row = 0; row < numRows; row++) {
pinMode(rowPins[row], INPUT);
digitalWrite(rowPins[row], HIGH);
}
for (int column = 0; column < numCols; column++) {
pinMode(colPins[column], OUTPUT);
digitalWrite(colPins[column], HIGH);
}
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
// ...
char key = getKey();
if (key != 0) {
Serial.print("Got key ");
Serial.println(key);
}
}
char getKey() {
char key = 0;
for (int column = 0; column < numCols; column++) {
digitalWrite(colPins[column], LOW);
for (int row = 0; row < numRows; row++) {
if (digitalRead(rowPins[row]) == LOW) {
delay(debounceTime);
while (digitalRead(rowPins[row]) == LOW)
;
key = keymap[row][column];
}
}
digitalWrite(colPins[column], HIGH);
}
return key;
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}