Self-watering Plant
Self-watering Plant
This project solves a practical real-world problem through automation. The system monitors the moisture level of a potted plant's soil and automatically activates a pump when it gets too dry.
Components: Arduino board, analog soil moisture sensor, 5V relay module, mini submersible water pump, vinyl tubing.
The Build: The soil sensor reads the analog resistance of the dirt. When the value drops below a set threshold, the Arduino signals the relay. The relay acts as an electronic switch, completing the circuit for the water pump.
Learning Outcome: This is an excellent introduction to analog inputs (reading variable data rather than simple ON/OFF states) and using relays to control higher-current external devices safely.
An Arduino self-watering plant project uses a soil moisture sensor to monitor your plant’s hydration and an Arduino board to trigger a water pump when the soil gets too dry. It’s a fantastic, beginner-friendly build that ensures your plants are watered even while you are away. [1, 2, 3, 4]
https://www.hackster.io/428988/arduino-flower-watering-system-with-oled-display-54326b
Costs:
Irrigation Kit w/Sensor, Pump, Tubing, Relay $9.99
Arduino Nano ea $5.33
Half-Breadboard ea $1.26
9V Battery and Clip ea $3.00
Barrel-Jack Adaptor ea $0.79
$21.00
Key Hardware Components:
Arduino Board: The brain of the project (e.g., Arduino Uno or Nano).
Soil Moisture Sensor: Measures the electrical conductivity of the soil to determine how dry it is.
5V or 12V Submersible Water Pump: Moves water from your reservoir to the plant.
Relay Module( or MOS Driver Module): Acts as a switch. Because the pump requires more power than the Arduino can provide, the relay allows the Arduino to safely turn the pump on and off.
Tubing: Vinyl tubing (usually 1/4" or 1/8") to carry the water.
Power Supply: An external power source (like a 5V/1A or 12V adapter) to drive the water pump. [1, 2, 3, 4, 5, 6]
Optional: Wifi Module
Programming Concepts:
analogRead- reads value of moisture sensor
digitalWrite- used to turn on/turn off pump
if/else - if sensor value exceeds threshold, turns on pump, else turns it off
Internet of Things
const int pumpPin = 7;
const int sensorPin = A0;
int threshold = 400; // Adjust this threshold based on your sensor (lower values = drier soil)
void setup() {
pinMode(pumpPin, OUTPUT);
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(sensorPin);
Serial.print("Soil Moisture: ");
Serial.println(sensorValue);
if (sensorValue < threshold) {
Serial.println("Watering the plant!");
digitalWrite(pumpPin, HIGH); // Turn the pump on
delay(5000); // Water for 5 seconds
digitalWrite(pumpPin, LOW); // Turn the pump off
delay(5000); // Wait 5 seconds to prevent overwatering
}
delay(1000); // Check again in 1 second
}
Internet of Things Version:
To build a self-watering plant system that connects to the internet and logs data to ThingSpeak or Blynk, you will need a Wi-Fi-enabled microcontroller. The ESP8266 (like a NodeMCU or Wemos D1 Mini) or ESP32 are the standard choices for this, as a standard Arduino Uno does not have built-in Wi-Fi.
Below is the complete C++ Arduino code designed for an ESP8266.
Microcontroller: ESP8266 (or ESP32, with minor library adjustments).
Soil Moisture Sensor: Connected to the analog pin (A0).
Water Pump & Relay: A 5V relay module to safely turn the pump on and off, connected to a digital pin (e.g., D1 / GPIO 5).
Power Supply: Make sure you power the pump separately if it draws more current than the microcontroller can handle.
Before uploading, ensure you have installed the ESP8266 board package and the ThingSpeak library (by MathWorks) via the Arduino IDE Library Manager.
C++
#include <ESP8266WiFi.h>
#include "ThingSpeak.h"
// --- Wi-Fi Credentials ---
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
// --- ThingSpeak Settings ---
unsigned long myChannelNumber = YOUR_CHANNEL_NUMBER; // e.g., 1234567
const char * myWriteAPIKey = "YOUR_THINGSPEAK_WRITE_API_KEY";
// --- Hardware Pins ---
const int moisturePin = A0; // Analog pin for soil moisture sensor
const int relayPin = 5; // Digital pin (GPIO 5 / D1) for relay module
// --- Variables & Thresholds ---
// Note: Many analog sensors output HIGHER values when DRY, and LOWER when WET.
// You must calibrate this threshold based on your specific sensor.
const int dryThreshold = 700;
const int wateringTime = 5000; // How long the pump runs in milliseconds (5 seconds)
WiFiClient client;
void setup() {
Serial.begin(115200);
// Set up the relay pin
pinMode(relayPin, OUTPUT);
// Most 5V relay modules are active-LOW. We set it HIGH to ensure the pump starts OFF.
digitalWrite(relayPin, HIGH);
// Set up Wi-Fi
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop() {
// 1. Connect or reconnect to Wi-Fi
if (WiFi.status() != WL_CONNECTED) {
Serial.print("Connecting to Wi-Fi...");
while (WiFi.status() != WL_CONNECTED) {
WiFi.begin(ssid, password);
delay(5000);
Serial.print(".");
}
Serial.println("\nConnected!");
}
// 2. Read the soil moisture
int moistureValue = analogRead(moisturePin);
Serial.print("Soil Moisture Level: ");
Serial.println(moistureValue);
// 3. Check if the plant needs watering
if (moistureValue > dryThreshold) {
Serial.println("Soil is dry! Watering the plant...");
digitalWrite(relayPin, LOW); // Turn pump ON (Active-LOW)
delay(wateringTime); // Run pump for specified time
digitalWrite(relayPin, HIGH); // Turn pump OFF
Serial.println("Watering complete.");
} else {
Serial.println("Soil moisture is adequate. No watering needed.");
}
// 4. Send data to ThingSpeak (Field 1)
int httpCode = ThingSpeak.writeField(myChannelNumber, 1, moistureValue, myWriteAPIKey);
if(httpCode == 200){
Serial.println("ThingSpeak update successful.");
} else {
Serial.println("Problem updating ThingSpeak. HTTP error code: " + String(httpCode));
}
// 5. Wait before the next cycle
// ThingSpeak requires a minimum 15-second delay between updates on free accounts.
// For a plant, checking every 5 minutes (300,000 ms) is usually more than enough.
Serial.println("Waiting for next cycle...\n");
delay(300000);
}
Configure ThingSpeak:
Create a new channel on ThingSpeak.
Enable Field 1 and name it "Moisture Level".
Copy the Channel ID and the Write API Key, then paste them into the code where indicated.
Calibrate Your Sensor: * Do not trust the 700 threshold blindly. Soil moisture sensors vary wildly.
To calibrate: Upload the code, open the Serial Monitor (at 115200 baud), and observe the moistureValue when the sensor is in completely dry soil, and then again when it is in perfectly watered soil.
Update the dryThreshold variable to a number right between those two extremes.
Relay Module Logic:
The code assumes you are using a standard Active-LOW relay module (common for Arduino kits), meaning sending a LOW signal turns the switch ON, and a HIGH signal turns it OFF. If your pump turns on when it shouldn't, simply swap the LOW and HIGH commands in the watering block of the code.