Arduino Uno R3-Based Automated Plant Care System with Ultrasonic Sensing and Inductive Moisture Detection
View and Edit Project In Cirkit Designer
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
- Arduino Uno R3: A microcontroller board based on the ATmega328P, with a variety of digital and analog I/O pins.
- Buzzer: An audio signaling device.
- HC-SR04 Ultrasonic Sensor: A sensor for measuring distances using ultrasonic waves.
- SparkFun Soil Moisture Sensor: A sensor for detecting the moisture content in soil.
- Tower Pro SG90 Servo: A small and lightweight servo motor for angular movement.
- Inductive Sensor: A sensor for detecting metallic objects.
- 7805 Voltage Regulator: A voltage regulator that outputs a stable 5V from a higher voltage input.
- 28BYJ-48 Stepper Motor: A small stepper motor for precise rotational movement.
- ULN2003A Breakout Board: A driver board for controlling stepper motors like the 28BYJ-48.
- IR Sensor: A sensor for detecting obstacles and measuring distances using infrared light.
- 12V Power Supply: A power source for the circuit.
Wiring Details
Arduino Uno R3
- Power Jack: Connected to the 12V power supply.
- 5V: Powers the HC-SR04 Ultrasonic Sensor, SparkFun Soil Moisture Sensor, Tower Pro SG90 servo, and IR sensor.
- GND: Common ground for the Tower Pro SG90 servo, SparkFun Soil Moisture Sensor, HC-SR04 Ultrasonic Sensor, IR sensor, and buzzer.
- A0: Connected to the SparkFun Soil Moisture Sensor.
- Pins 2-13: Various I/O connections to the sensors and actuators.
Buzzer
- PIN: Connected to pin 12 of the Arduino Uno R3.
- GND: Connected to the common ground.
HC-SR04 Ultrasonic Sensor
- VCC: Powered by the 5V output from the Arduino Uno R3.
- TRIG: Connected to pin 7 of the Arduino Uno R3.
- ECHO: Connected to pin 6 of the Arduino Uno R3.
- GND: Connected to the common ground.
SparkFun Soil Moisture Sensor
- VCC: Powered by the 5V output from the Arduino Uno R3.
- GND: Connected to the common ground.
- SIG: Connected to the A0 pin of the Arduino Uno R3.
Tower Pro SG90 Servo
- Signal: Connected to pin 3 of the Arduino Uno R3.
- +5V: Powered by the 5V output from the Arduino Uno R3.
- GND: Connected to the common ground.
Inductive Sensor
- Signal: Connected to pin 4 of the Arduino Uno R3.
- VCC: Powered by the 5V output from the Arduino Uno R3.
- GND: Connected to the common ground.
7805 Voltage Regulator
- INPUT: Connected to the +12V from the power supply.
- OUTPUT: Provides +5V to the ULN2003A breakout board.
- GND: Connected to the common ground.
28BYJ-48 Stepper Motor
- Connected to the ULN2003A breakout board using the color-coded wires.
ULN2003A Breakout Board
- In 1-4: Controlled by pins 8-11 of the Arduino Uno R3.
- +5V: Powered by the 5V output from the 7805 voltage regulator.
- 0V: Connected to the common ground.
IR Sensor
- out: Connected to pin 13 of the Arduino Uno R3.
- vcc: Powered by the 5V output from the Arduino Uno R3.
- gnd: Connected to the common ground.
12V Power Supply
- +: Provides power to the 7805 voltage regulator and the Arduino Uno R3.
- -: Connected to the common ground.
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.