Welcome to Yarana IoT Guru! π±π
Are you looking for an efficient way to automate your irrigation system and remotely control your water pump? With IoT-based smart irrigation, you can:
β
Monitor soil moisture in real-time
β
Control your water pump remotely using an Android app
β
Store and retrieve live data using Firebase
This project is ideal for smart farming, home gardens, and IoT enthusiasts who want to save water while keeping their plants healthy. πΎπ»
π π₯ Download Complete Source Code:
π GitHub Repository
π― What You Will Learn in This Project
βοΈ Connecting a soil moisture sensor to your Android app
βοΈ Using Firebase for real-time data storage and retrieval
βοΈ Controlling a water pump using a relay module
βοΈ Building an Android app interface for easy control & monitoring
π Components & Technologies Used
β
Soil Moisture Sensor β Measures soil moisture levels
β
Relay Module β Controls the water pump
β
ESP32 / ESP8266 β Connects the sensor to Firebase
β
Firebase Realtime Database β Stores sensor readings
β
Android App (Kotlin/Java) β Displays real-time data & controls the pump
β
WiFi Network β Required for remote access
π Why Build a Smart Irrigation System?
Traditional irrigation methods waste water and require manual effort. An automated smart irrigation system ensures:
πΉ Optimal water usage β No over-watering or under-watering
πΉ Remote control β Turn the pump on/off from anywhere
πΉ Data-driven decisions β Adjust watering based on real-time soil moisture levels
πΉ Increased crop yield β Smart irrigation leads to better plant health
π Step-by-Step Guide to Building a Smart Irrigation System
Step 1: Setting Up the Soil Moisture Sensor
- Connect the soil moisture sensor to the ESP32 or ESP8266.
- Use analog input pins to read the sensor values.
- The sensor provides a voltage output depending on the soil moisture level:
- Dry soil β High resistance β Low voltage output
- Wet soil β Low resistance β High voltage output
π₯ Example Code to Read Moisture Sensor Data
cppCopyEdit#define SENSOR_PIN A0 // Connect the sensor to the Analog pin
void setup() {
Serial.begin(115200);
pinMode(SENSOR_PIN, INPUT);
}
void loop() {
int moistureValue = analogRead(SENSOR_PIN);
Serial.print("Soil Moisture Level: ");
Serial.println(moistureValue);
delay(1000); // Read every second
}
Step 2: Sending Data to Firebase
Now, we send the soil moisture data to Firebase so that the Android app can retrieve it.
π₯ ESP32 Code to Send Data to Firebase
cppCopyEdit#include <WiFi.h>
#include <FirebaseESP32.h>
#define FIREBASE_HOST "your-firebase-url.firebaseio.com"
#define FIREBASE_AUTH "your-firebase-secret"
#define SENSOR_PIN A0
FirebaseData firebaseData;
WiFiClient client;
void setup() {
Serial.begin(115200);
WiFi.begin("your-SSID", "your-PASSWORD");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
int moistureValue = analogRead(SENSOR_PIN);
Firebase.setInt(firebaseData, "/soilMoisture", moistureValue);
Serial.println("Soil Moisture Data Sent to Firebase: " + String(moistureValue));
delay(5000); // Send data every 5 seconds
}
Step 3: Controlling the Water Pump Using a Relay
Once we receive moisture data on Firebase, we can use it to turn the water pump ON/OFF automatically.
π₯ Code to Control the Relay
cppCopyEdit#define RELAY_PIN 5
void setup() {
pinMode(RELAY_PIN, OUTPUT);
}
void loop() {
int moistureValue = analogRead(SENSOR_PIN);
if (moistureValue < 300) { // If soil is dry
digitalWrite(RELAY_PIN, HIGH); // Turn ON pump
} else {
digitalWrite(RELAY_PIN, LOW); // Turn OFF pump
}
}
Step 4: Building an Android App to Display Data & Control Pump
Now, we need an Android app to:
β
Display real-time moisture levels
β
Turn the pump ON/OFF manually
π₯ Steps to Build the Android App
1οΈβ£ Use Firebase Realtime Database to read sensor data.
2οΈβ£ Create a user-friendly UI using Kotlin or Java.
3οΈβ£ Add a manual ON/OFF button to control the pump remotely.
π₯ Android Code to Read Firebase Data
javaCopyEditDatabaseReference databaseRef = FirebaseDatabase.getInstance().getReference("soilMoisture");
databaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int moistureLevel = dataSnapshot.getValue(Integer.class);
moistureTextView.setText("Moisture: " + moistureLevel);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w("Firebase", "Failed to read value.", databaseError.toException());
}
});
Step 5: Testing & Demonstration
1οΈβ£ Upload the ESP32 code and connect it to Firebase.
2οΈβ£ Run the Android app and check if soil moisture data is displayed.
3οΈβ£ Test the water pump by making the soil dry/wet.
4οΈβ£ Verify remote control functionality from the app.
β Congratulations! You have successfully built a smart irrigation system that saves water and automates plant watering. π
πΊ Watch the Full Video Tutorial
π΄ Smart Irrigation System Video on Yarana IoT Guru
π’ Check out our GitHub Repo for the full source code!
π Download Code
π Frequently Asked Questions (FAQs)
β Can I use this system for large farms?
β
Yes! You can scale it by adding more sensors and pumps.
β What if my WiFi goes down?
β
You can set up offline mode where the ESP32 runs without Firebase.
β Can I modify the app?
β
Yes! You can customize the UI and add features like notifications.
π Final Thoughts
This IoT-based smart irrigation system is a game-changer for farming and gardening. It helps you:
β
Save water
β
Improve plant health
β
Control irrigation remotely
Try this project today and take your farming automation to the next level! π