1. Connect the Soil Moisture Sensor:
- Connect the VCC pin of the sensor to the 3.3V pin on the NodeMCU.
- Connect the GND pin of the sensor to the GND pin on the NodeMCU.
- Connect the A0 pin of the sensor to the A0 pin on the NodeMCU.
2. Connect the Relay Module:
- Connect the VCC pin of the relay module to the 3.3V pin on the NodeMCU.
- Connect the GND pin of the relay module to the GND pin on the NodeMCU.
- Connect the IN1 pin of the relay module to a digital pin (e.g., D1) on the NodeMCU.
3. Connect the Water Pump:
- Connect the positive terminal of the water pump to the common (COM) terminal of the relay.
- Connect the negative terminal of the water pump to the normally open (NO) terminal of the relay.
Programming:
Write a program in Arduino IDE using the ESP8266 board support package. Utilize libraries for reading the soil moisture sensor and controlling the relay module.
#include <ESP8266WiFi.h>
// WiFi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
// Pin definitions
const int moistureSensorPin = A0;
const int relayPin = D1;
// Moisture threshold (adjust as needed)
const int moistureThreshold = 500;
void setup() {
Serial.begin(115200);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Ensure relay is off initially
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
}
void loop() {
int moistureValue = analogRead(moistureSensorPin);
Serial.print("Moisture: ");
Serial.println(moistureValue);
if (moistureValue < moistureThreshold) {
Serial.println("Soil is dry. Turning on pump.");
digitalWrite(relayPin, HIGH); // Turn on relay (activate pump)
delay(5000); // Run pump for 5 seconds (adjust as needed)
digitalWrite(relayPin, LOW); // Turn off relay
}
delay(60000); // Check moisture every minute (adjust as needed)
}
Optional Features:
- Implement a real-time clock (RTC) module for scheduling irrigation times.
- Add a water level sensor to monitor water reservoir levels.
- Integrate with a mobile app for remote monitoring and control.
Conclusion:
Building a Smart Irrigation System with the NodeMCU ESP8266 demonstrates the practical application of IoT technology in agriculture. This project provides a foundation for developing more sophisticated smart farming solutions and showcases the versatility of the ESP8266 microcontroller in IoT projects.
Comments
Please log in or sign up to comment.