IOT — Getting Started #05 (Automatic Irrigation System)

Aditya Narain Gupta
4 min readJan 7, 2018

--

In the previous blog we have covered the two components of Arduino Environment: Arduino Uno & Arduino IDLE. In this blog we will be covering one of the project of Arduino for better project based learning.

This blog is based on Automatic Irrigation System as Agriculture is one the areas which should be focused on.

Lets first start with discussing the problem statement, Why and what’s the need of this system?
Today there is problem of watering the plants, farmers have to spend lots of time in it and often inadequate watering occurs. This may lead to failure of crop and wastage of water and we all know crop and water are very precious. So why not have a system that maintains adequate water level and water these plants 24*7 without any human intervention. Thus saving lots of efforts and time of our farmers.

So now lets start building the system for our farmers.

Hardware needed:

  1. Arduino Uno
  2. YL-69 Soil Moisture Sensor
  3. Small Water pump (Here I’m using 9V pump)
  4. Transistor — 2N2222A
  5. Resistor — 1K ohm
  • I’m using transistor and resistor as a switch here which are very cheap. Instead of this setup you can simply use a 5V Relay module which will act as a switch when connected to D7.

Schematic Diagram of the setup is shown below:

Schematic Diagram

Soil Moisture sensor is used for sensing the amount of moisture in soil. It gives an analog output between 0 to 1023, so here we are reading it in A0.
The optimum water content required for each type of crop for better growth is known beforehand which can be found on internet. In this case I’m using this value as 800 which can be modified depending on the crop type. Whenever the moisture content is less than the stated, water pump switches on, a LED is also used to indicate that system is watering the plant.

Code Snippet:

Initializing the pins to variables.

int soil_moist = A0; // Reading moisture values at pin A0
int LED = 4; // LED to make it visible that motor is on
int motor = 7; // Motor is connected at pin 7
int thresholdValue = 800; // it stores the moisture content required by plant.

Now writing the setup function, remember this function is executed only once. Setting up the A0 pin as input as it receives input and pins 4 and 7 of LED and motor as output as arduino is giving output at these pins. Initially making led and motor off mode. Setting the baud rate at 9600. Often people stuck at baud rate. Don’t think it as a big thing, it is the number of bits transferred per second between the devices. For eg in our case it’s the transfer rate between the Arduino and host.

void setup() {
pinMode(soil_moist, INPUT);
pinMode(LED, OUTPUT);
pinMode(motor, OUTPUT);
digitalWrite(LED, LOW);
digitalWrite(motor, LOW);
Serial.begin(9600);
}

This was all about setup, now lets write our main application code and as you all know, if read the previous blogs, this application code has to run in infinite loop. Here we regularly receive the moisture content of soil from sensor and check if it is less than threshold value then we start our motor and led for indication till the moisture content is again more then threshold value+100. In order to serve the purpose of the system.

void loop() {
int sensorValue = analogRead(soil_moist);
Serial.print(sensorValue);
if (sensorValue < thresholdValue) {
Serial.println(“ — Doesn’t need watering”);
digitalWrite(motor, LOW);
digitalWrite(LED, LOW);
}
else {
while (sensorValue > (thresholdValue + 100)) {
Serial.println(“ — Watering your plant”);
digitalWrite(motor, HIGH);
digitalWrite(LED, HIGH);
sensorValue = analogRead(soil_moist);
Serial.print(sensorValue);
delay(500);
}
}
delay(1000);
}

Apart from agriculture sector it can be used in homes which will prevent your plants from dying whenever you go on vacation.

As an extension, we can use solar cells for power supply which will make it reliable without being dependent on any external source and we can even add GSM module to this for remote monitoring.

This was all about this system for now. By now you should have got idea that this is an embedded system which we have been learning. Later in this series we will be transforming this system into an IOT one.

If you want me to pick any project to be discussed or have any doubts/queries do mention them in comments. Also there have been five blogs in series do give your feedback/suggestion in order to make it more fruitful.

If you have want to follow the series, make sure to follow this account for regular updates.

Link to the previous blog on Arduino IDE.
Link to the next blog on Smart Street Lights.

--

--