Arduino
NAME : ___________________________
CLASS : ____________________________
Content by:
● www.aimsity.com Aimsity
1
Table Content
2
PROJECT: SMART PLANT SYSTEM
______________________________________________
Introduction
This project is a Smart Plant System using Arduino, designed to automate plant care by
monitoring soil moisture and providing irrigation when necessary. The system uses a capacitive
soil moisture sensor to detect the water content in the soil. If the sensor indicates that the soil is
too dry, the Arduino triggers a relay to activate a water pump, delivering water to the plant. An
LCD screen provides real-time feedback, displaying the soil moisture level and the system's
status. The water pump is powered by batteries, ensuring the system remains operational even
without a direct power source. A breadboard is used to simplify connections and organize the
components.
This project is practical for maintaining houseplants, small gardens, or even agricultural setups,
reducing the need for manual watering. It is particularly useful for individuals with busy
schedules, frequent travelers, or those managing multiple plants. For example, homeowners can
use this system to ensure their indoor plants remain healthy while they are on vacation. Farmers
with smaller greenhouses can implement it to automate irrigation without requiring constant
supervision. Additionally, it can be used in urban gardening setups, such as balcony gardens, to
help conserve water and ensure efficient plant care.
The system integrates physical components and code to function seamlessly. The hardware
includes a capacitive soil moisture sensor for data collection, a relay to control the water pump,
an LCD for status of soil and motor of the water pump, and a battery-powered water pump for
irrigation. The Arduino acts as the brain of the system, processing the sensor’s input and
executing programmed actions. For example, when the soil moisture falls below a predefined
threshold, the Arduino activates the relay to power the water pump, irrigates the soil, and updates
the LCD to reflect the soil’s moisture condition and the operational status of the water pump.
This synergy between hardware and software creates a reliable and efficient plant care system
that is both educational and practical for real-world use cases.
__________________________________________________________________
Learning Objectives
1. Understanding Automation in Agriculture
2. Familiarizing with Sensors and Modules
3. Programming Microcontrollers
4. Circuit Design and Hardware Integration
5. Problem-Solving and Debugging
3
6. Sustainability Awareness
Components
Arduino Mega - It is designed for
projects requiring a larger number of
input/output pins or more memory than
the standard Arduino UNO
Capacitive Soil Moisture Sensor - It is
used in automated irrigation systems,
and soil analysis in agriculture or
gardening.
4
Micro Submersible Water Pump -
This sensor measures soil moisture
based on its capacitance, which varies
with the water content in the soil.
Unlink resistive sensors, it doesn’t
corrode over time
Single Channel 5V Relay Breakout
Board - It automates high-power
devices like pumps, lights or
appliances and protects the Arduino
from high-current circuits.
Breadboard - It is a reusable
platform for prototyping circuits
without soldering.
5
Male-to-Male Jumper Wire - It
used to connect components on
breadboards and link pins on
microcontroller boards like
Arduino.
Male-to-Female Jumper Wire - It
is used to link Arduino pins to
sensors, modules or breadboards and
bridges gaps between incompatible
connectors.
Arduino Mega USB Cables - It allows you
to power the Arduino Mega and communicate
between Arduino Mega and computer when
connected to a computer.
6
5V battery - The water pump is powered
by 5V batteries, which provide the
necessary energy to operate the pump
independently.
7
Learning Outcome
8
Step 1: CONNECT THE BREADBOARD
Arduino Mega Breadboard
5v Red Line: Positive rail.
GND Blue Line: Negative rail.
Connect to Arduino Mega to the Breadboard:
1. GND Pin:
○ use a male-to male jumper wire to connect the Arduino’s GND pin to the
breadboard’ s negative rail (blue line).
○ This step causes the whole row of the negative rails (blue line) to be GND.
○ The others of components which need the connection of GND and do not have
enough pins of GND, we can connect through everywhere of the row.
2. 5v Pin:
○ Use another jumper wire to connect the Arduino’s 5v pin to the breadboard’s
positive rail (red line).
○ This step causes the whole row of the positive rails (red lines) to be 5v of power.
○ The others of components which need power of 5v and do not have enough pins
from the board, we can connect through everywhere of the row.
9
10
Step 2: CONNECT THE LCD I2C Display
LCD 12C Display Connect to:
SDA Arduino Mega: Pin 20
SCL Arduino Mega :Pin 21
VCC BreadBoard: Positive rail (red)
GND BreadBoard: Negative rail (blue)
The function for each pin:
1. GND (Ground):
○ To provide a reference voltage level for the LCD module and complete the circuit.
2. VCC (Power Supply):
○ To supply power to the LCD module, ensuring it operates properly.
3. SDA (Serial Data Line):
○ Transmits data from the Arduino to the LCD. This line carries the information to
be displayed (examples: text)
4. SCL (Serial Clock Line):
○ To provide a clock signal to synchronize communication between the Arduino
and the LCD.
11
Test the LCD:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with I2C address 0x27 (common address)
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.begin(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0); // Set cursor to the first row, first column
lcd.print("Hello, World!"); // Print a test message
}
void loop() {
// Nothing to do here
}
12
13
Step 3: Connect the Soil Moisture Sensor
Soil Moisture Sensor Connect to:
Analog Output Arduino Mega: A0
VCC Breadboard: Positive rails (red)
GND Breadboard: Negative rails (blue)
Explanation for the connections:
1. AO to A0 (Arduino Mega):
○ The AO pin outputs a continuous analog voltage that corresponds to the soil
moisture level. This voltage is proportional to the amount of water in the soil.
○ Connecting AO to the Arduino’s A0 pin allows the Arduino to read this analog
signal using its built-in analog-to-digital converter (ADC).
Why Analog Output (AO)?
○ Analog input pins (like A0) on the Arduino are designed to read varying voltage
levels. By interpreting the voltage from the sensor, the Arduino can calculate the
moisture level and take actions (e.g., activating the water pump).
2. VCC to Positive Rail (Breadboard):
○ The VCC pin is the power input for the sensor module. Connecting it to the
positive rail of the breadboard (powered by Arduino’s 5V pin) ensures the sensor
receives the electrical energy required for operation.
Why Positive Rail?
○ The breadboard positive rail acts as a convenient distribution line for 5V power,
allowing multiple components (e.g., LCD, relay, sensor) to share the same power
source.
3. GND to Negative Rail (Breadboard):
○ The GND pin is the return path for the electrical current. Connecting it to the
Arduino’s GND pin via the breadboard’s negative rail completes the circuit.
Why Negative Rail?
14
○ The negative rail on the breadboard serves as a common ground for all
components, ensuring all parts in the circuit share the same reference point for
voltage.
15
Step 4: Connect Relay, Water Pump and Batteries.
Water Pump Connect to:
Negative Wire Batteries: Negative wire
Positive Wire Relay: Com pin
Relay Connect to:
Vcc Breadboard: Positive rail (red)
GND Breadboard: Negative rail (blue)
IN Arduino Mega: pin 22
Battery Connect to:
Positive Wire Relay: NO
Negative Wire Water Pump: Negative wire
1. Negative Wire of Water Pump to Negative Wire of the Batteries:
○ This completes the ground connection for the water pump, allowing current to
flow when the circuit is closed.
Why Connect to Battery’s Negative Terminal?
○ The water pump requires a separate power source which is the batteries.
Connecting the pump’s negative terminal to the battery’s negative terminal
establishes a shared ground, ensuring proper operation and preventing potential
power imbalances.
○ Without this connection, the circuit for the water pump would be incomplete, and
the pump would not function properly.
2. Positive Wire of the Water pump to the COM pin of the Relay:
16
○ The COM (Common) pin on the relay is the central point of the switching
mechanism. Connecting the positive wire of the water pump to this pin allows the
relay to control the pump's power supply.
Why COM Pin?
○ The relay acts as an electronically controlled switch. The COM pin serves as the
connection point for the circuit that the relay will control (in this case, the water
pump).
○ When the relay is activated, the COM pin connects to either the NO (Normally
Open) or NC (Normally Closed) pin, depending on the relay’s configuration. In
this setup, the COM pin connects to the NO pin to power the pump only when the
relay is triggered.
3. VCC and GND of the Relay to Positive and Negative Rails of the
Breadboard:
○ The relay requires power to operate its internal electromagnetic switch. The VCC
pin receives power from the positive rail, and the GND pin connects to the
negative rail.
Why Use the Breadboard Rails?
○ The breadboard's positive and negative rails distribute power from the Arduino or
an external power source to multiple components, making it easier to connect and
organize the circuit.
○ Using the rails ensures that the relay module is consistently powered and ready to
respond to control signals from the Arduino.
4. IN of Relay to Arduino Mega Pin 22:
○ The IN pin is the control input for the relay. Connecting it to pin 22 on the
Arduino allows the Arduino to send a signal to turn the relay ON or OFF.
Why Pin 22?
○ Pin 22 is a digital pin on the Arduino Mega, and it can output a HIGH or LOW
signal to control the relay.
○ When the Arduino outputs a HIGH signal, the relay activates, closing the circuit
between the COM and NO pins, and powering the water pump.
○ This connection enables the Arduino to precisely control the operation of the
water pump based on the soil moisture sensor's readings.
17
5. Positive Wire of Battery to NO (Normally Open) Pin of Relay:
○ The NO (Normally Open) pin is part of the relay's switching mechanism.
Connecting the battery's positive terminal to this pin ensures that the water pump
remains OFF by default.
○ When the relay is activated, the NO pin connects to the COM pin, powering the
water pump.
Why NO Pin?
○ The relay is configured so the pump only receives power when the Arduino
signals the relay to close the circuit. This prevents unnecessary operation of the
pump, conserving battery power and preventing overwatering.
6. Negative Wire of Battery to Negative Wire of the Water Pump
○ This ensures the negative terminal of the power source (battery) is directly
connected to the negative terminal of the water pump.
Why Connect These?
○ Completing the ground connection allows current to flow through the pump when
the relay closes the circuit, enabling the pump to operate.
○ This connection ensures a consistent and stable power supply to the pump,
avoiding interruptions caused by incomplete circuits.
18
19
Step 5: Install and Open Arduino
Install Arduino:
Step 1: Search Arduino on Google.
Step 2: Select the Operating System of your computer (e.g., window,
macOS)
20
Step 3: Click I Agree
Step 4: Select Only for me and click Next
21
Select 5: Select or browse your disk and file and click install.
Step 6: Wait for installing
22
Step 7: Select Run Arduino IDE and click finish
23
Open Arduino IDE:
Step 1: Start the Arduino IDE
● Turn on your laptop and connect your Arduino Mega to the USB port.
● Locate the Arduino IDE icon on your desktop or in your applications menu and
double-click it to open.
Step 2: Create a New Sketch
● In the Arduino IDE, click on the FILE in the top left corner of the menu.
● Click the New Sketch of the menu.
Step 3: Select the Board
● Click the dropdown menu list.
● Select the COM that you connected with the USB and computer.
● Make sure the board is the Arduino Mega.
24
Step 4: Select the Programmer
● Click on Tools in the top menu.
● Navigate to Programmer, then select AVR ISP from the list.
25
Step 5: Run the Codes
1. Included Libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
● Wire.h: It enables communication between the Arduino and other devices using
the I2C protocol which is the LCD.
● LiquidCrystal_I2C.h: It simplifies the process of controlling an I2C based LCD
with Arduino.
2. LCD Setup
LiquidCrystal_I2C lcd(0x27, 16, 2);
This line of code creates an LCD object that allows the Arduino to control the connected
I2C LCD module.
● LiquidCrystal_I2C
○ This is the class provided by the <LiquidCrystal_I2C.h> library.
○ It defines an object that can manage and interact with an I2C-based LCD
display.
● lcd
○ This is the name of the object you are creating.
○ You can use this name to call methods like lcd.begin(),
lcd.print(), and lcd.clear() to control the LCD.
● 0x27
○ What It Is: The I2C address of the LCD module.
26
○ Why It Is Needed: Every I2C device on the same bus has a unique
address. The Arduino uses this address to send commands or data to the
correct device.
● 16
○ What It Is: The number of columns (characters) the LCD can display in
one row.
○ Why It Is Needed: This tells the Arduino how much text can fit on each
row of the LCD.
● 2
○ What It Is: The number of rows the LCD has.
○ Why It Is Needed: This tells the Arduino how many lines of text the LCD
can display.
3. Pin Definitions
int sensor_pin = A0; // Soil moisture sensor pin (A0 for Mega)
int relay_pin = 22; // Relay pin (connected to pin 22)
● This line defines a variable named sensor_pin and assigns it the value A0.
● By using a variable for the pin number, the code is more flexible and easier to
modify. If the sensor needs to be connected to a different pin, you only need to
change this line instead of searching through the entire code.
4. Setup() Function
Serial.begin(9600); // Start serial communication for debugging
lcd.begin(16, 2); // Initialize LCD
lcd.backlight(); // Ensure backlight is on
pinMode(sensor_pin, INPUT); // Set soil sensor pin as input
pinMode(relay_pin, OUTPUT); // Set relay pin as output
● Serial.begin(9600);
27
○ Starts serial communication between the Arduino and a computer for
debugging purposes.
● lcd.begin(16, 2);
○ Initializes the LCD with the specified dimensions.
Why It Is Used:
○ Prepares the LCD to display text.
○ Without this initialization, the LCD won't function correctly.
● lcd.backlight();
○ Ensures the LCD's backlight is turned on.
● pinMode(sensor_pin, INPUT);
○ Configures the soil moisture sensor pin as an input pin.
Why It Is Used:
○ The Arduino needs to know the moisture level of the soil, which is
provided as an analog signal by the sensor.
○ Configuring the pin as INPUT ensures the Arduino can read this signal.
● pinMode(relay_pin, OUTPUT);
○ Configures the relay pin as an output pin.
Why It Is Used:
○ The Arduino needs to send a digital signal (HIGH or LOW) to control the
relay's state (ON or OFF).
○ Configuring the pin as OUTPUT ensures the Arduino can send these
signals.
5. Test Relay manually
digitalWrite(relay_pin, LOW); // Turn on motor (active-low relay)
delay(5000); // Wait for 5 seconds
28
digitalWrite(relay_pin, HIGH); // Turn off motor
delay(2000); // Wait 2 seconds
● digitalWrite(relay_pin, LOW);
○ Sends a LOW signal to the relay pin to activate the motor.
○ This line turns on the water pump by activating the relay, which closes the
circuit between the power source and the pump.
● delay(5000);
○ Pause the program execution for 5000 milliseconds (5 seconds)
○ Keep the motor running for 5 seconds to irrigate the soil. This ensures the
plant receives enough water based on the programmed duration.
● digitalWrite(relay_pin, HIGH);
○ Sends a HIGH signal to the relay pin to deactivate the motor.
○ This line turns off the water pump by deactivating the relay, stopping the
irrigation process.
● delay(2000);
○ Pauses the program execution for 2000 milliseconds ( 2 seconds)
○ Adds a buffer time before the next action in the program, allowing the
system to stabilize or perform other tasks.
6. loop() Functions
void loop() {
int sensor_data = analogRead(sensor_pin); // Read soil moisture sensor
// Print sensor data for debugging
Serial.print("Sensor Data: ");
Serial.println(sensor_data);
// Display sensor value on LCD for debugging
29
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sensor Value:");
lcd.setCursor(0, 1);
lcd.print(sensor_data);
// Check soil moisture level and control relay accordingly
if (sensor_data > 950) { // Soil is dry
Serial.println("Soil is dry");
digitalWrite(relay_pin, LOW); // Turn on motor (active-low relay)
lcd.setCursor(0, 0);
lcd.print("Soil Dry");
lcd.setCursor(0, 1);
lcd.print("Motor On");
else if (sensor_data >= 450 && sensor_data <= 950) { // Soil is medium
Serial.println("Soil is medium");
digitalWrite(relay_pin, HIGH); // Turn off motor
lcd.setCursor(0, 0);
lcd.print("Soil Medium");
lcd.setCursor(0, 1);
lcd.print("Motor OFF");
else if (sensor_data < 450) { // Soil is wet
30
Serial.println("Soil is wet");
digitalWrite(relay_pin, HIGH); // Turn off motor
lcd.setCursor(0, 0);
lcd.print("Soil Wet");
lcd.setCursor(0, 1);
lcd.print("Motor OFF");
delay(1000); // Wait for a second before next loop
● When Sensor detected the sensor_data is greater than 950:
○ The soil is dry.
○ Turn ON the motor by setting replay_pin to LOW.
○ Displays “Soil Dry” and “Motor On” on the LCD
○ Display “Soil is Dry” on the serial monitor.
● When Sensor detected the sensor_data is between 450 and 950:
○ The soil is medium.
○ Turn OFF the motor by setting relay_pin to HIGH.
○ Display “Soil Medium” and “Motor OFF” on the LCD
○ Display “Soil is medium” on the serial monitor.
● When Sensor detected the sensor_data is less than 450:
○ The soil is wet.
○ Turn OFF the motor by setting relay_pin to HIGH.
○ Display “Soil Wet” and “Motor OFF” on the LCD.
○ Display “Soil is wet” on the serial monitor.
● Delay
31
○ The delay(1000) ensures a 1-second interval between sensor readings,
providing stability to the system and avoiding rapid toggling of the relay.
How the System Work
1. Sensor Data Acquisition:
○ The Capacitive soil moisture sensor detects the soil’s water content and send an
analog signal (a value between 0 and 1023) to the Arduino via the A0 pin.
○ The value is read using analogRead(sensor_pin) and store in the variable
sensor_data.
Data Interpretation:
○ The sensor value correspond to soil conditions:
i. Dry Soil: High sensor values (greater than 950)
ii. Medium Moisture: Moderate sensor value (450 to 950)
iii. Wet Soil: Low sensor value (less than 450)
2. Decision-Making and Action:
○ Based on the sensor data, the Arduino determines the soil condition and performs
the following actions:
i. Dry Soil: Activates the water pump by setting the relay pin to LOW
(active-low relay)
ii. Medium Moisture: Turns OFF the water pump by setting the relay pin to
HIGH
iii. Wet Soil: Keeps the water pump OFF by setting the relay pun to HIGH
3. Visual and Debug Feedback:
○ LCD Display:
i. The soil moisture level and corresponding system status (e.g, “Motor On”
or “Motor Off”) are displayed on the LCD in real time.
○ Serial Monitor:
i. Sensor values and soil condition messages (“Soil is dry”, “Soil is
medium”, or “Soil is wet”) are printed for debugging purposes.
4. Motor and Relay Control:
○ Relay Integration:
32
i.The relay acts as a switch to control the water pump. It is powered via the
breadboard’s positive and negative rails and controlled by the Arduino’s
pin 22.
○ Water Pump Activation:
i. When the relay pin is LOW, the relay completes the circuit between the
water pump and the battery, turning the pump ON.
ii. When the relay pin is HIGH, the relay breaks the circuit, turning the
pump OFF.
5. System Workflow:
○ Start:
i. The system begins by reading soil moisture data.
○ Decision-Making:
i. The Arduino processes the data to decide whether the soil needs water.
○ Action:
i. If the soil is dry, the motor is activated to irrigate the plant for a specified
duration (delay 5 seconds) and then turned OFF.
ii. If the soil is sufficiently moist, the motor remains OFF.
○ Feedback:
i. The system continuously updates the LCD and Serial Monitor with
real-time data and actions.
Full Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD setup (address 0x27, 16 columns, 2 rows)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Pin Definitions
int sensor_pin = A0; // Soil moisture sensor pin (A0 for Mega)
int relay_pin = 22; // Relay pin (connected to pin 22)
33
void setup() {
Serial.begin(9600); // Start serial communication for debugging
lcd.begin(16, 2); // Initialize LCD
lcd.backlight(); // Ensure backlight is on
pinMode(sensor_pin, INPUT); // Set soil sensor pin as input
pinMode(relay_pin, OUTPUT); // Set relay pin as output
// Test relay manually
digitalWrite(relay_pin, LOW); // Turn on motor (active-low relay)
delay(5000); // Wait for 5 seconds
digitalWrite(relay_pin, HIGH); // Turn off motor
delay(2000); // Wait 2 seconds
void loop() {
int sensor_data = analogRead(sensor_pin); // Read soil moisture sensor
// Print sensor data for debugging
Serial.print("Sensor Data: ");
Serial.println(sensor_data);
// Display sensor value on LCD for debugging
lcd.clear();
lcd.setCursor(0, 0);
34
lcd.print("Sensor Value:");
lcd.setCursor(0, 1);
lcd.print(sensor_data);
// Check soil moisture level and control relay accordingly
if (sensor_data > 950) { // Soil is dry
Serial.println("Soil is dry");
digitalWrite(relay_pin, LOW); // Turn on motor (active-low relay)
lcd.setCursor(0, 0);
lcd.print("Soil Dry");
lcd.setCursor(0, 1);
lcd.print("Motor On");
else if (sensor_data >= 450 && sensor_data <= 950) { // Soil is medium
Serial.println("Soil is medium");
digitalWrite(relay_pin, HIGH); // Turn off motor
lcd.setCursor(0, 0);
lcd.print("Soil Medium");
lcd.setCursor(0, 1);
lcd.print("Motor OFF");
else if (sensor_data < 450) { // Soil is wet
Serial.println("Soil is wet");
digitalWrite(relay_pin, HIGH); // Turn off motor
35
lcd.setCursor(0, 0);
lcd.print("Soil Wet");
lcd.setCursor(0, 1);
lcd.print("Motor OFF");
delay(1000); // Wait for a second before next loop
36