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

Arduino Uno R3-Based Automated Plant Care System with Ultrasonic Sensing and Inductive Moisture Detection

View and Edit Project In Cirkit DesignerImage of Arduino Uno R3-Based Automated Plant Care System with Ultrasonic Sensing and Inductive Moisture Detection

Circuit Documentation

Summary

This circuit is designed to interface with various sensors and actuators using an Arduino Uno R3 microcontroller. The circuit includes a buzzer for audio alerts, an HC-SR04 ultrasonic sensor for distance measurement, a SparkFun Soil Moisture Sensor for detecting moisture levels, a Tower Pro SG90 servo motor for angular movement, a 28BYJ-48 stepper motor with a ULN2003A driver board for precise rotational movement, an inductive sensor for metal detection, and an IR sensor for object detection. A 7805 voltage regulator is used to step down the voltage from a 12V power supply to 5V required by some of the components.

Component List

Wiring Details

Arduino Uno R3

Buzzer

HC-SR04 Ultrasonic Sensor

SparkFun Soil Moisture Sensor

Tower Pro SG90 Servo

Inductive Sensor

7805 Voltage Regulator

28BYJ-48 Stepper Motor

ULN2003A Breakout Board

IR Sensor

12V Power Supply

Documented Code

// Pin Definitions
#define trigPin 7
#define echoPin 6
#define buzzerPin 12
#define inductiveSensorPin 4
#define rainSensorPin A0
#define servoPin 3
#define stepperPin1 8
#define stepperPin2 9
#define stepperPin3 10
#define stepperPin4 11

#include <Servo.h>
#include <Stepper.h>

// Constants
const int stepsPerRevolution = 2048; // for 28BYJ-48 stepper motor
const int distanceThreshold = 10;    // distance threshold in cm
const int rainThreshold = 500;       // rain sensor threshold (analog value)

// Servo Motor Object
Servo myServo;

// Stepper Motor Object
Stepper myStepper(stepsPerRevolution, stepperPin1, stepperPin3, stepperPin2, stepperPin4);

void setup() {
  // Initialize Serial Monitor
  Serial.begin(9600);
  
  // Initialize Pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(inductiveSensorPin, INPUT);
  pinMode(rainSensorPin, INPUT);

  // Attach Servo to Pin
  myServo.attach(servoPin);
  myServo.write(0); // initial position

  // Set Stepper Motor Speed
  myStepper.setSpeed(10);
}

void loop() {
  // Ultrasonic Sensor Distance Measurement
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) / 29.1;

  // Inductive Sensor Reading
  int inductiveReading = digitalRead(inductiveSensorPin);

  // Rain/Moisture Sensor Reading
  int rainReading = analogRead(rainSensorPin);

  // Ultrasonic Sensor Logic
  if (distance <= distanceThreshold) {
    digitalWrite(buzzerPin, HIGH);
  } else {
    digitalWrite(buzzerPin, LOW);
  }

  // Inductive Sensor Logic
  if (inductiveReading == HIGH) {
    myStepper.step(stepsPerRevolution / 4);  // move 90 degrees
  }

  // Rain/Moisture Sensor Logic
  if (rainReading >= rainThreshold) {
    myServo.write(90);  // move servo to 90 degrees
  } else {
    myServo.write(0);   // move servo to 0 degrees
  }

  delay(100);
}

This code is designed to operate the various components connected to the Arduino Uno R3. It includes initialization of the pins, reading from the sensors, and controlling the buzzer, servo, and stepper motor based on sensor inputs. The ultrasonic sensor measures distance and triggers the buzzer if an object is too close. The inductive sensor, when detecting metal, causes the stepper motor to rotate 90 degrees. The soil moisture sensor's reading is used to control the position of the servo motor.