From 33d313c68ee9cd2e0c9dd34da3421914bb4ea1b6 Mon Sep 17 00:00:00 2001 From: Marcus Date: Sun, 7 Apr 2024 01:56:33 +0200 Subject: [PATCH] add analog soil moisture --- Arduino/CanGrow/CanGrow.ino | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 62c3d4d..058615f 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -167,22 +167,34 @@ float getHumidity() { } int getSoilmoisture(bool moistureSensor) { + // value to return int soilmoisture; + // value for wet + int wet; + // value for dry + int dry; if(moistureSensor == false ) { // read analog value from analog moisture sensor + wet = 185; + dry= 590; + digitalWrite(PINsoilmoisture, HIGH); // wait a bit to let the circuit stabilize delay(100); + // get analog input value soilmoisture = analogRead(PINanalog); // disable Vcc for the sensor to release analog pin digitalWrite(PINsoilmoisture, LOW); } else { // read soil moisture from chrip I2C + wet = 580; + dry= 250; + // get raw value from I2C chirp sensor soilmoisture = readI2CRegister16bit(0x20, 0); } - return soilmoisture; + return map(soilmoisture, wet, dry, 100, 0); } int getLightchirp() { @@ -285,7 +297,7 @@ void loop() { display.display(); Serial.println("Test"); - delay(1000); + //delay(1000); }