#include <dht.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define dataPin 8 // Defines pin number to which the sensor is connected
#define relayPin 4 // Defines the pin for the relay
dht DHT; // Creates a DHT object
// Define the I2C address for the LCD
#define I2C_ADDR 0x27 // You may need to change this address based on your LCD
// Define LCD dimensions
#define LCD_COLS 16
#define LCD_ROWS 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLS, LCD_ROWS);
void setup()
{
Serial.begin(9600);
lcd.begin(LCD_COLS, LCD_ROWS);
// Set the relay pin as OUTPUT
pinMode(relayPin, OUTPUT);
}
void loop()
{
// Uncomment whatever type you're using!
int readData = DHT.read22(dataPin); // DHT22/AM2302
// int readData = DHT.read11(dataPin); // DHT11
float t = DHT.temperature; // Gets the values of the temperature
float h = DHT.humidity; // Gets the values of the humidity
// Display the results on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(t);
lcd.print((char)176);
lcd.print("C | ");
lcd.print((t * 9.0) / 5.0 + 32.0);
lcd.print((char)176);
lcd.println("F");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print(" %");
// Printing the results on the serial monitor
Serial.print("Temperature = ");
Serial.print(t);
Serial.print(" ");
Serial.print((char)176);
Serial.print("C | ");
Serial.print((t * 9.0) / 5.0 + 32.0);
Serial.print(" ");
Serial.print((char)176);
Serial.println("F ");
Serial.print("Humidity = ");
Serial.print(h);
Serial.println(" % ");
Serial.println("");
// Check if temperature is below 40
if (t < 40)
{
// Activate the relay
digitalWrite(relayPin, HIGH);
}
else
{
// Deactivate the relay
digitalWrite(relayPin, LOW);
Serial.println("Relay deactivated!");
}
if (h < 50)
{
digitalWrite(relayPin, LOW);
Serial.println("the floar is dry");
lcd.clear();
lcd.setCursor(0, 1);
lcd.print()
}
delay(2000); // Delays 2 seconds
}