Professional Documents
Culture Documents
h>
#define RX 2
#define TX 3
#include <Wire.h>
//#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>
dht DHT;
#define DHT11_PIN 9 // This pin 9 use for sensor sense from DHT11
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the I2C bus address for an
unmodified module
//const int ledPin = 6; // pin that the LED is attached to
SoftwareSerial esp8266(RX,TX);
void setup()
{
esp8266.begin(115200);
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH); // NOTE: You can turn the backlight off by setting it
to LOW instead of HIGH
lcd.begin(16, 2);
lcd.clear();
pinMode(bulbPin, OUTPUT);
pinMode(ExhaustPin, OUTPUT);
pinMode(FanPin, OUTPUT);
pinMode(HeaterPin, OUTPUT);
pinMode(ldrPin, INPUT);
//Turn all the relay OFF on initial State
digitalWrite(bulbPin, HIGH);
digitalWrite(ExhaustPin, HIGH);
digitalWrite(FanPin, HIGH);
digitalWrite(HeaterPin, HIGH);
Serial.begin(9600);
}
void loop()
{
ldr();
TempHum();
lcd.setCursor(0,0);
lcd.print("Temp Hum Light");
}
void ldr()
{
int ldrStatus = analogRead(ldrPin);
if (ldrStatus <= 200) {
digitalWrite(bulbPin, LOW);
Serial.print("Its DARK, Turn on the LED : ");
Serial.println(ldrStatus);
lcd.setCursor(12,1);
lcd.println("ON ");
}
else
{
digitalWrite(bulbPin, HIGH);
Serial.print("Its BRIGHT, Turn off the LED : ");
Serial.println(ldrStatus);
lcd.setCursor(12,1);
lcd.print("Off ");
}
}
void TempHum()
{
int chk = DHT.read11(DHT11_PIN);
float temp=(DHT.temperature); //Temperature reading
//float temp = 36;
float Hum=(DHT.humidity);
// Temperature and humidity display on LCD
//lcd.print("Temp C ");
lcd.setCursor(0,1);
lcd.print(temp);
//lcd.setCursor(0,1);
//lcd.println("Humid % ");
lcd.setCursor(6,1);
lcd.print(Hum);
countTimeCommand++;
}
if(found == true)
{
Serial.println("OK");
countTrueCommand++;
countTimeCommand = 0;
}
if(found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}