From 87b2d4cb2c327e1d013c11f920f155c9cf60e99f Mon Sep 17 00:00:00 2001 From: sieja Date: Thu, 4 Sep 2025 19:20:56 +0200 Subject: [PATCH] PlantWaterer v0.1 --- ESP32/PlantWaterer/PlantWaterer.ino | 109 ++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 ESP32/PlantWaterer/PlantWaterer.ino diff --git a/ESP32/PlantWaterer/PlantWaterer.ino b/ESP32/PlantWaterer/PlantWaterer.ino new file mode 100644 index 0000000..5ef2727 --- /dev/null +++ b/ESP32/PlantWaterer/PlantWaterer.ino @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#define Version "0.1" +#define SCREEN_WIDTH 128 +#define SCREEN_HEIGHT 32 +#define OLED_RESET -1 +#define SCREEN_ADDRESS 0x3C +//PINS +#define WTR_SENSOR 4 //GPIO04 D4 +#define PIN_PUMP 26 //GPIO26 D26 +#define wetSoil 1200 // Define max value we consider soil 'wet' +#define midSoil 1730 // Define max value we consider soil 'wet' +#define drySoil 2400 // Define min value we consider soil 'dry' +#define AIR 3150 // Define min value we consider soil 'dry' +#define cupOfWater 1024 // Define min value we consider soil 'dry' +// #define LED_RED_TANK 26 //GPIO25 D25 +// #define WTR_LVL 33 //GPI +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); + +//MAIN VALUES VARIABLES +int moisture = 0; +int watertingCnt = 0; +int minValue = 5000; +int maxValue = 0; +int waitSec = 16; +int waitMs = 1000 * waitSec; + + void setup() { + pinMode(WTR_SENSOR, INPUT_PULLDOWN); + pinMode(PIN_PUMP, OUTPUT); + digitalWrite(PIN_PUMP, LOW); + Serial.begin(9600); + if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { + Serial.println(F("SSD1306 allocation failed")); + } + + display.setTextSize(1); + display.setTextColor(SSD1306_WHITE); + display.clearDisplay(); + display.setCursor(0, 0); + display.println("Version:"); + display.setCursor(60, 0); + display.println(Version); + display.display(); + moisture = analogRead(WTR_SENSOR); + delay(5000); + moisture = analogRead(WTR_SENSOR); + +} + +void loop() { + // ################################################### + // WYÚWIETLACZ + moisture = analogRead(WTR_SENSOR); + display.clearDisplay(); + display.setCursor(110, 0); + display.println(Version); + display.setCursor(0, 0); + display.println("cnt:"); + display.setCursor(25, 0); + display.println(watertingCnt); + display.setCursor(45, 0); + display.println("lvl:"); + display.setCursor(70, 0); + display.println(moisture); + display.setCursor(0, 10); + display.println("threshold:>"); + display.setCursor(73, 10); + display.println(drySoil); + +if (moisture > maxValue){ + maxValue = moisture; +} +if (moisture < minValue){ + minValue = moisture; +} + display.setCursor(0, 20); + display.println("min:"); + display.setCursor(23, 20); + display.println(minValue); + display.setCursor(70, 20); + display.println("max:"); + display.setCursor(93, 20); + display.println(maxValue); + + Serial.print("Analog output: "); + Serial.println(moisture); + + if (moisture < drySoil) { + Serial.println("Status: Soil is too wet"); + digitalWrite(PIN_PUMP, HIGH); + + } else { + display.fillCircle(110, 12, 5, SSD1306_WHITE); + display.display(); + Serial.println("Status: Soil is too dry - time to water!"); + digitalWrite(PIN_PUMP, LOW); + watertingCnt++; + delay(waitMs/4); + digitalWrite(PIN_PUMP, HIGH); +} + Serial.println(); + + display.fillCircle(110, 12, 5, SSD1306_BLACK); + display.display(); + delay(waitMs); +} \ No newline at end of file