#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Wire.h>
int dhtPin =13;
#define DHTTYPE DHT22
LiquidCrystal_I2C lcd(0x27,16,2);
DHT dht(dhtPin,DHTTYPE);
int motorPin=12;
int R=0;
int L=0;
int ledPin =3;
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] = {11, 10, 9, 8};
byte colPins[COLS] = {7, 6, 5, 4};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
// put your setup code here, to run once:
dht.begin();
pinMode(motorPin,OUTPUT);
pinMode(ledPin, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print ("welcom to my project");
lcd.clear();
lcd.print("enter temperatur:");
// get the first number from the keypad
lcd.setCursor(0,1);
char key = keypad.waitForKey();
while (key != '#') {
if (key >= '0' && key <= '9') {
R = R * 10 + (key - '0');
lcd.print(key);
}
key = keypad.waitForKey();
}
lcd.clear();
lcd.print("enter huméditie :");
// get the first number from the keypad
lcd.setCursor(0,1);
key = keypad.waitForKey();
while (key != '#') {
if (key >= '0' && key <= '9') {
L = L * 10 + (key - '0');
lcd.print(key);
}
key = keypad.waitForKey();
}
while(R>80 or R<-20){
lcd.clear();
lcd.setCursor(3,1);
lcd.print("erreur !!!");
delay(1000);
Write_again();
break;
}
while(R>100 or R<0){
lcd.clear();
lcd.setCursor(3,1);
lcd.print("erreur !!!");
delay(1000);
Write_again();
break;
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("h%:");
lcd.setCursor(0,1);
lcd.print("T C:");
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(motorPin, LOW);
digitalWrite(ledPin, LOW);
float T =dht.readTemperature();
float H =dht.readHumidity();
lcd.setCursor(4,0);
lcd.print(H);
lcd.setCursor(7,1);
lcd.print(T);
if (R<T or H<L){
digitalWrite(motorPin, HIGH);
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(motorPin, LOW);
digitalWrite(ledPin, LOW);
}
}
void Write_again(){
lcd.clear();
lcd.print("enter temperatur:");
// get the first number from the keypad
lcd.setCursor(0,1);
char key = keypad.waitForKey();
while (key != '#') {
if (key >= '0' && key <= '9') {
R = R * 10 + (key - '0');
lcd.print(key);
}
key = keypad.waitForKey();
}
lcd.clear();
lcd.print("enter huméditie :");
// get the first number from the keypad
lcd.setCursor(0,1);
key = keypad.waitForKey();
while (key != '#') {
if (key >= '0' && key <= '9') {
L = L * 10 + (key - '0');
lcd.print(key);
}
key = keypad.waitForKey();
}
}