#include "DHT.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h> //https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
LiquidCrystal_I2C lcd(0x27, 16, 2);
//here we use 14 of ESP32 to read data
#define DHTPIN 2 //A13
//our sensor is DHT11 type
#define DHTTYPE DHT11
//create an instance of DHT sensor
DHT dht(DHTPIN, DHTTYPE);
#define ADC_VREF_mV 3300.0 // in millivolt
#define ADC_RESOLUTION 4096.0
#define PIN_LM35 34 // ESP32 pin GIOP36 (ADC0) connected to LM35
int rainPin = A0;
int moisPin = A3;
void setup()
{
Serial.begin(9600);
Serial.println("DHT11 sensor!");
//call begin to start sensor
dht.begin();
lcd.init();
lcd.backlight();
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("IOT BASED");
lcd.setCursor(0,1);
lcd.print("AGRICULTURE MON");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Rain: ");
int rainValue = analogRead(rainPin);
//int raValue = map(rainValue , 0,1023,255,0);
lcd.print(rainValue);
Serial.print(rainValue);
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Moisture: ");
int moisValue = analogRead(moisPin);
//int moValue = map(moValue , 550,0,0,100);
Serial.print(moisValue);
lcd.print(moisValue);
delay(2000);
delay (2000);
//use the functions which are supplied by library.
float h = dht.readHumidity();
delay(2000);
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Humidity: ");
// print the result to Terminal
Serial.print("Humidity: ");
lcd.print(h);
lcd.print(" %\t");
Serial.print(h);
Serial.print(" %\t");
lcd.setCursor(0,1);
lcd.print("Temperature: ");
Serial.print("Temperature: ");
lcd.print(t);
Serial.print(t);
Serial.println(" *C ");
//we delay a little bit for next read
delay(2000);
}