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.
Components Required
- 1 x Arduino (Uno, Nano, etc.)
- 1 x Soil moisture sensor
- 1 x Relay module
- 1 x Small water pump
- 1 x 9V or 12V power supply for the pump
- Jumper wires
- Breadboard
- 1 x Diode (optional, for pump protection)
No Ads Available.
System Overview
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.
Wiring the Components
Follow these steps to set up the system:
- Connect the VCC and GND of the soil moisture sensor to the Arduino's 5V and GND pins.
- Connect the analog output pin of the moisture sensor to the A0 pin on the Arduino.
- Connect the IN pin of the relay module to pin 7 on the Arduino.
- Connect the VCC and GND of the relay module to the Arduino's 5V and GND pins.
- Wire the relay to control the water pump's power. Connect the pump’s power supply through the relay's normally open (NO) and common (COM) terminals.
Arduino Code
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
}
Code Explanation
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.
Upload and Test
- Upload the code to your Arduino.
- Monitor the serial output to check the current moisture level.
- If the soil is dry (below the threshold), the pump will turn on automatically. It will stop once the soil reaches a sufficient moisture level.
Expansion Ideas
Here are a few ideas to expand your smart plant watering system:
- Water Level Sensor: Add a water level sensor to monitor the water tank and avoid overwatering.
- LCD Display: Attach an LCD to display the soil moisture level and watering status.
- Wi-Fi Control: Integrate an ESP8266 or ESP32 module to control the watering system remotely via a smartphone app.
- Multiple Plants: Add more sensors and relays to create a system for multiple plants in different locations.
Conclusion
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.