From c62f482d1dcd930b861d246434edd725437c91d5 Mon Sep 17 00:00:00 2001 From: coolneng Date: Wed, 15 Mar 2023 04:03:22 +0100 Subject: [PATCH] Implement soil humidity logging to serial console --- src/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3b6e1f4..283c922 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,9 @@ DHT dht(DHTPIN, DHTTYPE); +int fc28_pin = A0; +int soil_threshold = 40; + void setup() { Serial.begin(9600); dht.begin(); @@ -13,8 +16,10 @@ void setup() { void loop() { char buffer[100]; - sprintf(buffer, "Temperature: %.2f °C Humidity: %.2f %%", - dht.readTemperature(), dht.readHumidity()); + int analog_val = analogRead(fc28_pin); + int soil_percentage = map(analog_val, 0, 1023, 0, 100); + sprintf(buffer, "Temperature: %.2f °C Humidity: %.2f %% Soil humidity: %i %%", + dht.readTemperature(), dht.readHumidity(), soil_percentage); Serial.println(buffer); delay(60000); }