In this project, we are going to build an automatic irrigation system using Arduino which senses the moisture of the soil and opens or closes the valve according to the moisture value. The moisture value and the valve status is shown on the Nokia 5110 LCD display.
Before we proceed, let’s take a look at another project – a plant watering system using Arduino, which is very similar to our application. You may also read our other tutorials on – interfacing Nokia LCD to Arduino and our tutorial on interfacing Soil Moisture Sensor to Arduino.
Required Components
The components required for this project are as follows
- Arduino
- Nokia 5110 LCD
- FC-28 Soil Moisture Sensor
- Single Relay Module
- 1K potentiometer
- 4 X 10K resistors
- 1K resistor
- 330 ohm resistor
Circuit Diagram – Automatic Irrigation System
Nokia 5110 LCD operates on 3.3V, and if we connect it directly to the data pins of Arduino the life time of Nokia 5110 LCD will decrease (notice that the LCD will still work even if you connect directly without current limiting resistors). So, if you want to use it for a longer span, it’s good to connect via resistors as we have shown in this project.
To connect the Nokia 5110 LCD with the Arduino, make the connections for the Nokia 5110 LCD with the Arduino as follows
- Connect the pin 1 of Nokia 5110 LCD which is the reset Pin to the pin 6 of Arduino through the 10K resistor.
- Connect the pin 2 of Nokia 5110 LCD which is the chip select pin to the pin 7 of Arduino through the 1K resistor.
- Connect the pin 3 of Nokia 5110 LCD which is the data or command pin to the pin 5 of Arduino through the 10K resistor.
- Connect the pin 4 of Nokia 5110 LCD which is the data input pin to the pin 4 of Arduino through the 10K resistor.
- Connect the pin 5 of Nokia 5110 LCD which is the clock pin to the pin 3 of Arduino through the 10K resistor.
- Connect the pin 6 of Nokia 5110 LCD which is the VCC pin to the 3.3V pin of Arduino.
- Connect the pin 7 of Nokia 5110 LCD which is the LED pin to the middle pin of 1k potentiometer through 330 ohm resistor and connect the other two pins to the VCC and the ground.
- Connect the pin 8 of Nokia 5110 LCD which is the ground pin to the GND of Arduino.
The potentiometer used here is for increasing or decreasing the backlight contrast of LCD. If you want full back light, then you can connect it directly to 5V or if you want no backlight, then connect it to ground.
After that, connect the relay module with the Arduino as follows
- Connect the VCC pin of relay to the 5V of Arduino.
- Connect the ground pin of the relay to the GND of Arduino.
- Connect the IN pin to the pin 8 of Arduino.
On the other side of the relay, connect the positive of the battery to the NC terminal (No Connection) of the relay and the C terminal of the relay to the positive of the solenoid valve. Finally, connect the negative of the battery to the negative of the solenoid valve.
In last, connect the FC-28 soil moisture sensor to the Arduino as follows
- Connect the VCC pin of FC-28 to the 5V pin of Arduino.
- Connect the GND pin of FC-28 to the GND pin of Arduino.
- Connect the A0 pin of FC-28 to the A0 of Arduino.
Working – Automatic Irrigation System
The soil moisture sensor senses the moisture present in the soil and gives the output to Arduino. The output of the sensor will be from 0-1023. The moisture is measured in percentage; therefore we should map these values to 0-100.
Whenever the moisture value is lower than the value we have set inside our code as the threshold value, the relay will turn ON and the valve will turn open and whenever the moisture value is lower than this threshold value, the relay will relay will turn OFF and the valve will get closed.
Program/Code
#include <PCD8544.h> PCD8544 lcd; int sensor_pin = A0 ; int output_value ; int valve_pin = 8 ; void setup ( ) { lcd.begin (84, 48); lcd.print ("Reading From the Sensor ... " ); pinMode (valve_pin, OUTPUT); delay (2000); } void loop ( ) { output_value = analogRead (sensor_pin); output_value = map (output_value , 1023 , 0 , 0 , 100); lcd.clear ( ); lcd.setCursor (0, 0); lcd.print (" Moisture = "); lcd.print (output_value); lcd.setCursor (0, 1); if (output_value < 40) { lcd.print (" Valve: ON "); digitalWrite (valve_pin , LOW); //Relay operates on opposite signal delay (1000); } else { lcd.print (" Valve: OFF "); digitalWrite (valve_pin , HIGH); //Relay operates on opposite signal delay (1000); } delay(1000); }
Code Explanation
First, we included the library for Nokia 5110 LCD and declared a constructor variable named ‘lcd’ for using the Nokia 5110 LCD library functions. Then we initialized different variables to read from the sensors and to turn ON or OFF the valve.
#include <PCD8544.h> PCD8544 lcd; int sensor_pin = A0 ; int output_value ; int valve_pin = 8 ;
In the loop function, we first get the readings from the soil moisture sensor FC-28 and stored these readings in the ‘output_value’ variable. The output values of the sensor will be from 0 to 1023 but we need the moisture value which is in percentage. So, we will map the output values of the sensor from 1023-0 to 0-100.
output_value = analogRead (sensor_pin); output_value = map (output_value , 1023 , 0 , 0 , 100);
Then we will print these values on the Nokia 5110 LCD and we will turn on or off the valve according to it. If the moisture value will be lower than 40, then we will make the valve pin low which will turn on the valve. If the moisture value will be higher than 40, then we will make the valve pin high which will turn off the valve.
lcd.print (" Moisture = "); lcd.print (output_value); lcd.setCursor (0, 1); if (output_value < 40) { lcd.print (" Valve: ON "); digitalWrite (valve_pin , LOW); //Relay operates on opposite signal delay (1000); } else { lcd.print (" Valve: OFF "); digitalWrite (valve_pin , HIGH); //Relay operates on opposite signal
So, we finished building an automatic irrigation system using Arduino. You may try this DIY irrigation system in your fields nearby and see how it goes!
Output Photographs
Demo Video
5 Comments
Where do you get or purchase the solenoid valve?
How much does it cost?
Can the solenoid connect to a standard size garden hose connector?