ebb and flood system with a chilli plant growing in hydroton scaled

Hydroponics Automation – Ebb & Flood Basic

The future of sustainable farming is not solely in sprawling fields or massive greenhouses, but it’s also being realized in compact, urban spaces using innovative methods such as hydroponics. Among the many hydroponic systems available, the ebb and flood (or flood and drain) system stands out due to its efficiency and simplicity. This system allows plants to get the perfect balance of nutrients, water, and oxygen by periodically flooding the plant roots and then draining the water back.

Video Explanation of the Automated Ebb & Flood System

Our recent video showcase dives deep into the intricacies of the “Hydroponics Automation – Ebb & Flood” system, offering viewers a hands-on guide on how to build an automated version of this traditional method. Why automate, you ask? Automation ensures that plants receive the right amount of water at precise intervals, maximizing growth while minimizing resource wastage. Moreover, the convenience of automation means you can maintain a thriving hydroponic garden with minimal daily intervention. For those eager to implement this system, the accompanying article provides the complete code used in the video. Dive in and explore the seamless amalgamation of nature’s wisdom and modern technology.

Schematic for this basic Automated Ebb & Flood System

Schematic - Ebb and Flood Automation- Basic

Code for the Automated Ebb & Flood Hydroponic System

/*
Author: Shaun AKA Chillichump
chillichump.com
www.youtube.com/chillichump
*/
const String swName = "ChillichumpIO Ebb&Flood Basic";
const String swVer = "1.1";
const String swRel = "09/03/19";

/* Common Millis equivalents
   4 hours = 14400000; 2 hours = 7200000; 1 hour = 3600000
   10 minutes = 600000; 5 minutes = 300000; 2 minutes = 120000; 1 minute = 60000
*/

const long floodIntMillis = 60000; //millis between flooding
const long floodDurMillis = 5000; //millis for flood duration
const long longestDelayBetweenFlooding = 43200000; //longest acceptable delay between flooding. This ensures flooding occurs even if lights fail etc. 43,200,000 is 12 hours
const int lightLevel = 600; //this value indicates whether the sun is up. Value out of 1023. higher = lighter (indirect sun is around 850; normal indoor lighting is around 650)
const long lightLevelDelay = 20000; //delay before deciding it is daylight. To avoid lights, torches etc. causing issues
const byte pumpPin = 6; //pin number for activating relay for pump
const byte pinLightSensor = A2; //pin number for light sensor

unsigned int lightSensorNow = analogRead(A2);
unsigned long sunUpMillis = 0;
unsigned long sunDownMillis = 0;
unsigned long pumpLastOn = floodIntMillis + lightLevelDelay; //ensuring pump comes on when device is turned on and it is light
unsigned long pumpOffAt = 0;
boolean sunUpCheck = false;
boolean sunDownCheck = false;
boolean sunUp;
boolean lastState = false;


void setup() {
  pinMode(pumpPin, OUTPUT);
  digitalWrite(pumpPin, LOW); //pump off
}


void loop() {
  lightSensorNow = analogRead(pinLightSensor);
  if (lightSensorNow >= lightLevel && sunUp == false) {
    sunUp = true;
  }
  if (lightSensorNow < lightLevel && sunUp == true) {
    sunUp = false;
  }

  if (sunUp == true && sunUpCheck == false) { //checking if sun is up or lights on
    sunUpMillis = millis();
    sunUpCheck = true;
  }
  if (sunUp == false && sunDownCheck == false) { //checking if sun is down or lights are off
    sunDownMillis = millis();
    sunDownCheck = true;
  }
  if (sunUp == true && millis() - sunUpMillis > lightLevelDelay && sunDownCheck == true) { //checking if sun has been up or lights have been on longer than lightLevelDelay
    sunDownCheck = false;
  }
  if (sunUp == false && millis() - sunDownMillis > lightLevelDelay && sunUpCheck == true) { //checking if sun has been down or lights have been off longer than lightLevelDelay
    sunUpCheck = false;
  }

  if (millis() - sunUpMillis > lightLevelDelay && sunUpCheck == true ) { //checking that there has been light longer than the lightLevelDelay
    if (millis() - pumpLastOn > floodIntMillis || millis() < pumpLastOn) { //checking when the pump was last on. also checking if the sun has just come up or lights are on to ensure a flooding at first light.
      pumpLastOn = millis();
      pumpOffAt = millis() + floodDurMillis; //pumpOffAt has been added so that the pump doesn't switch off during a cycle if the lights go our or sun goes down
    }
  }

  if (millis() - pumpLastOn > longestDelayBetweenFlooding && millis() > longestDelayBetweenFlooding) { //ensuring there is water at least every x hours
    pumpLastOn = millis();
    pumpOffAt = millis() + floodDurMillis;
  }

  if (millis() < pumpOffAt) { //turning the pump on
    digitalWrite(pumpPin, HIGH); //pump on
  } else {
    digitalWrite(pumpPin, LOW); //pump off
  }


}

Download the Arduino Code

2 thoughts on “Hydroponics Automation – Ebb & Flood Basic”

  1. Hey Champ/Chump.
    First off, you are amazing and the whole reason I now have built a greenhouse.
    I love fiddling around with small electronics, but can’t figure out the coding…
    In the video you mention and show the more advanced edition of the ebb and flow system. Can you perhaps please provide a link for that and maybe let me know the hardware and the code used for that.
    Kind Regards from a fan from Denmark

    1. Hello Mads, if you sign up on Patreon (patreon.com/Chillichump), you will get access to my private Discord where I have a channel just for discussing tech related things. It might be a good place for you to join up and I could give you a hand. With regards to the code for my advanced hydro system, I will be releasing that at some point I need to just figure out how and when I will be doing that!

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Basket