Automated Plant Watering System

by vasseurhannah in Circuits > Arduino

16 Views, 0 Favorites, 0 Comments

Automated Plant Watering System

project.jpg

An automated watering system using a soil moisture sensor and Arduino is an efficient way to ensure plants receive the right amount of water without manual intervention. This system is particularly useful for home gardens, greenhouses, and agricultural applications where consistent watering is necessary for plant health. The project will utilize two buttons, each representing different plants and their moisture thresholds. It will also utilize a soil moisture sensor to detect moisture levels in the soil, an Arduino microcontroller to process the data, and a water pump to supply water as needed. When the soil moisture falls below the predefined threshold, the Arduino activates the pump to water the plants. Once the desired moisture level is reached, the system stops the water flow, conserving water and preventing overwatering.

Supplies

arduino.png
breadboard.png
buttons.png
moisture sensors.png
pumps.png
relays.png

Collect Your Supplies

Arduino Board (Uno) – The microcontroller that processes sensor data and controls the pump.

Breadboard – Used for circuit connections and stability.

Buttons – Used to determine what plant is being watered.

Soil Moisture Sensor – Measures the moisture level in the soil and sends data to the Arduino.

Water Pump (DC or Submersible Pump) – Supplies water to the plants when activated.

Tubing – Delivers water from the pump to the plants.

Relay Module – Acts as a switch to control the pump based on Arduino signals.

Wires – Used for connecting components.

Power Supply (9V Battery) – Provides power to the relay.

Water Reservoir – Holds water for irrigation.

Plant - is the test subject for the project.


Setting Up the Connections

circuit new.png

Moisture Sensor:

Analog Output (AO) to Analog Pin A0 on Arduino.

VCC to 5V on Arduino.

GND to GND on Arduino.


Relay Module:

IN (control pin) to Digital Pin 7 on Arduino.

VCC and GND powered from the 9V battery (via relay's own terminals).


Buttons:

One button connects GND to Digital Pin 2 (yellow wire).

Second button connects GND to Digital Pin 3 (green wire).


Pump:

The pump (white box) is powered by the relay:

One wire from the pump goes directly to battery positive.

The other goes through the NO (Normally Open) terminal of the relay.

When the relay is triggered (closed), the circuit completes and the pump runs.

Physical Set Up of the System

project.jpg

Once the connections are set up, the plants, water, and tubing can be added. The pump is submerged into the water container with a tube connected to it. This tube is then ran to the soil of the plant in which the moisture sensor is in.

Develope the Code

// Pin configuration

const int moistureSensorPin = A0; // Analog pin for soil moisture sensor

const int relayPin = 7; // Digital pin connected to the relay module

const int buttonPinA = 5; // Digital pin for button A (Plant A)

const int buttonPinB = 6; // Digital pin for button B (Plant B)


// Plant profiles

struct PlantProfile {

int wetThreshold; // Moisture value above which pump should turn ON

int dryThreshold; // Moisture value below which pump should turn OFF

};


// Define two plant profiles with respective moisture thresholds

PlantProfile plantA = {1000, 500}; // Profile A with high wet threshold

PlantProfile plantB = {850, 600}; // Profile B with moderate thresholds


PlantProfile selectedProfile; // Variable to store currently selected profile

bool profileSelected = false; // Flag to check if a profile has been chosen

bool pumpOn = false; // State of the pump


void setup() {

pinMode(moistureSensorPin, INPUT); // Set sensor pin as input

pinMode(relayPin, OUTPUT); // Set relay pin as output


pinMode(buttonPinA, INPUT_PULLUP); // Set button A pin as input with pull-up resistor

pinMode(buttonPinB, INPUT_PULLUP); // Set button B pin as input with pull-up resistor


digitalWrite(relayPin, LOW); // Ensure pump is OFF at startup

Serial.begin(9600); // Start serial communication


Serial.println("System started.");

Serial.println("Press Button A or B to select plant profile...");

}


void loop() {

if (!profileSelected) { // Wait for user to select a plant profile

waitForProfileSelection();

return;

}


int moistureLevel = analogRead(moistureSensorPin); // Read moisture level from sensor

Serial.print("Soil Moisture Level: ");

Serial.println(moistureLevel);


// If soil is too dry and pump is OFF, turn pump ON

if (moistureLevel < selectedProfile.dryThreshold && !pumpOn) {

Serial.println("Soil is wet. Turning pump OFF.");

digitalWrite(relayPin, LOW);

pumpOn = true;

}

// If soil is wet enough and pump is ON, turn pump OFF

else if (moistureLevel > selectedProfile.wetThreshold && pumpOn) {

Serial.println("Soil is dry. Turning pump ON.");

digitalWrite(relayPin, HIGH);

pumpOn = false;

}


delay(2000); // Wait for 2 seconds before next reading

}


void waitForProfileSelection() {

// Check if Button A is pressed

if (digitalRead(buttonPinA) == LOW) {

delay(50); // Debounce delay

if (digitalRead(buttonPinA) == LOW) {

selectedProfile = plantA;

profileSelected = true;

printSelectedProfile("Plant A");

}

}

// Check if Button B is pressed

else if (digitalRead(buttonPinB) == LOW) {

delay(50); // Debounce delay

if (digitalRead(buttonPinB) == LOW) {

selectedProfile = plantB;

profileSelected = true;

printSelectedProfile("Plant B");

}

}

}


void printSelectedProfile(const char* plantName) {

Serial.print("Selected profile: ");

Serial.println(plantName);

Serial.print(" Dry threshold: ");

Serial.println(selectedProfile.dryThreshold);

Serial.print(" Wet threshold: ");

Serial.println(selectedProfile.wetThreshold);

}


Video of Project

https://mediahub.ku.edu/media/t/1_vwrst5yn