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

Arduino UNO-Based Smart Irrigation and Animal Deterrent System

Image of Arduino UNO-Based Smart Irrigation and Animal Deterrent System

Circuit Documentation

Summary

This circuit is designed to monitor and respond to environmental conditions using a variety of sensors and actuators. It includes an Arduino UNO as the central microcontroller, which processes inputs from an IR sensor, a soil moisture sensor, an ultrasonic sensor, and a DHT11 temperature and humidity sensor. The circuit can activate a relay to control a water pump and a buzzer for alerts. The system is powered by a 9V battery and is capable of detecting soil moisture levels, presence of objects or animals via IR and ultrasonic sensors, and can measure temperature and humidity.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P
  • Used as the main processing unit for the circuit

IR Sensor

  • Infrared sensor for object detection
  • Outputs a digital signal when an object is detected

SparkFun Soil Moisture Sensor

  • Measures the volumetric content of water in soil
  • Outputs an analog signal proportional to the moisture level

HC-SR04 Ultrasonic Sensor

  • Measures distance to objects using ultrasonic waves
  • Provides precise, non-contact distance measurements

DHT11

  • Digital temperature and humidity sensor
  • Provides digital readings of ambient temperature and humidity

1-Channel Relay (5V 10A)

  • Electromechanical switch controlled by a digital signal
  • Used to control high power devices like the water pump

5V Mini Water Pump

  • Submersible pump for water circulation
  • Controlled by the relay to water plants based on soil moisture

Buzzer

  • Emits an audible alert when activated
  • Used for notifications or alarms

9V Battery

  • Provides power to the circuit

Wiring Details

Arduino UNO

  • 5V: Powers the IR sensor, soil moisture sensor, ultrasonic sensor, DHT11, and relay
  • GND: Common ground for all components
  • A0: Receives analog input from the soil moisture sensor
  • D2: Digital input from the DHT11 sensor
  • D3: Digital output to the ultrasonic sensor's TRIG pin
  • D4: Digital input from the ultrasonic sensor's ECHO pin
  • D5: Digital input from the IR sensor
  • D6: Digital output to the buzzer
  • D8: Digital output to control the relay

IR Sensor

  • VCC: Connected to 5V from Arduino
  • GND: Connected to GND on Arduino
  • OUT: Digital output to D5 on Arduino

SparkFun Soil Moisture Sensor

  • VCC: Connected to 5V from Arduino
  • GND: Connected to GND on Arduino
  • SIG: Analog output to A0 on Arduino

HC-SR04 Ultrasonic Sensor

  • VCC: Connected to 5V from Arduino
  • TRIG: Digital output from D3 on Arduino
  • ECHO: Digital input to D4 on Arduino
  • GND: Connected to GND on Arduino

DHT11

  • VCC: Connected to 5V from Arduino
  • GND: Connected to GND on Arduino
  • DATA: Digital output to D2 on Arduino

1-Channel Relay (5V 10A)

  • Power: Connected to 5V from Arduino
  • Ground: Connected to GND on Arduino
  • Signal: Controlled by D8 on Arduino
  • C: Connected to the positive terminal of the 9V battery
  • NO: Normally open contact connected to the positive pin of the water pump

5V Mini Water Pump

  • Positive Pin: Connected to the NO contact on the relay
  • Negative Pin: Connected to the negative terminal of the 9V battery

Buzzer

  • PIN: Controlled by D6 on Arduino
  • GND: Connected to GND on Arduino

9V Battery

  • +: Connected to the C contact on the relay and the positive pin of the water pump
  • -: Connected to the negative pin of the water pump

Documented Code

#include <DHT.h>

// Define pins for DHT sensor
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

// Define pins for soil moisture sensor and relay
const int soilMoisturePin = A0;
const int relayPin = 8;

// Define pins for ultrasonic sensor and IR sensor
#define TRIG_PIN 3
#define ECHO_PIN 4
#define IR_SENSOR_PIN 5
#define BUZZER_PIN 6

// Define threshold values
const int moistureThreshold = 30;
const int maxMoistureValue = 1023;

// Variables for ultrasonic sensor
long duration;
int distance;

// Variables for IR sensor
bool irDetected = false;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize DHT sensor
  dht.begin();

  // Set pin modes
  pinMode(relayPin, OUTPUT);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(IR_SENSOR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  // Ensure the pump and buzzer are off initially
  digitalWrite(relayPin, LOW);
  digitalWrite(BUZZER_PIN, LOW);
}

void loop() {
  // Delay for reading sensors
  delay(2000);

  // Read DHT sensor
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  // Check if DHT readings are valid
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor!");
  } else {
    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" *C");
  }

  // Read soil moisture value
  int sensorValue = analogRead(soilMoisturePin);
  int moisturePercentage = map(sensorValue, 0, maxMoistureValue, 100, 0);

  // Print the moisture percentage to the serial monitor for debugging
  Serial.print("Soil Moisture: ");
  Serial.print(moisturePercentage);
  Serial.println("%");

  // Check if soil moisture is below the threshold
  if (moisturePercentage > moistureThreshold) {
    digitalWrite(relayPin, HIGH); // Turn on the pump
    Serial.println("Pump ON");
  } else {
    digitalWrite(relayPin, LOW); // Turn off the pump
    Serial.println("Pump OFF");
  }

  // Measure distance from the ultrasonic sensor
  distance = measureDistance(TRIG_PIN, ECHO_PIN);

  // Read IR sensor value
  irDetected = digitalRead(IR_SENSOR_PIN) == LOW; // Assuming LOW means detection

  // Check if an animal is detected (adjust distance threshold as needed)
  if (distance < 100 || irDetected) {
    activateBuzzer();
    Serial.println("Animal Detected!");
  } else {
    deactivateBuzzer();
  }

  // Small delay to prevent too much serial output
  delay(200);
}

int measureDistance(int trigPin, int echoPin) {
  // Send a pulse to trigger the ultrasonic sensor
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Measure the duration of the echo pulse
  long duration = pulseIn(echoPin, HIGH);
  
  // Calculate the distance in cm
  int distance = duration * 0.034 / 2;
  return distance;
}

void activateBuzzer() {
  digitalWrite(BUZZER_PIN, HIGH);
}

void deactivateBuzzer() {
  digitalWrite(BUZZER_PIN, LOW);
}

This code is designed to run on the Arduino UNO and manages the various sensors and actuators in the circuit. It reads environmental data, controls a water pump based on soil moisture, and activates a buzzer if an animal is detected or if an object is too close to the ultrasonic sensor. The code includes functions for reading sensors, controlling the relay, and managing the buzzer.