/* DHT-22 sensor with 12c 16x2 LCD with Arduino uno
Temperature and humidity sensor displayed in LCD
based on: http://www.ardumotive.com/how-to-use-dht-22-sensor-en.html and
https://www.ardumotive.com/i2clcden.html for the i2c LCD library by Michalis Vasilakis
Recompile by adhitadhitadhit
Notes: use LCD i2c Library from link above, i'm not sure why but new Liquidcristal library from Francisco Malpartida isn't working for me
other thing, check your */
//Libraries
#include <dht.h> // sensor library using lib from https://www.ardumotive.com/how-to-use-dht-22-sensor-en.html
#include <LiquidCrystal_I2C.h> // LCD library using from https://www.ardumotive.com/i2clcden.html for the i2c LCD library
#include <Wire.h>
dht DHT;
//Constants
#define DHT22_PIN 2 // DHT 22 (AM2302) - pin used for DHT22
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 after finding it from serial monitor (see comment above) for a 16 chars and 2 line display
//Variables
int hum; //Stores humidity value
int temp; //Stores temperature value
const int RELAY1=10; //Red LED
const int RELAY2=11; //Green LED
const int RELAY3=12; //Lock Relay or motor
const int up_key=3;
const int down_key=4;
int SetPoint=30;
void setup()
{
pinMode(RELAY1,OUTPUT);
pinMode(RELAY2,OUTPUT);
pinMode(RELAY3,OUTPUT);
pinMode(up_key,INPUT);
pinMode(down_key,INPUT);
digitalWrite(up_key,LOW);
digitalWrite(down_key,LOW);
digitalWrite(RELAY1,LOW); //Red LED On
digitalWrite(RELAY2,LOW); //Turn off Relay
digitalWrite(RELAY3,LOW); //Turn off Relay
Serial.begin(9600);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setBacklight(HIGH);
}
void loop()
{
int chk = DHT.read22(DHT22_PIN);
//Read data and store it to variables hum and temp
hum = DHT.humidity;
temp= DHT.temperature;
//Print temp and humidity values to LCD
lcd.setCursor(0,0);
lcd.print("Homoditi:");
lcd.print(hum);
lcd.print("%");
lcd.setCursor(0,1);
lcd.print("Temperatur:");
lcd.print(temp);
lcd.println("C");
delay(2000); //Delay 2 sec between temperature/humidity check.
//Get user input for setpoints
if(digitalRead(down_key)==HIGH)
{
if(SetPoint>0)
{
SetPoint--;
}
}
if(digitalRead(up_key)==HIGH)
{
if(SetPoint<100)
{
SetPoint++;
}
}
//Display Set point on LCD
lcd.setCursor(0,2);
lcd.print("Set Point:");
lcd.print(SetPoint);
lcd.print("C ");
//Check Temperature is in limit
if(temp > SetPoint)
{
digitalWrite(RELAY1,LOW); //Turn off heater
digitalWrite(RELAY2,LOW);
digitalWrite(RELAY3,HIGH); //Turn on Green LED
}
else
{
digitalWrite(RELAY1,HIGH); //Turn on heater
digitalWrite(RELAY2,LOW);
digitalWrite(RELAY3,HIGH);
delay(2000);
//Turn on RED LED
}
}
//=================================================================