This tutorial will guide you through building a smart plant watering system using an Arduino. The system uses a soil moisture sensor to detect soil dryness and automatically turns on a water pump when necessary.
The smart plant watering system works by constantly monitoring the moisture level in the soil using a soil moisture sensor. If the soil is too dry, the system will activate the water pump via a relay, watering the plant automatically. Once the desired moisture level is reached, the pump turns off.
Follow these steps to set up the system:
Here’s the Arduino code to monitor the soil moisture level and control the pump:
const int moisturePin = A0; // Pin connected to the soil moisture sensor
const int relayPin = 7; // Pin connected to the relay module
int moistureLevel = 0; // Variable to store the moisture level
const int threshold = 500; // Moisture level threshold to activate the pump
void setup() {
pinMode(relayPin, OUTPUT); // Set relay pin as output
digitalWrite(relayPin, HIGH); // Initially keep the pump off
Serial.begin(9600); // Start serial communication for monitoring
}
void loop() {
moistureLevel = analogRead(moisturePin); // Read moisture level from sensor
Serial.print("Moisture Level: ");
Serial.println(moistureLevel); // Print the moisture level to serial monitor
if (moistureLevel < threshold) { // If soil is too dry
digitalWrite(relayPin, LOW); // Activate the pump (turn on relay)
Serial.println("Watering the plant...");
} else {
digitalWrite(relayPin, HIGH); // Deactivate the pump (turn off relay)
Serial.println("Soil moisture is sufficient.");
}
delay(1000); // Wait for 1 second before taking the next reading
}
const int moisturePin = A0;
: Defines the analog pin (A0) where the soil moisture sensor is connected.analogRead(moisturePin);
: Reads the analog value from the sensor, which is proportional to the soil moisture.const int threshold = 500;
: Sets a threshold value; when the soil moisture is below this level, the pump will activate.digitalWrite(relayPin, LOW);
: Activates the relay, turning on the water pump when the soil is dry.Here are a few ideas to expand your smart plant watering system:
You have successfully built a smart plant watering system! This can be expanded by adding features like a water level sensor, a display showing moisture levels, or remote control via Wi-Fi using an ESP8266. Such systems can make gardening easier and help ensure that your plants receive the proper care even when you're not around.