Arduino Lesson 10: The Automated Plant Watering System – Make Your Plants Happy!

In this lesson, we’ll learn how to build a system that automatically waters plants using a moisture sensor, a relay, and Arduino. Get ready to become a plant-loving tech wizard!

Objective: Learn how to use Arduino and a moisture sensor to automatically water plants.

Materials:

  • Arduino Uno board
  • Breadboard
  • Moisture sensor
  • Relay module
  • Water pump (12V)
  • Jumper wires
  • 12V power supply
  • Plant pot with soil and plant

Steps:

  1. Review: Recap previous lessons and components, including sensors, relays, and motor control.
  2. Meet the Components: Introduce the moisture sensor, relay module, and water pump. Explain how they work together.
  3. Building the Circuit: Connect the moisture sensor, relay, water pump, Arduino board, and power supply to the breadboard. Ensure the relay is connected to the water pump and the moisture sensor to an analog input pin on the Arduino.

Step 1: Connecting the Moisture Sensor

  1. Find the two legs of the moisture sensor: One is usually for the signal (often marked “S”) and the other is for ground (often marked “G”).
  2. Connect the signal leg of the moisture sensor to an analog input pin on the Arduino: We’ll use pin A0.
  3. Connect the ground leg of the moisture sensor to a ground rail on the breadboard:

Step 2: Connecting the Relay

  1. Find the pins on the relay module: It usually has pins for power (VCC, GND), control (IN), and output (NO, NC, COM).
  2. Connect the relay’s VCC pin to the 12V power supply’s positive terminal:
  3. Connect the relay’s GND pin to the 12V power supply’s negative terminal:
  4. Connect the relay’s control pin (IN) to a digital output pin on the Arduino: We’ll use pin 9.
  5. Connect the relay’s output pins (NO and COM) to the water pump: Connect the NO pin to the water pump’s positive terminal and the COM pin to the water pump’s negative terminal.

Step 3: Connecting the Water Pump

  1. Find the two wires on the water pump: One is positive (+) and the other is negative (-).
  2. Connect the positive wire of the water pump to the relay’s NO pin:
  3. Connect the negative wire of the water pump to the relay’s COM pin:

Step 4: Programming the Arduino

  1. Open the Arduino IDE.
  2. Copy and paste the following code:
const int relayPin = 9; // Relay connected to pin 9
const int moisturePin = A0; // Moisture sensor connected to analog pin A0

int moistureThreshold = 500; // Adjust this value to control moisture level

void setup() {
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW); // Turn off the relay (pump)
}

void loop() {
  int moistureValue = analogRead(moisturePin); 

  if (moistureValue < moistureThreshold) { // If soil is dry
    digitalWrite(relayPin, HIGH); // Turn on the relay (pump)
    delay(3000); // Water for 3 seconds
    digitalWrite(relayPin, LOW); // Turn off the relay (pump)
  }

  delay(1000); // Check moisture every 1 second
}
  1. Upload the code to the Arduino board.

Step 5: Test the Watering System

  1. Place the moisture sensor in the soil near the plant’s roots:
  2. Observe the pump: You should see the pump turn on when the soil is dry and turn off when it’s moist.
  3. Adjust the moisture threshold: Change the moistureThreshold value in the code to fine-tune how dry the soil needs to be before the pump turns on.

Congratulations! You’ve built an automated plant watering system!

Let’s Experiment:

  • Try different plants: Experiment with watering different types of plants.
  • Add a timer: Use a timer to control the watering duration or schedule.
  • Monitor the water level: Use a water level sensor to prevent overwatering.

Keep experimenting with sensors, motors, and have fun with Arduino!