2022-12-29 19:20:23 +01:00
|
|
|
#include "DHTesp.h"
|
|
|
|
#define AOUT_PIN A0
|
2022-12-20 16:03:44 +01:00
|
|
|
|
2022-12-29 19:20:23 +01:00
|
|
|
DHTesp dht;
|
2022-12-20 16:03:44 +01:00
|
|
|
|
|
|
|
void setup() {
|
2022-12-30 11:37:35 +01:00
|
|
|
Serial.begin(115200); // use this baud rate in serial monitor to see stuff
|
2023-02-26 17:08:33 +01:00
|
|
|
dht.setup(D1, DHTesp::DHT11); // Connect DHT sensor to D1
|
2022-12-20 16:03:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
// read humidity
|
2022-12-29 19:20:23 +01:00
|
|
|
float humi = dht.getHumidity();
|
2022-12-20 16:03:44 +01:00
|
|
|
// read temperature in Celsius
|
2022-12-29 19:20:23 +01:00
|
|
|
float tempC = dht.getTemperature();
|
2022-12-20 16:03:44 +01:00
|
|
|
// read soil
|
|
|
|
int soil = analogRead(AOUT_PIN); // read the analog value from sensor
|
|
|
|
|
|
|
|
// check whether the reading is successful or not
|
2022-12-30 11:37:35 +01:00
|
|
|
if (isnan(tempC) || isnan(humi)) {
|
2022-12-20 16:03:44 +01:00
|
|
|
Serial.println("Failed to read from DHT sensor!");
|
|
|
|
} if (isnan(soil)) {
|
|
|
|
Serial.println("Failed to read from soil sensor!");
|
|
|
|
} else {
|
2022-12-30 11:37:35 +01:00
|
|
|
|
2022-12-20 16:03:44 +01:00
|
|
|
Serial.print("Humidity: ");
|
|
|
|
Serial.print(humi);
|
|
|
|
Serial.print("%");
|
|
|
|
|
|
|
|
Serial.print(" | ");
|
|
|
|
|
|
|
|
Serial.print("Temperature: ");
|
|
|
|
Serial.print(tempC);
|
|
|
|
Serial.print(" C ");
|
2022-12-30 11:37:35 +01:00
|
|
|
|
2022-12-20 16:03:44 +01:00
|
|
|
Serial.print(" | ");
|
2022-12-30 11:37:35 +01:00
|
|
|
|
2022-12-20 16:03:44 +01:00
|
|
|
Serial.print("Moisture value: ");
|
|
|
|
Serial.println(soil);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait a 2 seconds between readings
|
|
|
|
delay(2000);
|
|
|
|
}
|