Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Based Automatic Plant Irrigation System with Rain Detection

View and Edit Project In Cirkit DesignerImage of Arduino-Based Automatic Plant Irrigation System with Rain Detection

Automatic Plant Irrigation System Documentation

Summary

The Automatic Plant Irrigation System is designed to automate the watering process for plants based on soil moisture levels and weather conditions. The system utilizes an Arduino UNO microcontroller to monitor inputs from a rain/snow sensor and a soil moisture sensor. When the soil is dry and there is no rain detected, the system activates a 5V mini water pump through a 1-channel relay to water the plants. The system is powered by a 9V battery.

Component List

Arduino UNO

1-Channel Relay (5V 10A)

Rain/Snow Sensor - Board

SparkFun Soil Moisture Sensor

9V Battery

5V Mini Water Pump

Wiring Details

Arduino UNO

1-Channel Relay (5V 10A)

Rain/Snow Sensor - Board

SparkFun Soil Moisture Sensor

9V Battery

5V Mini Water Pump

Documented Code

/*
 * Automatic Plant Irrigation System
 *
 * This Arduino sketch controls an automatic plant irrigation system. It uses a
 * rain/snow sensor to detect moisture and a soil moisture sensor to monitor the
 * soil's moisture level. If the soil is dry and it is not raining, the system
 * activates a water pump via a relay to water the plants.
 */

// Pin definitions
const int rainSensorPin = 6; // Digital pin connected to rain sensor
const int soilMoisturePin = A0; // Analog pin connected to soil moisture sensor
const int relayPin = 3; // Digital pin connected to relay

// Soil moisture threshold
const int soilMoistureThreshold = 500;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize pin modes
  pinMode(rainSensorPin, INPUT);
  pinMode(soilMoisturePin, INPUT);
  pinMode(relayPin, OUTPUT);

  // Ensure the relay is off initially
  digitalWrite(relayPin, LOW);
}

void loop() {
  // Read the rain sensor value
  int rainSensorValue = digitalRead(rainSensorPin);
  // Read the soil moisture sensor value
  int soilMoistureValue = analogRead(soilMoisturePin);

  // Print sensor values to the serial monitor
  Serial.print("Rain Sensor: ");
  Serial.print(rainSensorValue);
  Serial.print("\tSoil Moisture: ");
  Serial.println(soilMoistureValue);

  // Check if it is not raining and the soil is dry
  if (rainSensorValue == LOW && soilMoistureValue < soilMoistureThreshold) {
    // Turn on the relay to activate the water pump
    digitalWrite(relayPin, HIGH);
  } else {
    // Turn off the relay to deactivate the water pump
    digitalWrite(relayPin, LOW);
  }

  // Wait for a second before the next loop
  delay(1000);
}

This code is responsible for reading the sensor inputs and controlling the relay based on the predefined conditions. The rainSensorPin is set to digital pin 6, which corresponds to the digital output of the rain/snow sensor. The soilMoisturePin is set to analog pin A0, which is connected to the soil moisture sensor. The relayPin is set to digital pin 3, which controls the relay module. The system reads the sensor values, prints them to the serial monitor, and activates the water pump if the conditions are met.