This is my automatic watering system for the greenhouse. You simply submerge the pump and attach it to your preferred irrigation method. The hardest bit is getting the pressure correct around the green house. I've found it best to use house guttering with holes drilled in it placed above the plants. Then you simply pump water into the gutter and let it run around and drop through the holes to the plants below. If the waterlevel gets too low, the system will shut off so as not to damage the pump.
Arduino Code:
int RELAY1 = A0; //water pump
int RELAY2 = A1; //low level lamp
int pin_switch1 = 3; //water level
int pin_switch2 = 4; //manual override
int pin_switch3 = 5; //clock timer relay
boolean switchState1 = LOW; //LOW = Switch closed (because switch is shorted to GND) HIGH would be switch open
boolean switchState2 = LOW;
boolean switchState3 = LOW;
void setup() {
// put your setup code here, to run once:
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
digitalWrite(RELAY1, HIGH); //high = off, LOW = on
digitalWrite(RELAY2, HIGH);
Serial.begin(9600);
pinMode(pin_switch1, INPUT_PULLUP); //input pullup negates the need for a resistor in circuit as you use arduino built in resistor
pinMode(pin_switch2, INPUT_PULLUP);
pinMode(pin_switch3, INPUT_PULLUP);
}
void loop()
{
//read the state of the switch (high or low)
//LOW = Switch closed (because switch is shorting Arduino pin to GND)
//HIGH = Switch open
switchState1 = digitalRead(pin_switch1);
switchState2 = digitalRead(pin_switch2);
switchState3 = digitalRead(pin_switch3);
if ( switchState1 == LOW && switchState3 == LOW) //i.e if water level is ok and timer relay is engaged then:
{
digitalWrite(RELAY2, HIGH); //turn level warning lamp off
digitalWrite(RELAY1, LOW); //turn pump on
}
else {
digitalWrite(RELAY1, HIGH); //turn pump off
digitalWrite(RELAY2, HIGH); //turn level warning lamp off
}
if (switchState1 == HIGH) //water level too low
{
digitalWrite(RELAY1, HIGH); //turn pump off
digitalWrite(RELAY2, LOW); //Turn level warning lamp on
}
if ( switchState2 == LOW) //manual override button pressed
{
digitalWrite(RELAY1, LOW); //turn pump on
}
}