/* How to use the DHT-22 sensor with Arduino uno
Temperature and humidity sensor
*/
//Libraries
#include <DHT.h>;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//i2c pins
LiquidCrystal_I2C lcd(0x27, 16,2 ); //
//Constants
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
//ldr variable declaring
const int ledPin = 5; // digital pin 5
const int ldrPin = A0; // analog pin 0
//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup()
{
Serial.begin(9600);
dht.begin();
lcd.backlight();//Power on the back light
lcd.init();
pinMode(ldrPin, INPUT); // Here LDR sensor is determined as input
}
void loop()
{
delay(2000); //DELAY before starting loop
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
// Print temp and humidity values to serial monitor
//humidity
Serial.print("Humidity: ");
Serial.print(hum);
lcd.setCursor(0,0); //we start writing from the first row first column
lcd.print("Humidity:");
lcd.print(hum);
lcd.print("%"); //16 characters poer line
delay(1000);
//temperature
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
lcd.setCursor(0,1);
lcd.print("Temp:");
lcd.print(temp);
lcd.print("C");
delay(10000); //Delay 2 sec.
int ldrStatus = analogRead(ldrPin); //reading data from ldr sensor by analog pin
if (ldrStatus <= 200) {digitalWrite(ledPin, HIGH); // If LDR senses darkness led pin high that means led will glow.
Serial.print("Darkness over here,turn on the LED :");
Serial.println(ldrStatus);
} else {
digitalWrite(ledPin, LOW); // If LDR senses light led pin low that means led will stop glowing.
Serial.print("There is sufficient light , turn off the LED : ");
Serial.println(ldrStatus);
lcd.clear();//Clean the screen
//Write your text:
}}