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