pflanzensensor-workshop/serial-out/serial-out.ino

45 lines
969 B
Arduino
Raw Normal View History

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-29 19:20:23 +01:00
Serial.begin(115200);
dht.setup(D0, DHTesp::DHT11); // Connect DHT sensor to D0
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-29 19:20:23 +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 {
Serial.print("Humidity: ");
Serial.print(humi);
Serial.print("%");
Serial.print(" | ");
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print(" C ");
Serial.print(" | ");
Serial.print("Moisture value: ");
Serial.println(soil);
}
// wait a 2 seconds between readings
delay(2000);
}