Smart Irrigation System

Author: Ghidiu Teodor Sorin

Master: SSA


I. Short Description

The purpose of this project is to create a smart irrigations system developed for home use, but scalable to industrial applications also. The whole idea started when I planted some hot peppers, but after some weeks I forgot to water them, so they died. The best way to deal with this problem was to develop to develop an automation for this process. The proposed system is continuously monitoring soil moisture, air humidity and temperature, and based on those inputs system decides whether to water the plants or to wait. These three measures are displayed on a small screen and also they are transmitted to a Blynk Cloud and from there they are displayed on the web dashboard and also in the mobile app. The water level from the tank is visible as well Blynk app, and also an on-tap watering function is available, to water the plants whenever needed.

II. Hardware Description

For this project I used multiple components, in order to monitor, control, display and trigger actions.

ESP-WROOM-32S: low-cost microcontroller very suitable for applications like this because it incorporates WI-FI, Bluetooth, GIPIO Pins with digital and analog I/Os, I2C and many more. Another thing that was very helpful, was the integration with Arduino IDE.

OLED Display SSD1306: a small 0.96 inch display with 128×64 pixels resolution that was used to display temperature, humidity and soil moisture. This device is using I2C communication protocol, so in order to communicate with it, was required to use the suitable pins for this: GPIO21 – SDA and GPIO22 SCL.

DHT11: this sensor is used to measure the temperature and humidity. It has a high precision and large measurement range: 0 to 50 Celsius degrees, for temperature, and 20 to 90% humidity.

Moisture sensor: this sensor has to parts, one that comes in contact with water, and the other one, that process and send data. One interesting thig about this sensor is the fact that it can have an analog output and also a digital one. It has adjustable sensitivity and an indicator LED to show when the maximum value is obtained.

Water level sensor: another sensor which stays in water. This sensor has an analog output and a LED to indicate it is functioning. SRD-50VDC-SL-C relay module: this relay was used to control the water pump. Low current signal triggers the relay in order to open or close the circuit. This type of relays support up to 250V and 10A.

Water pump: this pump is very useful because it can function under water without problems and it has an imput voltage between 3 and 6V.

Other components used: battery holder, to power the pump, jump wires and breadboard to make all the connections.

III. Software Description

This application was developed in C using Arduino IDE, and it used multiple libraries in order to communicate with all components and send data to server:

WiFi.h and WiFiClient.h were needed for WI-FI communication

BlynkSimpleEsp32.h - is the library used in order to send and retrieve data from Blynk IoT external service. Template ID, device name and auth token were needed to connect to the service. This credentials were hard-coded at the begging of the file.

DHT.h - is the library needed to read values from temperature and humidity sensors. In order to use the appropriate methods DHT11 type and the dedicated pin were specified.

Wire.h - is used in order to facilitate communication using I2C protocol, used by the OPED screen.

Adafruit_GFX.h and Adafruit_SSD1306.h are the libraries used to display and customize text on SSD1306 OLED screen.

Firstly, were initialized al the needed variables for pins, WI-FI and external services credentials and screen settings. After that, sendTempHumid() method was defined in order to read date from the DHT11 sensor, validate data and send it to Blynk for further processing and displaying.

1.	void sendTempHumid(){
2.	  float humidity = dht.readHumidity();
3.	  float temperature = dht.readTemperature();
5.	  if (isnan(humidity) || isnan(temperature)) {
6.	    Serial.println("Failed to read from DHT sensor!");
7.	    return;
8.	  }else{
9.	    Serial.println("Temperature and humidity:");
10.	    Serial.println(temperature);
11.	    Serial.println(humidity);
12.	  }
13.	  Blynk.virtualWrite(V5, humidity);
14.	  Blynk.virtualWrite(V6, temperature);
15.	}

Now, data retrieved from soil moisture and water level sensors is read, processed, validated and sent to cloud. In this method, based on the soil moisture value relay is actioned to start the water pump.

