Automatic Plant Watering System Kit Documentation
The Automatic Plant Watering System Kit is a comprehensive IoT solution designed to automate the watering process for plants. This kit consists of a soil moisture sensor, a water pump, a solenoid valve, and a microcontroller board. The kit is ideal for home automation, agriculture, and gardening applications.
Soil Moisture Sensor (YL-69): measures the soil moisture levels
Water Pump (DC 6V): pumps water to the plants
Solenoid Valve (2-Way): controls the water flow to the plants
Microcontroller Board (Arduino/ESP32): controls the entire system and communicates with the sensors and actuators
Microcontroller Board programming using Arduino IDE or ESP32 framework
Optional: Wi-Fi or cellular connectivity for remote monitoring and control
### Example 1: Basic Automatic Watering Using Arduino
This example demonstrates how to use the Automatic Plant Watering System Kit with an Arduino board to automate the watering process based on soil moisture levels.
```c++
#include <Arduino.h>
// Define pin connections
const int soilMoisturePin = A0; // Soil moisture sensor pin
const int pumpPin = 9; // Water pump pin
const int valvePin = 10; // Solenoid valve pin
void setup() {
Serial.begin(9600);
pinMode(soilMoisturePin, INPUT);
pinMode(pumpPin, OUTPUT);
pinMode(valvePin, OUTPUT);
}
void loop() {
int soilMoistureValue = analogRead(soilMoisturePin);
if (soilMoistureValue < 400) { // adjust the threshold value based on your soil type
digitalWrite(pumpPin, HIGH);
digitalWrite(valvePin, HIGH);
delay(10000); // water the plants for 10 seconds
digitalWrite(pumpPin, LOW);
digitalWrite(valvePin, LOW);
delay(3600000); // wait for 1 hour before checking again
} else {
digitalWrite(pumpPin, LOW);
digitalWrite(valvePin, LOW);
}
delay(1000); // check soil moisture every 1 second
}
```
### Example 2: Remote Monitoring and Control using ESP32 and Wi-Fi
This example demonstrates how to use the Automatic Plant Watering System Kit with an ESP32 board to monitor and control the watering process remotely using Wi-Fi.
```c++
#include <WiFi.h>
#include <HTTPClient.h>
// Define Wi-Fi credentials and API endpoint
const char ssid = "your_wifi_ssid";
const char password = "your_wifi_password";
const char apiEndpoint = "http://your-api-endpoint.com/plant_watering";
// Define pin connections
const int soilMoisturePin = 32; // Soil moisture sensor pin
const int pumpPin = 25; // Water pump pin
const int valvePin = 26; // Solenoid valve pin
WiFiClient client;
HTTPClient http;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
http.begin(apiEndpoint);
}
void loop() {
int soilMoistureValue = analogRead(soilMoisturePin);
if (soilMoistureValue < 400) { // adjust the threshold value based on your soil type
digitalWrite(pumpPin, HIGH);
digitalWrite(valvePin, HIGH);
delay(10000); // water the plants for 10 seconds
digitalWrite(pumpPin, LOW);
digitalWrite(valvePin, LOW);
delay(3600000); // wait for 1 hour before checking again
} else {
digitalWrite(pumpPin, LOW);
digitalWrite(valvePin, LOW);
}
// Send soil moisture data to API endpoint
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
http.POST("soil_moisture=" + String(soilMoistureValue));
int statusCode = http.responseStatusCode();
if (statusCode == 200) {
Serial.println("Data sent successfully");
} else {
Serial.println("Error sending data: " + String(statusCode));
}
delay(1000); // check soil moisture and send data every 1 second
}
```
Note: In this example, you need to create an API endpoint to receive the soil moisture data and send control signals to the ESP32 board. The API endpoint can be implemented using a server-side programming language like Python, Node.js, or PHP.
### Example 3: Scheduled Watering using ESP32 and RTC
This example demonstrates how to use the Automatic Plant Watering System Kit with an ESP32 board to automate the watering process based on a schedule using a Real-Time Clock (RTC).
```c++
#include <WiFi.h>
#include <RTClib.h>
// Define RTC module
RTC_DS3231 rtc;
// Define pin connections
const int soilMoisturePin = 32; // Soil moisture sensor pin
const int pumpPin = 25; // Water pump pin
const int valvePin = 26; // Solenoid valve pin
void setup() {
Serial.begin(115200);
rtc.begin();
if (!rtc.isrunning()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
DateTime now = rtc.now();
if (now.hour() == 8 && now.minute() == 0 && now.second() == 0) { // adjust the schedule based on your needs
int soilMoistureValue = analogRead(soilMoisturePin);
if (soilMoistureValue < 400) { // adjust the threshold value based on your soil type
digitalWrite(pumpPin, HIGH);
digitalWrite(valvePin, HIGH);
delay(10000); // water the plants for 10 seconds
digitalWrite(pumpPin, LOW);
digitalWrite(valvePin, LOW);
}
}
delay(1000); // check the schedule every 1 second
}
```
Note: In this example, you need to connect the ESP32 board to the internet to set the RTC module with the current date and time. You can use the `WiFi` library to connect to a Wi-Fi network and set the RTC module.