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

Arduino-Controlled Automated Plant Watering System with Soil Moisture Sensing and Daylight-Activated Stepper Motor

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Automated Plant Watering System with Soil Moisture Sensing and Daylight-Activated Stepper Motor

Circuit Documentation

Summary

The circuit is designed to monitor and control a plant watering system. It includes sensors for soil moisture and water level, a light-dependent resistor (LDR) for detecting daylight, a relay-controlled water pump, a stepper motor for mechanical movement, and LEDs to indicate water levels. An Arduino UNO microcontroller serves as the central processing unit, interfacing with the sensors, controlling the water pump via a relay, driving the stepper motor through a ULN2003A breakout board, and lighting up LEDs based on water level status.

Component List

Soil Moisture Sensor

Arduino UNO

1-Channel Relay (5V 10A)

5V Mini Water Pump

Water Level Sensor

28BYJ-48 Stepper Motor

ULN2003A Breakout Board

Resistor (220 Ohms)

LED: Two Pin (Green, Yellow, Red)

Photocell (LDR)

Battery AAx4 6V

Wiring Details

Soil Moisture Sensor

Arduino UNO

1-Channel Relay (5V 10A)

5V Mini Water Pump

Water Level Sensor

28BYJ-48 Stepper Motor

ULN2003A Breakout Board

Resistor (220 Ohms)

LED: Two Pin (Green, Yellow, Red)

Photocell (LDR)

Battery AAx4 6V

Documented Code

// Define the pin connections
const int soilMoisturePin = A0;  // Soil moisture sensor connected to A0
const int waterPumpPin = 7;      // Relay to control water pump
const int waterLevelPin = A1;    // Water level sensor connected to A1
const int ldrPin = A2;           // LDR connected to A2
const int greenLEDPin = 4;       // Green LED for full water level
const int yellowLEDPin = 3;      // Yellow LED for half water level
const int redLEDPin = 2;         // Red LED for empty water level
const int motorPin1 = 8;         // Stepper motor driver IN1
const int motorPin2 = 9;         // Stepper motor driver IN2
const int motorPin3 = 10;        // Stepper motor driver IN3
const int motorPin4 = 11;        // Stepper motor driver IN4

unsigned long previousMillis = 0; // Store the last time the motor was updated
const int stepDelay = 5;          // Delay between steps for the motor
int stepCount = 0;                // Track steps for the motor
bool motorActive = false;         // Track motor state

void setup() {
  // Initialize the pins
  pinMode(soilMoisturePin, INPUT);
  pinMode(waterLevelPin, INPUT);
  pinMode(ldrPin, INPUT);
  pinMode(waterPumpPin, OUTPUT);  // Control relay to turn the pump on/off
  pinMode(greenLEDPin, OUTPUT);
  pinMode(yellowLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  
  // Initialize motor pins
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);

  Serial.begin(9600);  // Initialize serial communication for debugging
  Serial.println("Setup complete.");
}

void loop() {
  // Soil moisture sensor reading
  int soilMoistureValue = analogRead(soilMoisturePin);
  Serial.print("Soil moisture value: ");
  Serial.println(soilMoistureValue);

  // Control water pump based on soil moisture
  if (soilMoistureValue > 750) {  // Dry condition
    digitalWrite(waterPumpPin, LOW);  // Turn on the water pump (relay activates)
    Serial.println("Water pump ON.");
  } else {
    digitalWrite(waterPumpPin, HIGH);   // Turn off the water pump
    Serial.println("Water pump OFF.");
  }

  // Water level sensor reading
  int waterLevelValue = analogRead(waterLevelPin);
  Serial.print("Water level value: ");
  Serial.println(waterLevelValue);

  // Water level indication using LEDs
  if (waterLevelValue > 342) {
    // Full water level
    digitalWrite(greenLEDPin, HIGH);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(redLEDPin, LOW);
    Serial.println("Water level: FULL (Green LED ON).");
  } else if (waterLevelValue > 195) {
    // Half water level
    digitalWrite(greenLEDPin, LOW);
    digitalWrite(yellowLEDPin, HIGH);
    digitalWrite(redLEDPin, LOW);
    Serial.println("Water level: HALF (Yellow LED ON).");
  } else {
    // Low or empty water level
    digitalWrite(greenLEDPin, LOW);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(redLEDPin, HIGH);
    Serial.println("Water level: LOW/EMPTY (Red LED ON).");
  }

  // LDR (light sensor) reading
  int ldrValue = analogRead(ldrPin);
  Serial.print("LDR value: ");
  Serial.println(ldrValue);

  // Control the stepper motor based on daylight (when LDR detects enough light)
  if (ldrValue > 600) {
    // Start the motor if it's not already running
    if (!motorActive) {
      Serial.println("Daylight detected. Starting motor.");
      motorActive = true; // Set motor to active