Automatic Plant Watering System with Arduino & Soil Moisture Sensor
Automatic Plant Watering System with Arduino & Capacitive Soil Moisture Sensor to turn on off relay based on Moisture Level & display on OLED
- Suitable forB.Tech/Diploma Arduino students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
Overview:
In this project, we’ll set up an
Automatic Plant Watering System
using
Arduino
and a
Soil Moisture Sensor
. Keeping plants watered just right can be a challenge. Sometimes we forget, or we might water them too much. Our solution helps ensure plants always get the
right amount of water
Our system uses the
Capacitive Soil Moisture Sensor
to see if the soil needs water. When it’s too dry (
below 40% moisture
), the Arduino tells a relay to turn on a
motor
, which pumps water to the plant. The cool part? You can see the
soil’s moisture level
on an
OLED Display
. This display also shows if the motor is on or off. When the soil is moist enough, the motor stops.
In this article, we’ll walk you through setting up the system. By the end, you’ll understand how the
Soil Moisture Sensor
and
OLED Display
work together with the
Arduino
and how the motor waters your plants when needed. You may check
IoT Plant Watering System
Project made using ESP8266
Bill of Materials:
The following are the components required for making Automatic Plant Watering System project.
S.N.
Components
Quantity
Purchase Link
Arduino Nano
Amazon
AliExpress
SunFounder
Capacitive Soil Moisture Sensor
Amazon
AliExpress
SunFounder
Relay 5V
Amazon
AliExpress
SunFounder
Transistor 2N2222
Amazon
AliExpress
SunFounder
Resistor 1K
Amazon
AliExpress
SunFounder
LED Red
Amazon
AliExpress
SunFounder
Diode 1N4007
Amazon
AliExpress
SunFounder
0.96" I2C OLED Display
Amazon
AliExpress
SunFounder
Water Pump Motor
Amazon
AliExpress
Male/Female Headers
Amazon
AliExpress
SunFounder
Capacitor 47uF, 25V
Amazon
AliExpress
SunFounder
DC Jack
Amazon
AliExpress
9V DC Adapter
Amazon
AliExpress
SunFounder
Jumper Wires
Amazon
AliExpress
SunFounder
Capacitive Soil Moisture Sensor
This is an
analog capacitive soil moisture sensor
which measures soil moisture levels by
capacitive sensing
. This means the capacitance is varied on the basis of water content present in the soil. You can convert the capacitance into voltage level basically from 1.2V minimum to 3.0V maximum. The advantage of Capacitive Soil Moisture Sensor is that they are made of a
corrosion-resistant material
giving it a long service life.
Features & Specifications
Supports 3-Pin Sensor interface
Analog output
Operating Voltage: DC 3.3-5.5V
Output Voltage: DC 0-3.0V
Interface: PH2.0-3P
Size: 99x16mm/3.9×0.63″
To learn more about Capacitive Soil Moisture Sensor you can follow this post:
Capacitive Soil Moisture Sensor Basic Interfacing Guide
DC 3-6V Micro Submersible Mini Water Pump
The
DC 3-6 V Mini Micro Submersible Water Pump
is a low cost, small size Submersible Pump Motor. It operates from a
2.5 ~ 6V power supply
. It can take up to 120 liters per hour with a very low current consumption of
220mA
. Just connect the tube pipe to the motor outlet, submerge it in water, and power it.
Features & Specifications
Operating Voltage: 2.5 ~ 6V
Operating Current: 130 ~ 220mA
Flow Rate: 80 ~ 120 L/H
Maximum Lift: 40 ~ 110 mm
Outlet Outside Diameter: 7.5 mm
Outlet Inside Diameter: 5 mm
0.96″ I2C OLED Display
The
0.96″ I2C OLED display
is a compact and versatile screen popular among electronics enthusiasts. Its OLED (
Organic Light-Emitting Diode
) nature means it produces its own light, achieving a high contrast ratio by turning off
individual pixels
for pure black. Unlike LCDs, this results in vibrant displays, even on such a small scale.
Using the
I2C (Inter-Integrated Circuit)
communication protocol, the display connects via only two wires:
SDA
for data and
SCL
for the clock. This makes interfacing with
microcontrollers
straightforward. With a typical resolution of
128×64 pixels
, these displays are commonly used many projects.
Automatic Plant Watering System with Arduino & Soil Moisture Sensor
The following is the schematic for the project Automatic Plant Watering System designed using the EasyEDA software.
Connect the VCC, GND & A0 pin Capacitive Soil moisture sensor to 3.3V, GND & A0 Pin of Arduino. The motor connects to Relay. To control the relay, we use the Pin 2 of Arduino.
Connect the OLED display to the I2C pin of Arduino. This means connect the VCC, GND, SCL & SDA pin of OLED to 3.3V, GND, A5 & A4 pin of Arduino. You can power the Motor and Relay using the 5V pin of Arduino. The Arduino Board is powered by 9V DC Adapter connected directly to Vin pin of Arduino.
You can assemble all the components on Zero PCB as per the circuit diagram above. For the Water Pump Motor, a pipe can be fixed which can draw water.
After assembling all components connect the Soil Moisture Sensor and Water Pump to the Board.
Source Code/Program
The code for Automatic Plant Watering System with Arduino & Soil Moisture Sensor project is written in Arduino IDE. The code requires
Adafruit SSD1306
library for compilation.
Copy the following code and paste it on your Arduino IDE.
#include <Adafruit_SSD1306.h> // Include the Adafruit SSD1306 library to interact with the display
#define SCREEN_WIDTH 128 // Set the width and height of the display in pixels
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // Set the OLED reset pin to -1 if it shares the Arduino reset pin
#define SCREEN_ADDRESS 0x3C // Set the address of the screen as specified in its datasheet
// Create an Adafruit_SSD1306 object called display
Adafruit_SSD1306
display
(
SCREEN_WIDTH
SCREEN_HEIGHT
&
Wire
OLED_RESET
)
;
const
int
AirValue
=
;
// Analog Value when Sensor is exposed to dry air
const
int
WaterValue
=
;
// Analog Value when Sensor is kept in water
const
int
SensorPin
=
A0
;
// Analog pin where the sensor is connected
// Variables to hold sensor values
int
soilMoistureValue
=
;
int
soilmoisturepercent
=
;
int
relaypin
=
;
// Pin where the relay is connected
void
setup
(
)
{
Serial
begin
(
9600
)
;
// Begin serial communication at 9600 bps
pinMode
(
relaypin
OUTPUT
)
;
// Set the relay pin as an output
digitalWrite
(
relaypin
LOW
)
;
// Start with the relay off
delay
(
)
;
// Start the display, looping forever if it fails
if
(
!
display
begin
(
SSD1306_SWITCHCAPVCC
SCREEN_ADDRESS
)
)
{
Serial
println
(
F
(
"SSD1306 allocation failed"
)
)
;
for
(
;
;
)
;
}
display
clearDisplay
(
)
;
// Clear the display and display the cleared screen
display
display
(
)
;
delay
(
)
;
}
// Function to update the display and control the relay based on soil moisture
void
updateDisplayAndRelay
(
)
{
const
char
*
motorStatus
=
(
soilmoisturepercent
<=
)
?
"ON"
:
"OFF"
;
// Set the motor status based on the soil moisture
if
(
soilmoisturepercent
<=
)
// Control the relay based on the soil moisture
{
digitalWrite
(
relaypin
HIGH
)
;
}
else
{
digitalWrite
(
relaypin
LOW
)
;
}
// Clear the display and set the text color
display
clearDisplay
(
)
;
display
setTextColor
(
SSD1306_WHITE
)
;
// Display the soil moisture
display
setCursor
(
)
;
display
setTextSize
(
)
;
display
(
"Soil Moisture: "
)
;
display
setCursor
(
)
;
display
setTextSize
(
)
;
display
(
soilmoisturepercent
)
;
display
setTextSize
(
)
;
display
(
"%"
)
;
// Display the motor status
display
setCursor
(
)
;
display
setTextSize
(
)
;
display
(
"Motor: "
)
;
display
(
motorStatus
)
;
// Update the display with the new text
display
display
(
)
;
// Print the soil moisture and motor status to the serial monitor
Serial
(
"Soil moisture: "
)
;
Serial
(
soilmoisturepercent
)
;
Serial
println
(
"%"
)
;
Serial
(
"Mot
In this project, we’ll set up an
Automatic Plant Watering System
using
Arduino
and a
Soil Moisture Sensor
. Keeping plants watered just right can be a challenge. Sometimes we forget, or we might water them too much. Our solution helps ensure plants always get the
right amount of water
Our system uses the
Capacitive Soil Moisture Sensor
to see if the soil needs water. When it’s too dry (
below 40% moisture
), the Arduino tells a relay to turn on a
motor
, which pumps water to the plant. The cool part? You can see the
soil’s moisture level
on an
OLED Display
. This display also shows if the motor is on or off. When the soil is moist enough, the motor stops.
In this article, we’ll walk you through setting up the system. By the end, you’ll understand how the
Soil Moisture Sensor
and
OLED Display
work together with the
Arduino
and how the motor waters your plants when needed. You may check
IoT Plant Watering System
Project made using ESP8266
Bill of Materials:
The following are the components required for making Automatic Plant Watering System project.
S.N.
Components
Quantity
Purchase Link
Arduino Nano
Amazon
AliExpress
SunFounder
Capacitive Soil Moisture Sensor
Amazon
AliExpress
SunFounder
Relay 5V
Amazon
AliExpress
SunFounder
Transistor 2N2222
Amazon
AliExpress
SunFounder
Resistor 1K
Amazon
AliExpress
SunFounder
LED Red
Amazon
AliExpress
SunFounder
Diode 1N4007
Amazon
AliExpress
SunFounder
0.96" I2C OLED Display
Amazon
AliExpress
SunFounder
Water Pump Motor
Amazon
AliExpress
Male/Female Headers
Amazon
AliExpress
SunFounder
Capacitor 47uF, 25V
Amazon
AliExpress
SunFounder
DC Jack
Amazon
AliExpress
9V DC Adapter
Amazon
AliExpress
SunFounder
Jumper Wires
Amazon
AliExpress
SunFounder
Capacitive Soil Moisture Sensor
This is an
analog capacitive soil moisture sensor
which measures soil moisture levels by
capacitive sensing
. This means the capacitance is varied on the basis of water content present in the soil. You can convert the capacitance into voltage level basically from 1.2V minimum to 3.0V maximum. The advantage of Capacitive Soil Moisture Sensor is that they are made of a
corrosion-resistant material
giving it a long service life.
Features & Specifications
Supports 3-Pin Sensor interface
Analog output
Operating Voltage: DC 3.3-5.5V
Output Voltage: DC 0-3.0V
Interface: PH2.0-3P
Size: 99x16mm/3.9×0.63″
To learn more about Capacitive Soil Moisture Sensor you can follow this post:
Capacitive Soil Moisture Sensor Basic Interfacing Guide
DC 3-6V Micro Submersible Mini Water Pump
The
DC 3-6 V Mini Micro Submersible Water Pump
is a low cost, small size Submersible Pump Motor. It operates from a
2.5 ~ 6V power supply
. It can take up to 120 liters per hour with a very low current consumption of
220mA
. Just connect the tube pipe to the motor outlet, submerge it in water, and power it.
Features & Specifications
Operating Voltage: 2.5 ~ 6V
Operating Current: 130 ~ 220mA
Flow Rate: 80 ~ 120 L/H
Maximum Lift: 40 ~ 110 mm
Outlet Outside Diameter: 7.5 mm
Outlet Inside Diameter: 5 mm
0.96″ I2C OLED Display
The
0.96″ I2C OLED display
is a compact and versatile screen popular among electronics enthusiasts. Its OLED (
Organic Light-Emitting Diode
) nature means it produces its own light, achieving a high contrast ratio by turning off
individual pixels
for pure black. Unlike LCDs, this results in vibrant displays, even on such a small scale.
Using the
I2C (Inter-Integrated Circuit)
communication protocol, the display connects via only two wires:
SDA
for data and
SCL
for the clock. This makes interfacing with
microcontrollers
straightforward. With a typical resolution of
128×64 pixels
, these displays are commonly used many projects.
Automatic Plant Watering System with Arduino & Soil Moisture Sensor
The following is the schematic for the project Automatic Plant Watering System designed using the EasyEDA software.
Connect the VCC, GND & A0 pin Capacitive Soil moisture sensor to 3.3V, GND & A0 Pin of Arduino. The motor connects to Relay. To control the relay, we use the Pin 2 of Arduino.
Connect the OLED display to the I2C pin of Arduino. This means connect the VCC, GND, SCL & SDA pin of OLED to 3.3V, GND, A5 & A4 pin of Arduino. You can power the Motor and Relay using the 5V pin of Arduino. The Arduino Board is powered by 9V DC Adapter connected directly to Vin pin of Arduino.
You can assemble all the components on Zero PCB as per the circuit diagram above. For the Water Pump Motor, a pipe can be fixed which can draw water.
After assembling all components connect the Soil Moisture Sensor and Water Pump to the Board.
Source Code/Program
The code for Automatic Plant Watering System with Arduino & Soil Moisture Sensor project is written in Arduino IDE. The code requires
Adafruit SSD1306
library for compilation.
Copy the following code and paste it on your Arduino IDE.
#include <Adafruit_SSD1306.h> // Include the Adafruit SSD1306 library to interact with the display
#define SCREEN_WIDTH 128 // Set the width and height of the display in pixels
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // Set the OLED reset pin to -1 if it shares the Arduino reset pin
#define SCREEN_ADDRESS 0x3C // Set the address of the screen as specified in its datasheet
// Create an Adafruit_SSD1306 object called display
Adafruit_SSD1306
display
(
SCREEN_WIDTH
SCREEN_HEIGHT
&
Wire
OLED_RESET
)
;
const
int
AirValue
=
;
// Analog Value when Sensor is exposed to dry air
const
int
WaterValue
=
;
// Analog Value when Sensor is kept in water
const
int
SensorPin
=
A0
;
// Analog pin where the sensor is connected
// Variables to hold sensor values
int
soilMoistureValue
=
;
int
soilmoisturepercent
=
;
int
relaypin
=
;
// Pin where the relay is connected
void
setup
(
)
{
Serial
begin
(
9600
)
;
// Begin serial communication at 9600 bps
pinMode
(
relaypin
OUTPUT
)
;
// Set the relay pin as an output
digitalWrite
(
relaypin
LOW
)
;
// Start with the relay off
delay
(
)
;
// Start the display, looping forever if it fails
if
(
!
display
begin
(
SSD1306_SWITCHCAPVCC
SCREEN_ADDRESS
)
)
{
Serial
println
(
F
(
"SSD1306 allocation failed"
)
)
;
for
(
;
;
)
;
}
display
clearDisplay
(
)
;
// Clear the display and display the cleared screen
display
display
(
)
;
delay
(
)
;
}
// Function to update the display and control the relay based on soil moisture
void
updateDisplayAndRelay
(
)
{
const
char
*
motorStatus
=
(
soilmoisturepercent
<=
)
?
"ON"
:
"OFF"
;
// Set the motor status based on the soil moisture
if
(
soilmoisturepercent
<=
)
// Control the relay based on the soil moisture
{
digitalWrite
(
relaypin
HIGH
)
;
}
else
{
digitalWrite
(
relaypin
LOW
)
;
}
// Clear the display and set the text color
display
clearDisplay
(
)
;
display
setTextColor
(
SSD1306_WHITE
)
;
// Display the soil moisture
display
setCursor
(
)
;
display
setTextSize
(
)
;
display
(
"Soil Moisture: "
)
;
display
setCursor
(
)
;
display
setTextSize
(
)
;
display
(
soilmoisturepercent
)
;
display
setTextSize
(
)
;
display
(
"%"
)
;
// Display the motor status
display
setCursor
(
)
;
display
setTextSize
(
)
;
display
(
"Motor: "
)
;
display
(
motorStatus
)
;
// Update the display with the new text
display
display
(
)
;
// Print the soil moisture and motor status to the serial monitor
Serial
(
"Soil moisture: "
)
;
Serial
(
soilmoisturepercent
)
;
Serial
println
(
"%"
)
;
Serial
(
"Mot
Technologies used
Hardware components
- ESP8266
- Arduino
- SSD1306
- OLED
- Relay
- Soil Moisture
Software & tools
- Arduino IDE
- EasyEDA
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.