changed code for D1

This commit is contained in:
simonox 2022-12-29 19:20:23 +01:00
parent b5b57b5942
commit 344812d012

View file

@ -1,29 +1,26 @@
#include <DHT.h> #include "DHTesp.h"
#define DHT_SENSOR_PIN 21 // ESP32 pin GIOP21 connected to DHT11 sensor #define AOUT_PIN A0
#define DHT_SENSOR_TYPE DHT11
#define AOUT_PIN 36 // ESP32 pin GIOP36 (ADC0) that connects to AOUT pin of moisture sensor
DHT dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE); DHTesp dht;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(115200);
dht_sensor.begin(); // initialize the DHT sensor dht.setup(D0, DHTesp::DHT11); // Connect DHT sensor to D0
} }
void loop() { void loop() {
// read humidity // read humidity
float humi = dht_sensor.readHumidity(); float humi = dht.getHumidity();
// read temperature in Celsius // read temperature in Celsius
float tempC = dht_sensor.readTemperature(); float tempC = dht.getTemperature();
// read temperature in Fahrenheit
float tempF = dht_sensor.readTemperature(true);
// read soil // read soil
int soil = analogRead(AOUT_PIN); // read the analog value from sensor int soil = analogRead(AOUT_PIN); // read the analog value from sensor
// check whether the reading is successful or not // check whether the reading is successful or not
if ( isnan(tempC) || isnan(tempF) || isnan(humi)) { if ( isnan(tempC) || isnan(humi)) {
Serial.println("Failed to read from DHT sensor!"); Serial.println("Failed to read from DHT sensor!");
} if (isnan(soil)) { } if (isnan(soil)) {
Serial.println("Failed to read from soil sensor!"); Serial.println("Failed to read from soil sensor!");
@ -37,8 +34,6 @@ void loop() {
Serial.print("Temperature: "); Serial.print("Temperature: ");
Serial.print(tempC); Serial.print(tempC);
Serial.print(" C "); Serial.print(" C ");
Serial.print(tempF);
Serial.print(" F");
Serial.print(" | "); Serial.print(" | ");
Serial.print("Moisture value: "); Serial.print("Moisture value: ");
Serial.println(soil); Serial.println(soil);