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

Arduino UNO Based Soil Moisture Monitoring and Servo Control System

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Soil Moisture Monitoring and Servo Control System

Circuit Documentation

Summary

This circuit integrates an Arduino UNO with a set of sensors and a servo motor to create a system capable of measuring soil moisture and distance to an object. The system uses a soil moisture module and a SparkFun Soil Moisture Sensor to determine the wetness of the soil, and an HC-SR04 Ultrasonic Sensor to measure distance. A servo motor is controlled based on the distance measured. The Arduino UNO serves as the central processing unit, running the embedded code to read sensor data, process it, and control the servo accordingly.

Component List

Arduino UNO

Soil Moisture Module

Servo

HC-SR04 Ultrasonic Sensor

SparkFun Soil Moisture Sensor

Wiring Details

Arduino UNO

Soil Moisture Module

Servo

HC-SR04 Ultrasonic Sensor

SparkFun Soil Moisture Sensor

Documented Code

#include <Servo.h>

Servo servo1;
const int trigPin = 12;
const int echoPin = 11;
long duration;
int distance = 0;
int potPin = A0; // Input pin for Soil Moisture Module
int soil = 0;
int fsoil;

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  servo1.attach(8);
}

void loop() {
  // Reset distance and soil moisture average
  distance = 0;
  fsoil = 0;

  // Take 2 measurements for distance
  for (int i = 0; i < 2; i++) {
    digitalWrite(trigPin, LOW);
    delayMicroseconds(7);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance += duration * 0.034 / 2;
    delay(10);
  }
  distance /= 2;
  Serial.println(distance);

  // If distance is within range, check soil moisture
  if (distance < 15 && distance > 1) {
    delay(1000);
    // Take 3 measurements for soil moisture
    for (int i = 0; i < 3; i++) {
      soil = analogRead(potPin);
      soil = constrain(soil, 485, 1023);
      fsoil += map(soil, 485, 1023, 100, 0);
      delay(75);
    }
    fsoil /= 3;
    Serial.println(fsoil);
    Serial.print("%");

    // Control servo based on soil moisture
    if (fsoil > 3) {
      delay(1000);
      Serial.print("WET ");
      servo1.write(180);
      delay(3000);
    } else {
      delay(1000);
      Serial.print("dry ");
      servo1.write(0);
      delay(3000);
    }

    // Return servo to neutral position
    servo1.write(90);
  }

  // Delay before next loop iteration
  delay(1000);
}

This code is designed to run on the Arduino UNO. It initializes the servo and ultrasonic sensor, then enters a loop where it measures distance and soil moisture. If an object is detected within a certain range, it checks the soil moisture and rotates the servo to a position based on the moisture level. The servo returns to a neutral position after each check.