// LCD1602 to Arduino Uno connection example
#include <DHT.h>;
#include <LiquidCrystal.h>
#include <Servo.h>
//Constants
#define DHTPIN 2 // DHT SDA pin connected to Pin 2
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
Servo myservo; // create servo object to control a servo
//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
int temp1; // displacement in degree
void setup()
{
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
lcd.print("Green house automation");
lcd.setCursor(0,0);
myservo.attach(5); // attaches the servo on pin 5 to the servo object
Serial.begin(9600);
dht.begin();
}
void loop()
{
delay(2000);
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
lcd.setCursor(0, 0);
lcd.print("Humi: ");
lcd.setCursor(5, 0);
lcd.print(hum);
lcd.setCursor(7, 0);
lcd.print("%,Temp: ");
lcd.setCursor(14, 0);
lcd.print(temp);// reads the value of the potentiometer (value between 0 and 1023)
temp1 = map(temp, 0,63,0, 180); // scale it to use it with the servo (value between 0 and 180)
// temp1= 180;
myservo.write(temp1); // sets the servo position according to the scaled value
Serial.print(temp1);
delay(15);
lcd.setCursor(0,1);
lcd.print("Motor on :");
lcd.setCursor(11, 1);
lcd.print(temp1);
delay(10000); //Delay 2 sec.
}