During the summer, we usually go sailing for 3-5 weeks, and in this time our indoor plants need water ( or at least that's the story, in reality I just found the idea funny to play around with).
Again the Arduino Nano was my place to go to, this time a Arduino Nano Every, a little DC motor(wrs-385sa) with a Peristaltic pump, from something I disassembled long time ago, and a dual relay board.
The fist little mockup looked like this:
The sensor I used was the common available. The one used was a Chinese brand, but is is pretty much the same as the one SparkFun has.
After about a week of testing and coding, the values I was reading started to drift, and I use at least 2 days of debugging, before I - mostly by accident, had a look at the sensor.
The metal on one of the electrodes was basically gone, so here was my problem.
The metal on one of the electrodes was basically gone, so here was my problem.
If you need something that should work more than a couple of days, I can recommend using a capacitive soil moisture sensor instead, like the one one below, it is a bit more expensive (~ 6 Euro @ arduino.cc), but worth it.
After a few months of constant use, it still works like a charm:
After a few months of constant use, it still works like a charm:
After the code was done, and the hardware stated to turn out as I wanted it to, next step was to transform it to something 'I would be able to look at every day, and one thing was, I would only use one relay, and I would like to get the breadboard out of the way, so i started to draw this:
It basically ended out as a more generic controlboard, that later on could be used for a hydroponics project as well( and proberly a lot of other stuff, )
A new version of the PCB is in the making , the main difference is that the smd components is gone and replaced by ordinary components, and instead of pins for one sensor, the new board har pins for 3 sensors, in order to take into account if the canister where the water is drained from is empty and a sensor to detect a overflow on the plant. I also added 2 LED's, again I see this board as a easy small generic project board, that I hope to reuse for other stuff as well...To be continued..
Note: the plant used is Ginger ;)
Note: the plant used is Ginger ;)
Arduino Code:
// Sense moisture in soil, and start pump(relay) to water the plant if needed. // https://wiki.dfrobot.com/Capacitive_Soil_Moisture_Sensor_SKU_SEN0193 char newstate[5][5][10] = { {"1", "Soaked", "0", "271", "3600000"}, // 60 min. Water {"2", "Moist", "271", "350" ,"1800000"}, // 30 min. Wet {"3", "Damp", "351", "430", "900000" }, // 15 min. // 450 Damp {"4", "Dry ", "431", "520", "300000" }, // 5 min. Dry {"5", "Very dry", "521", "1024","120000" }}; // 2 min. Air // ----- Sleeptime vs level ------------ //delay(120000); // 2 min. / 5 //delay(300000); // 5 min. / 4 //delay(900000); // 15 min. / 3 //delay(1800000); // 30 min. 7 2 //delay(3600000); // 60 min. / 1 //-------------------------------------- int soilpin = A4; // sensor1 int tankempty = A3; // sensor2 int tankmyoverflow = A2; // sensor3 int RELAY1 = 21; // was 3 int LED1 = 4; int LED2 = 5; void setup() { Serial.begin(9600); Serial.println("Startup"); Serial.println("Message,value,level,sleeptimer,myoverflow,empty"); pinMode(13, OUTPUT); // Buildin LED pinMode(LED1, OUTPUT); // Buildin LEDa pinMode(LED2, OUTPUT); // Buildin LED pinMode(RELAY1, OUTPUT); // Relæ 1 pinMode(tankmyoverflow, INPUT); // myoverflow sensor pinMode(tankempty, INPUT); // Empty sensor digitalWrite(RELAY1, LOW); // Relæ 1 } void showlevel(String level){ for ( int i = 0; i < level.toInt(); ++i ) { digitalWrite(13, HIGH); digitalWrite(LED1, HIGH); delay(500); digitalWrite(13, LOW); digitalWrite(LED1, LOW); delay(500); } } void loop() { //Serial.println("Starting loop"); digitalWrite(13, HIGH); int a; int sleeptime=0; int val=0; int empty=0;int myoverflow=0; String level;String thismin;String thismax;String sleeptimer;// init control signals char message[15]; val = analogRead(soilpin); myoverflow = analogRead(tankmyoverflow); empty = analogRead(tankempty); for ( int i = 0; i < 5; ++i ) { thismin= newstate[i][2]; thismax= newstate[i][3]; if (val >= thismin.toInt() && val <= thismax.toInt()) { a=i; level= (newstate[i][0]); sleeptimer= (newstate[i][4]); } } if (empty < 800 && myoverflow < 800) { if ( level.toInt() >= 4) { Serial.println("Pump ON"); digitalWrite(RELAY1, HIGH); digitalWrite(LED1, HIGH); delay(3000); Serial.println("Pump OFF"); digitalWrite(RELAY1, LOW); digitalWrite(LED1, LOW); } } strncpy(message, newstate[a][1], sizeof (message)); if (empty > 700 || myoverflow > 700) { char message[25] = "Tank Empty or overflow"; digitalWrite(LED2, HIGH); } else { digitalWrite(LED2, LOW); } // Print data to console Serial.print(message); Serial.print(","); Serial.print(val); Serial.print(","); Serial.print(level); Serial.print(","); Serial.print(sleeptimer); Serial.print(","); Serial.print(myoverflow); Serial.print(","); Serial.println(empty); //showlevel(level); // flash LED1 a number of times to indicate current level delay(sleeptimer.toInt()); // sleep x time according to current level }
Comments
Post a Comment