1.	void sendMoistureTriggerRelay(){
2.	  waterLevel = analogRead(waterLevelSensor);
3.	  waterLevel = map(waterLevel,0,2000,0,100);
4.	  moistureLevel = analogRead(moistureLevelSensor);
5.	  moistureLevel = map(moistureLevel,4080,1380,0,100);
7.	  int limit = 30;
8.	  if( moistureLevel < limit ){
9.	      digitalWrite(relay, LOW);
10.	      Serial.println("Current IS Flowing");
11.	    }else{
12.	      digitalWrite(relay, HIGH);
13.	      Serial.println("Current NOT Flowing");
14.	    }
16.	  Blynk.virtualWrite(V2, waterLevel);
17.	  Blynk.virtualWrite(V3, moistureLevel);
19.	  Serial.println("Water level:  ");
20.	  Serial.println(waterLevel);
21.	  Serial.println("Soil moisture:  ");
22.	  Serial.println(moistureLevel);
23.	}

In order to trigger the system to water the plants in any moment input received from Blynk platform.

2.	  int pinValue = param.asInt();
4.	  Serial.print("V1 received is: ");
5.	  Serial.println(pinValue);
7.	  if (pinValue != 0){
8.	      digitalWrite(relay, LOW);
9.	      Serial.println("Current IS Flowing");
10.	      sleep(10);
11.	  }else{
12.	      digitalWrite(relay, HIGH);
13.	      Serial.println("Current NOT Flowing");
14.	    }
15.	}

In setup() method Serial port is being initialized, relay is opened, display is initialized, authentication to Blynk is made and dht is started. Lastly, the timer for the two measurements functions is set.

1.	void setup(){
2.	  Serial.begin(115200);
3.	  pinMode(relay, OUTPUT);
4.	  digitalWrite(relay, HIGH);
5.	  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
6.	    Serial.println(F("SSD1306 allocation failed"));
7.	    for(;;); 
8.	  }
9.	  Blynk.begin(auth, ssid, pass);
10.	    dht.begin();
11.	  timer.setInterval(3000L, sendTempHumid);
12.	  timer.setInterval(6000L, sendMoistureTriggerRelay);
13.	}

In loop() method Blynk and timer are started, and data is displayed on screen.

1.	void loop(){
5.	  float humidity = dht.readHumidity();
6.	  float temperature = dht.readTemperature();
7.	  moistureLevel = analogRead(moistureLevelSensor);
8.	  moistureLevel = map(moistureLevel,4080,1380,0,100);
9.	  if(moistureLevel > 100){
10.	    moistureLevel = 100;
11.	  }
13.	  display.clearDisplay();
15.	  display.setTextSize(2);
16.	  display.setTextColor(WHITE);
17.	  display.setCursor(0,0);
18.	  display.print("T: ");
19.	  display.print(temperature);
20.	  display.print(" ");
21.	  display.setTextSize(1);
22.	  display.cp437(true);
23.	  display.write(248);
24.	  display.setTextSize(2);
25.	  display.print("C");
27.	  display.setTextSize(2);
28.	  display.setCursor(0, 25);
29.	  display.print("H: ");
30.	  display.print(humidity);
31.	  display.print(" %"); 
33.	  display.setTextSize(2);
34.	  display.setCursor(0, 50);
35.	  display.print("M: ");
36.	  display.print(moistureLevel);
37.	  display.setTextSize(2);
38.	  display.print(" %");
40.	  display.display();
41.	}

Here are some samples from Blynk web and mobile dashboards and code flow:

IV. Issues and solutions

One funny issue, run out of jump wires and I was forced to glue them using glue gun. At begging had some problems with Blynk IoT new developed app and understanding how to use it. Some of the sensors don’t have any pin notations on them, and I had to try multiple times how to connect.

V. Conclusion

I relay enjoyed developing this project and I relay want to implement it to all my hot peppers that I planted. Also, I want to make a room thermometer using the sensors and screen and implement some other smart features and home automations using ESP-32 or Arduino. In conclusion, this was a very useful and fun project. I had the chance to put up some practical knowledge and build a solution for a problem. Blynk IoT is a powerful platform and combined with ESP board give us endless projects to implement.

VI. Bibliography

iothings/proiecte/2021/smart-irrigation-system.txt · Last modified: 2022/01/28 18:36 by teodor_sorin.ghidiu
CC Attribution-Share Alike 3.0 Unported Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0