From d39683002691ce8838cb06c4641bab1a6a47f6af Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 21 May 2024 00:30:39 +0200 Subject: [PATCH] firmware wip - PINsoilmoisture is always HIGH and gets only low when waterlevel is measured --- Arduino/CanGrow/CanGrow.ino | 10 +++++++--- Arduino/CanGrow/CanGrow_Sensors.h | 13 ++++++++----- playground/html/root/index.html | 23 ++++++++++++----------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 12bc260..26bae8e 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -65,12 +65,16 @@ void setup() { // set all OUTPUT to low digitalWrite(PinFAN, LOW); digitalWrite(PINwaterlevel, LOW); - digitalWrite(PINsoilmoisture, LOW); digitalWrite(PinLED, LOW); digitalWrite(PinPUMP, LOW); - + // except PINsoilmoisture + // PINsoilmoisture is always HIGH and gets LOW in moment of waterlevel measurement + digitalWrite(PINsoilmoisture, HIGH); + // set PWM frequency lower to avoid annoying noises - // in combination with 47uF at fan output, 220Hz is kinda sweetspot + // in combination with 47uF at fan output, 220Hz is kinda sweetspot for a fan + // but i guess putting just a cap in parallel for voltage regulation isnt a good idea + // low pass filter or buck converter would be better // 220Hz is note A3 btw. analogWriteFreq(220); diff --git a/Arduino/CanGrow/CanGrow_Sensors.h b/Arduino/CanGrow/CanGrow_Sensors.h index c4d0731..8cd8242 100644 --- a/Arduino/CanGrow/CanGrow_Sensors.h +++ b/Arduino/CanGrow/CanGrow_Sensors.h @@ -53,11 +53,13 @@ int getWaterlevel(bool returnRAW = false) { short waterlevelRAW = 0; byte waterlevel = 0; + // disable first PINsoilmoisture + digitalWrite(PINsoilmoisture, LOW); // enable Vcc for water level sensor digitalWrite(PINwaterlevel, HIGH); // wait a bit to let the circuit stabilize // TODO: replace delay() with millis() - delay(50); + delay(100); // get the value for(byte i = 0; i < 10 ; i++) { @@ -67,7 +69,8 @@ int getWaterlevel(bool returnRAW = false) { // disable Vcc for the sensor to prevent electrolysis effect and release analog pin digitalWrite(PINwaterlevel, LOW); - + // and turn soilmoisture back on + digitalWrite(PINsoilmoisture, HIGH); if( waterlevelRAW >= waterlevelOK) { waterlevel = 0; } else if( waterlevelRAW >= waterlevelWARN) { @@ -131,9 +134,9 @@ int getSoilmoisture(byte moistureSensor, bool returnRAW = false) { wet = 180; dry= 590; - digitalWrite(PINsoilmoisture, HIGH); + //digitalWrite(PINsoilmoisture, HIGH); // wait a bit to let the circuit stabilize - delay(50); + //delay(50); // get analog input value // get values 10 times and get the middle for more precise data @@ -143,7 +146,7 @@ int getSoilmoisture(byte moistureSensor, bool returnRAW = false) { soilmoisture = soilmoisture / 10; // disable Vcc for the sensor to release analog pin - digitalWrite(PINsoilmoisture, LOW); + //digitalWrite(PINsoilmoisture, LOW); break; case 2: // read soil moisture from chrip I2C diff --git a/playground/html/root/index.html b/playground/html/root/index.html index 087761c..f6557ab 100644 --- a/playground/html/root/index.html +++ b/playground/html/root/index.html @@ -4,7 +4,7 @@ -CanGrow - Amnesia Haze +CanGrow - Ruderalis Indica -

🌱 Ruderalis Indica

@@ -197,10 +198,10 @@ input[type=text], input[type=date], input[type=number], input[type=password], se var gaugeSoilmoisture = new Gauge(document.getElementById('gaugeSoilmoisture')); -Grow started: 2024-05-08
-Day of Grow: 1
+Grow started: 2024-04-12
+Day of Grow: 33
Pump water level: Critical
-Growlight brightness: 100 %
+Growlight brightness: 69 %
MOSFET