Hi guys/ladies,
Last summer i started a project in which i would like to water my 150m2 (a stretch of 6 meter x 25 meter vegetable garden automatically.
My general idea is the following: The vegetable garden is split up into 4 stations. These stations control 16-valves individually basically turning 1 valve after the other on thereby watering around 2 m2 at the time.
Last month you creative forum members have helped me solve my issue with the 16-way valves so it looks like this concept of the stations is working now. Since the tips were sooo great i would assume that your can also improve my main controller.
What about the controller. The controller is basically an Arduino Mega which is located against my greenhouse. This greenhouse has a couple of nice features built in... such as a groundwaterwell (14 meters deep, dug myself), 3 30 watt solar panels and 3 batteries (100 kAh each). These batteries are partly used in my automated greenhouse on hydroponics (which is running successfully for a couple of years) but there is some room for more automation left.
The idea of this controller is the following. It will basically sleep and is just checking once every hour how much light there is out there. In the dark it would activate once per day. Basically when activated it would power Station 1 and at the same time start pumping water from the waterreservoir next to the greenhouse. After a specific period it would switch to watering Station 2 and turning on pump 2. Idem for Station 3 and 4.
What makes it more interesting is that the reservoir is around 200 liters and i would say a general Wateringday would look like the distribution of around 2000 liters of water. Therefore i build in 2 water level float switches to detect the water level and once the reservoir is not full it would already start to pump ground water into the reservoir to avoid that it gets empty. If 'empty' it should temporarely stop the system. Fill up the reservoir completely and resume the remaining time. Also worth mentioning that the Arduino must be in sleep mode in the time that it is not active because else even an arduino is able to drain a 100kAh battery completely (in a few days)
As attachment a rough overview of the different components and connections. Furthermore some insights into the controller and the code.
Any suggestions what to improve? (i have my doubts about the code around the light sensor and maybe you have suggestions how to resume or deal with an empty reservoir?)
#define onderstesensor 9
#define bovenstesensor 8
#define relaygrondwater 11
#define lichtsensor 12
#define box1 41
#define box2 42
#define box3 43
#define box4 44
int box1time = 200;
int box2time = 200;
int box3time = 200;
int box4time = 200;
bool emptyreservoir = false;
bool volreservoir = false;
bool malfunction = false;
void setup() {
Serial.begin(9600);
pinMode(onderstesensor, INPUT_PULLUP);
pinMode(bovenstesensor, INPUT_PULLUP);
pinMode(relaygrondwater, OUTPUT);
pinMode(lichtsensor, INPUT_PULLUP);
pinMode(box1, OUTPUT);
pinMode(box2, OUTPUT);
pinMode(box3, OUTPUT);
pinMode(box4, OUTPUT);
digitalWrite(relaygrondwater, HIGH);
digitalWrite(box1, HIGH);
digitalWrite(box2, HIGH);
digitalWrite(box3, HIGH);
digitalWrite(box4, HIGH);
//SETUP WATCHDOG TIMER
WDTCSR = (24);//change enable and WDE - also resets
WDTCSR = (33);//prescalers only - get rid of the WDE and WDCE bit
WDTCSR |= (1<<6);//enable interrupt mode
//Disable ADC - don't forget to flip back after waking up if using ADC in your application ADCSRA |= (1 << 7);
ADCSRA &= ~(1 << 7);
//ENABLE SLEEP - this enables the sleep mode
SMCR |= (1 << 2); //power down mode
SMCR |= 1;//enable sleep
}
void loop() {
// put your main code here, to run repeatedly:
int licht = digitalRead(lichtsensor);
if (licht == 1){
Serial.println("it is dark");
/in this scenario we would like to water the plants..
/*
*
*
*/
//first check whether tank is full and turn on groundwaterpump
//check waterlevel
//scenario 1: tank full
if(digitalRead(bovenstesensor) == LOW)
{
//check both sensors
if (digitalRead(onderstesensor) == HIGH)
{
Serial.println("waterlevels unrealistic");
//waterniveau's onrealistisch
}
// confirmed tank full:
else if (digitalRead(onderstesensor) == LOW)
{
Serial.println("waterlevel high");
volreservoir = true;
//tank full ... up to the next step
}
else
{
Serial.println("error 404.. cannot detect sensors");
//error, sensors niet gedetecteerd
}
}
//scenario 2: tank half full
else if (digitalRead(bovenstesensor) == HIGH)
{
//check bottom sensor
if (digitalRead(onderstesensor) == LOW)
{
//tank half full confirmed
Serial.println("tank half full");
}
else if (digitalRead(onderstesensor) == HIGH)
//tank empty
{
Serial.println("tank empty, action required");
//tank empty
//change status of emptyreservoir
emptyreservoir = true;
}
else
{
Serial.println("error 404.. cannot detect sensors");
//sensors niet gedetecteerd
}
}
else
{
Serial.println("error 404.. cannot detect sensors");
//sensors niet gedetecteerd
}
//wenn waterlevels are too low, fill water to upper waterlevel
if(volreservoir == false){
Serial.println("entered fill loop");
//for 30 minutes run procedure...
int j = 0;
for (int i = 0; i <= 300; i++) {
digitalWrite(relaygrondwater, LOW);
j = j+1;
Serial.println("j teller: " +j);
delay(10000);
//immediately shut off loop when sensor says reservoir is full
if (digitalRead(bovenstesensor) == LOW)
{
Serial.println("break performed");
volreservoir = true;
emptyreservoir = false;
break;
}
//if entire loop is run...pump has been filling for half an hour. turn on malfunction to indicate that sensors or pump are not functioning properly
if (i == 298){
malfunction = true;
Serial.println("safety switch activated");
}
}
//turn water off and set emptyreservoir on false;
digitalWrite(relaygrondwater, HIGH);
emptyreservoir = false;
//when enough water, turn box 1 during .... minutes. Turn box1 on and flow groundwater.
//////////////////////////////////////////////////////
digitalWrite(box1, LOW);
digitalWrite(relaygrondwater, LOW);
for (int i = 0; i <= box1time; i++) {
Serial.println("loop box1");
if(digitalRead(onderstesensor) == HIGH){
//reservoirtak low, shut down box and refill reservoir... de relaypump is still running.
digitalWrite(box1, HIGH);
Serial.println("reservoirtank low, enter fill loop");
for(int j = 0; j <= 200; j++) {
if(digitalRead(bovenstesensor) == LOW){
//tank is back full and we can continue running
Serial.println("tank is again full");
break;
}
delay(10000);
}
//restart box... has been resetted back to the beginning.
digitalWrite(box1, LOW);
}
delay(10000);
}
digitalWrite(box1, HIGH);
digitalWrite(relaygrondwater, HIGH);
//////////////////////////////
//daarna wanneer voldoende vol box2 aangeschakelen gedurende ... minuten
//box1 aanschakelen en grondwater laten stromen.
//next when reservoir is full enough turn box2 on during ... minutes.
//switch on box1 and let ground water flush.
//////////////////////////////////////////////////////