Automatic watering system with Arduino for your plants, orchard or garden

Watering can watering plants

Summer is a time when many tend to go on vacation outside and plants are a problem, since they cannot be water those days when you are not at home. In addition, garden stores usually sell a kind of gel that allows the plant to be hydrated and nourished for about a month. But with the heat that it is or if you leave for more than a month, then you will need a somewhat better system so that when you return they are still alive and vigorous.

For that to be possible, the solution that exists is to buy a automatic irrigation system that you can program or if you are a maker and you like DIY, you can do it yourself with Arduino. The materials you need, apart from the Arduino board, are easy to find and quite cheap, so they do not involve too great an expense. Also, for some elements like the water tank, etc., you could use recycled materials ...

If you browse the web a bit you will find various projects of this type, but perhaps the most interesting is garden. In that I will be inspired for this project, since I consider that other irrigation systems that only use humidity sensors and nothing else are not so complete.

What do you need?

The materials needed for your automatic irrigation system are:

  • No products found., although others would be worth.
  • Protoboard or PCB if you want to solder it and make it permanent.
  • Temperature and humidity sensor No products found.
  • Cables
  • Sensor YL-69 moisture on the ground with a hygrometer to stick in your pot / s or soil.
  • Minipump 3V submersible water and approximate flow of 120 l / h.
  • Diode 1N4007
  • Bipolar transistor PN2222
  • 3 Resistors: 1x 220 ohms, 1x 1k, 1x No products found.
  • Water tank, which can be a drum or a bottle of 5 or more liters, etc.
  • Tubo to connect to the minipump and take to the plant / s

Just like alternative ideas, I would tell you that you could also use a sonoff or a WiFi module to activate it over the Internet from wherever you are, or improve it by also adding an automatic valve to the tap to program the filling of the water tank when it empties, etc.

How to set up the automatic irrigation system

Schematic of the assembly in Fritzing

The assembly is quite simple. You may use the above schematic to make all the connections. You should position your system in a place near the window or where the plant you want to water is located and stick the two tips of the humidity sensor in the soil of the plant, near the stem.

The automatic watering system with Arduino will water whenever it detects a series of environmental conditions. For example, when it detects low light or darkness, the air temperature is a concrete one that we will configure in the Arduino IDE sketch, and the humidity on the ground is low. At that moment he would activate the motor to water the plant.

It is advisable to water the plants at night, when it is less hot, since doing so during intense hot days could harm more than benefit ...

Remember that you should introduce the mini pump under water in the tank that you have destined for irrigation, and that should have a sufficient capacity to hold the days that you are not there. You can do previous tests to know how long it lasts and you should leave a little more water in case it evaporates with the intense heat ...

It goes without saying that the tube must be fixed to the plant so that it does not move with the wind or the water can fall out and be wasted. And I think it would not be necessary to remember that you have to maintain a current supply to the Arduino board for it to work ...

Programme

Now is when you should write the code needed in Arduino IDE to be able to program the microcontroller that manages the hardware you have used. This is the time to adapt the appropriate temperature, humidity and light values ​​to water in your area, as it can vary depending on where you are. But the example you can use as a base is (I have left comments where you could modify the values, the rest you can leave it like this):

Download the code from code-irrigation-autowatering-auto for your garden

#include <SimpleDHT.h>
#include <SPI.h>
#define humidity_sensor_pin A0
#define ldr_pin A5
//Bibliotecas para los módulos sensores usados necesarias
//Y definición de variables para los sensores de humedad y LDR en los pines A0 y A5

int pinDHT11 = 2;
SimpleDHT11 dht11;
int ldr_value = 0;
int water_pump_pin = 3;
int water_pump_speed = 255;
//Aquí puedes dar valores desde 0 a 255 para la velocidad a la que trabajará la minibomba
//Haz pruebas previas del caudal y configura la. Yo he //elegido 255 pero ustedes pueden elegir la que estimen conveniente. A más velocidad, mayor //bombeo de agua
void setup() {
  Serial.begin(9600);
}
void loop() {
// Mide la temperatura y humedad relativa y muestra resultado
  Serial.println(“***”);
  Serial.println(“Muestra DHT11…”);
  
  byte temperature = 0;
  byte humidity_in_air = 0;
  byte data[40] = {0};
  if (dht11.read(pinDHT11, &temperature, &humidity_in_air, data)) {
    Serial.print(“Lectura del sensor DHT11 fallida”);
    return;
  }
  
  Serial.print(“Muestra RAW Bits: “);
  for (int i = 0; i < 40; i++) { Serial.print((int)data[i]); if (i > 0 && ((i + 1) % 4) == 0) {
      Serial.print(‘ ‘);
    }
  }
  Serial.println(“”);
  
  Serial.print(“Muestra OK: “);
  Serial.print(“Temperatura: “);Serial.print((int)temperature); Serial.print(” *C, “);
  Serial.print(“Humedad relativa en aire: “);Serial.print((int)humidity_in_air); Serial.println(” %”);
  
  int ground_humidity_value = map(analogRead(humidity_sensor_pin), 0, 1023, 100, 0);
  Serial.print(“Humedad en suelo: “);
  Serial.print(ground_humidity_value);
  Serial.println(“%”);

  int ldr_value = map(analogRead(ldr_pin), 1023, 0, 100, 0);
  Serial.print(“Luz: “);
  Serial.print(ldr_value);
  Serial.println(“%”);
   Serial.println(“***”);

//**
// Condiciones de riego 
// Si la humedad en el suelo es igual o inferior al 60%, si la luminosidad es inferior al 30%,
// Si la temperatura es inferior al 35%, entonces el sistema de riego riega. 
// En caso de que no se  cumpla alguno o ninguno de los 3 requisitos anteriores,
// el sistema de riego no riega
//**
//Aquí puedes variar los parámetros que necesites de 60, 35 y 30, e incluso usar otros operandos <>=...
 if( ground_humidity_value <= 60 && ldr_value<30 && temperature<35) {
 digitalWrite(water_pump_pin, HIGH);
 Serial.println(“Irrigación”);
 analogWrite(water_pump_pin, water_pump_speed);

 }
 else{
 digitalWrite(water_pump_pin, LOW);
 Serial.println(“Riego detenido”);

 }
 delay (2000); 
// Ejecuta el código cada 2000 milisegundos, es decir, 2 segundos. Puedes variar la frecuencia de muestreo
}

More information - Arduino Programming Course (Free PDF)

Fonts

More information - garden