Smart Irrigation System using Arduino and IoT
Project Overview
This Smart Irrigation System uses soil moisture sensors, a water pump, and IoT connectivity to automate watering based on real-time soil conditions. The system prevents overwatering and optimizes water usage.
1. Components Required
Component | Quantity | Description |
---|---|---|
Arduino Uno/Nano | 1 | Microcontroller Board |
Soil Moisture Sensor | 1+ | Detects soil moisture level |
Relay Module (5V) | 1 | Controls the water pump |
Water Pump | 1 | Pumps water to the plants |
DHT22 Sensor | 1 | Measures temperature and humidity |
ESP8266/ESP32 | 1 | IoT connectivity for remote monitoring |
OLED Display (I2C) | 1 | Displays sensor readings |
Jumper Wires | As needed | For connections |
Breadboard | 1 | For prototyping |
2. Pin Connections
Component | Pin Name | Arduino Pin |
---|---|---|
Soil Moisture Sensor | VCC | 5V |
GND | GND | |
Analog Out | A0 | |
Relay Module | VCC | 5V |
GND | GND | |
Signal | D3 | |
DHT22 | VCC | 5V |
GND | GND | |
Data | D2 | |
ESP8266/ESP32 | VCC | 3.3V |
GND | GND | |
TX | RX | |
RX | TX | |
OLED Display | VCC | 3.3V |
GND | GND | |
SDA | A4 (I2C SDA) | |
SCL | A5 (I2C SCL) |
3. Code Implementation
This Arduino code reads soil moisture, temperature, and humidity, controls the water pump, and sends data to a cloud server via ESP8266.
Required Libraries
DHT.h
Wire.h
Adafruit_GFX.h
Adafruit_SSD1306.h
ESP8266WiFi.h
ThingSpeak.h
Install these libraries via the Arduino Library Manager.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <ThingSpeak.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define SOIL_PIN A0
#define RELAY_PIN D3
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
WiFiClient client;
unsigned long myChannelNumber = YOUR_THINGSPEAK_CHANNEL;
const char * myWriteAPIKey = "YOUR_API_KEY";
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting...");
}
Serial.println("WiFi Connected!");
ThingSpeak.begin(client);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
dht.begin();
pinMode(RELAY_PIN, OUTPUT);
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
int soilMoisture = analogRead(SOIL_PIN);
Serial.print("Temp: "); Serial.print(temperature);
Serial.print("C | Humidity: "); Serial.print(humidity);
Serial.print("% | Soil: "); Serial.println(soilMoisture);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print("Temp: "); display.print(temperature); display.print(" C");
display.setCursor(0, 10);
display.print("Humidity: "); display.print(humidity); display.print(" %");
display.setCursor(0, 20);
display.print("Soil Moisture: "); display.print(soilMoisture);
display.display();
if (soilMoisture < 400) {
digitalWrite(RELAY_PIN, HIGH);
Serial.println("Water Pump ON");
} else {
digitalWrite(RELAY_PIN, LOW);
Serial.println("Water Pump OFF");
}
ThingSpeak.setField(1, temperature);
ThingSpeak.setField(2, humidity);
ThingSpeak.setField(3, soilMoisture);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
delay(5000);
}
4. Working Explanation
- The Soil Moisture Sensor detects soil moisture level.
- The DHT22 Sensor records temperature & humidity.
- The ESP8266/ESP32 sends the data to the cloud (ThingSpeak).
- The OLED Display shows real-time data.
- The Relay Module turns the Water Pump ON when soil moisture is too low.
- The system updates every 5 seconds.
Projects for Beginners and Enthusiasts
Click here: https://iotbyhvm.ooo/10-exciting-arduino-projects-for-beginners-and-enthusiasts/