Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Controlled Automated Irrigation System with Humidity Sensing

Image of Arduino-Controlled Automated Irrigation System with Humidity Sensing

Circuit Documentation

Summary

This circuit is designed to control a plastic solenoid valve and a 5V mini water pump based on readings from a YL-69 humidity sensor. The system operates by checking the soil moisture level every 24 hours and activates the valve and pump if the moisture level exceeds a specified threshold. The Arduino UNO serves as the central controller, reading the sensor data and managing the power to the pump and valve accordingly.

Component List

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Purpose: Acts as the central control unit for reading sensor data and controlling the valve and pump.

Humidity Sensor (YL-69)

  • Description: A soil moisture sensor that provides both digital and analog outputs.
  • Purpose: Measures the soil moisture level to determine if watering is needed.

5V Mini Water Pump

  • Description: A small pump that operates at 5 volts.
  • Purpose: Pumps water to the soil when activated by the Arduino.

Plastic Solenoid Valve

  • Description: An electrically controlled valve for controlling the flow of water.
  • Purpose: Opens to allow water flow and closes to stop water flow as controlled by the Arduino.

Wiring Details

Arduino UNO

  • 5V: Provides power to the YL-69 humidity sensor.
  • A0: Receives the analog signal from the YL-69 humidity sensor.
  • GND: Common ground for the Arduino, YL-69 sensor, 5V mini water pump, and plastic solenoid valve.
  • D10: Controls the plastic solenoid valve.
  • D9: Controls the 5V mini water pump.
  • D2: Receives the digital signal from the YL-69 humidity sensor.

Humidity Sensor (YL-69)

  • VCC: Connected to the 5V output from the Arduino UNO.
  • A0: Analog output connected to the A0 pin on the Arduino UNO.
  • GND: Ground connected to the common ground on the Arduino UNO.
  • D0: Digital output connected to the D2 pin on the Arduino UNO.

5V Mini Water Pump

  • Positive Pin: Connected to the D9 pin on the Arduino UNO.
  • Negative Pin: Connected to the common ground on the Arduino UNO.

Plastic Solenoid Valve

  • Pin1: Connected to the D10 pin on the Arduino UNO.
  • Pin2: Connected to the common ground on the Arduino UNO.

Documented Code

/*
* This Arduino sketch controls a valve and a water pump based on
* readings from a humidity sensor. The valve and water pump are activated
* when the analog value from the humidity sensor exceeds a specified threshold. The
* system checks the moisture level every 24 hours and activates the valve
* and water pump accordingly.
*/

// Declaration of constants and pins
const int humidityDigitalPin = 2; // Digital output from the humidity sensor
const int humidityAnalogPin = A0; // Analog output from the humidity sensor
const int valvePin = 10;          // Control pin for the valve
const int pumpPin = 9;            // Control pin for the pump
const int threshold = 600;        // Moisture threshold (0-1023), adjust based on soil

unsigned long wateringInterval = 86400000UL;  // Watering interval: 24 hours (in ms)
unsigned long wateringDuration = 60000UL;     // Pump and valve activation duration: 1 minute (in ms)
unsigned long previousMillis = 0;             // Time of the last measurement
unsigned long pumpStartMillis = 0;            // Pump start time

bool isWatering = false;  // Indicates whether watering is in progress

void setup() {
  pinMode(valvePin, OUTPUT);  // Set the valve pin as an output
  pinMode(pumpPin, OUTPUT);   // Set the pump pin as an output
  pinMode(humidityDigitalPin, INPUT); // Set the digital sensor pin
  pinMode(humidityAnalogPin, INPUT);  // Set the analog sensor pin

  digitalWrite(valvePin, LOW);  // Valve closed by default
  digitalWrite(pumpPin, LOW);   // Pump off by default

  Serial.begin(9600);  // For displaying information on the serial monitor
}

void loop() {
  unsigned long currentMillis = millis();  // Get the current time

  // Check every 24 hours
  if (currentMillis - previousMillis >= wateringInterval) {
    previousMillis = currentMillis;  // Update the time of the last measurement

    int soilMoistureValue = analogRead(humidityAnalogPin);  // Read the soil moisture
    Serial.print("Soil Moisture: ");
    Serial.println(soilMoistureValue);

    if (soilMoistureValue > threshold) {
      // Moisture is above the threshold, start watering
      Serial.println("Low moisture, activating pump and valve!");
      digitalWrite(valvePin, HIGH);   // Open the valve
      digitalWrite(pumpPin, HIGH);    // Activate the pump
      isWatering = true;              // Mark that watering has started
      pumpStartMillis = currentMillis;  // Record the pump start time
    }
  }

  // Check if watering is in progress and needs to stop
  if (isWatering) {
    if (currentMillis - pumpStartMillis >= wateringDuration) {
      // Watering duration is over
      Serial.println("Watering complete, stopping pump and valve.");
      digitalWrite(valvePin, LOW);  // Close the valve
      digitalWrite(pumpPin, LOW);   // Turn off the pump
      isWatering = false;           // Watering is finished
    }
  }

  // You can perform other tasks here while watering is paused
  // For example, you can check other sensors, manage an LCD display, etc.
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the humidity sensor, water pump, and solenoid valve, and sets up a serial communication for debugging purposes. The main loop checks the soil moisture level every 24 hours and activates the water pump and valve for a minute if the soil is too dry.