Arduino Projects
Bluetooth
Workshop dust warning
Watering system
Illuminated bowl
Code for other projects
Watering System
Given that in retirement we are taking longer and more frequent holidays it was essential that I find an effective automatic watering system for my greenhouse.
I have still a fair way to go to be tidy in my wiring but the system works a treat
To the left are the circuits to connect up the moisture sensors but in the end I found that they deteriorated so rapidly that I used two six inch nails hammered into a block of wood. These worked for much longer but they natural electrolysis caused the anode to heavily oxidise which changed the resistance between it and the cathode and affected the point at which the water was pumped. A simpler solution was just pumping a fixed amount of water on a timed basis rather than try and react to the actual moisture content. This only worked however when the plant was relatively fully grown and the water per day needed was relatively constant.

Bit messy wiring eh?


Initially I bought moisture probes below but they only lasted a few months and instead I used two 6" nails in a block of wood - above
CODE
/*
Allen Kaye Feb 2020
Moisture controller using Analog Input. One moisture sensor connected to A0. One relay and water pump triggered ON when PIN 7 is HIGH
*/
#include <SPI.h>
#include <SD.h>
//const int chipSelect = 4;
int sensorPin1 = A0; // select the input pin for the potentiometer
int sensorValue1 = 0; // variable to store the value coming from the sensor
int sensorPin2 = A1;
int sensorValue2 = 0;
int relay1=4;
int relay5=5;
int relay6=6;
int relay7=7;
int led5=5;
int led6=6;
int led8=8;
int loops = 0;
int i = 0;
int j = 0;
File dataFile;
void setup()
{
Serial.begin(9600);
/* while(!Serial)
{
; // wait for serial port to connect
Serial.println("waiting for serial port to connect");
}
if (!SD.begin(chipSelect))
{
Serial.println("Card failed or not in holder");
return;
}
*/
pinMode(relay7, OUTPUT);
Serial.println("Starting");
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led8, OUTPUT);
digitalWrite(led5,HIGH);
digitalWrite(led6,HIGH);
digitalWrite(led8,HIGH);
delay(2000);
digitalWrite(led5,LOW);
digitalWrite(led6,LOW);
digitalWrite(led8,LOW);
}
void loop() {
digitalWrite(led6,HIGH);
delay(1000);
digitalWrite(led6,LOW);
// read the value from the sensor at A0:
sensorValue1 = analogRead(sensorPin1);
sensorValue2 = analogRead(sensorPin2);
Serial.println(sensorValue1);
/* String dataString = "";
dataString += String(sensorValue);
dataString += ",";
dataFile = SD.open("ghouse1.txt", FILE_WRITE);
Serial.println("testgreenhouse should be open");
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
Serial.println("written an item of data");
*/
for (i=0;i<4;i++) {
digitalWrite(led5, HIGH);
delay(500);
digitalWrite(led5, LOW);
delay(500);
Serial.println("Led 5 flash");
}
/*
// }
*/
digitalWrite(relay7,LOW);
if (sensorValue1>800) {
Serial.println("Too DRY");
for (i=0;i<6;i++){
digitalWrite(led8, HIGH);
delay(500);
digitalWrite(led8, LOW);
delay(500);
}
digitalWrite(relay7,HIGH);
delay(10000);
digitalWrite(relay7,LOW);
}
else {
Serial.println("wet enough for now");
digitalWrite(relay7,LOW);
}
digitalWrite(relay7,LOW);
/* if (sensorValue2>800) {
Serial.println("Too DRY");
for (i=0;i<6;i++){
digitalWrite(led8, HIGH);
delay(500);
digitalWrite(led8, LOW);
delay(500);
}
digitalWrite(relay6,HIGH);
delay(10000);
digitalWrite(relay6,LOW);
// dataFile.println("On");
// dataFile.close();
}
else {
Serial.println("Second sensor wet enough for now");
digitalWrite(relay6,LOW);
}
delay(2000);
digitalWrite(led6,HIGH);
delay(2000);
digitalWrite(led6,LOW);
Serial.println("cycle ends");
*/
Serial.println("loop delay now");
delay(20000);
Serial.println("loop delay end");
}
