From b8490ebb837a038ec102f807bbd2780115e8c92d Mon Sep 17 00:00:00 2001 From: sotaro3 <99892530+sotaro3@users.noreply.github.com> Date: Tue, 30 Jan 2024 11:49:26 +0900 Subject: [PATCH] Create arduino_WateringN Refactored 4-way plant watering system to N-way with making it expandable for adusting moisture level on the fly. --- arduino_WateringN/arduino_WateringN | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 arduino_WateringN/arduino_WateringN diff --git a/arduino_WateringN/arduino_WateringN b/arduino_WateringN/arduino_WateringN new file mode 100644 index 0000000..5098482 --- /dev/null +++ b/arduino_WateringN/arduino_WateringN @@ -0,0 +1,36 @@ +// N-way plant Watering System +// refactored by T. Endo 2024.1.24 + +#define Interval 1000 +#define On LOW +#define Off HIGH +#define END (-1) +const char* Header = "MOISTURE LEVEL:"; +int MoistLevel = 750; // ajustable by adding some code. +// refactored to make Sensors and Pumps appendable before END. +const int Sensor[] = {A0, A1, A2, A3, END}; +const int Pump[] = {4, 5, 6, 7, END}; +// note: pins 2 & 3 should be reserved for interrupt, +// to add level adjustment functionality in the future +// because only those pins are available to early Arduinos. + +void setup() { + Serial.begin(9600); + for (int i=0; Pump[i] != END; i++) { + pinMode(Sensor[i], INPUT); + pinMode(Pump[i], OUTPUT); + digitalWrite(Pump[i], Off); + } + delay(500); +} +void loop() { + Serial.print(Header); + for (int i = 0; Pump[i] != END; i++) { + int value1 = analogRead(Sensor[i]); + Serial.println(value1); + digitalWrite(Pump[i], // higher as drier + (value1 > MoistLevel) ? On : Off ); + Serial.println(); + } + delay(Interval); +}