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

Arduino UNO and ESP32-CAM Animal Deterrence System with GSM Alerts

View and Edit Project In Cirkit DesignerImage of Arduino UNO and ESP32-CAM Animal Deterrence System with GSM Alerts

Animal Deterrence System Documentation

Summary

The Animal Deterrence System is designed to detect animals using a combination of a PIR sensor and an ultrasonic sensor. When an animal is detected, the system sends an SMS alert via a GSM module and triggers a buzzer alarm. Additionally, an ESP32-CAM captures images of the detected animal. The system is controlled by an Arduino UNO, which interfaces with all the sensors and modules.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. HC-SR04 Ultrasonic Sensor

    • Description: Ultrasonic distance sensor.
    • Pins: VCC, TRIG, ECHO, GND
  3. GSM SIM900

    • Description: GSM module for sending SMS.
    • Pins: A5, A4, A3, A2, A1, A0, 5V, GND, 3.3V, RESET, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, AREF
  4. Buzzer

    • Description: Simple piezoelectric buzzer.
    • Pins: PIN, GND
  5. ESP32-CAM

    • Description: Camera module based on the ESP32.
    • Pins: 5V, GND, IO12, IO13, IO15, IO14, IO2, IO4, VOT, VOR, VCC, IO0, IO16, 3V3
  6. 5V Battery

    • Description: Power source for the circuit.
    • Pins: +, -
  7. PIR/Motion Sensor

    • Description: Passive Infrared sensor for motion detection.
    • Pins: GND, OUTPUT, VCC
  8. Resistor

    • Description: 3.3 Ohms resistor.
    • Pins: pin1, pin2

Wiring Details

Arduino UNO

HC-SR04 Ultrasonic Sensor

GSM SIM900

Buzzer

ESP32-CAM

5V Battery

PIR/Motion Sensor

Resistor

Code Documentation

Arduino UNO Code

/*
 * Animal Deterrence System
 *
 * This system uses an Arduino UNO to interface with a PIR sensor, an ultrasonic
 * sensor, a GSM module, and a buzzer. The ESP32-CAM is used for capturing images.
 * When the PIR sensor or ultrasonic sensor detects an animal, the system sends
 * an SMS alert via the GSM module and triggers the buzzer alarm.
 */

#include <SoftwareSerial.h>

// Pin definitions
const int pirPin = 2; // PIR sensor output
const int trigPin = 3; // Ultrasonic sensor TRIG
const int echoPin = 4; // Ultrasonic sensor ECHO
const int buzzerPin = 5; // Buzzer
const int gsmRxPin = 10; // GSM module RX
const int gsmTxPin = 11; // GSM module TX

// Variables
long duration;
int distance;
SoftwareSerial gsm(gsmRxPin, gsmTxPin); // RX, TX

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

  // Initialize pins
  pinMode(pirPin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzerPin, OUTPUT);

  // Initialize GSM module
  sendSMS("System Initialized");
}

void loop() {
  // Check PIR sensor
  if (digitalRead(pirPin) == HIGH) {
    triggerAlarm();
    sendSMS("Animal Detected by PIR Sensor");
  }

  // Check Ultrasonic sensor
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;

  if (distance < 50) { // If an object is detected within 50 cm
    triggerAlarm();
    sendSMS("Animal Detected by Ultrasonic Sensor");
  }

  delay(1000); // Wait for a second before next loop
}

void triggerAlarm() {
  digitalWrite(buzzerPin, HIGH);
  delay(1000); // Buzzer on for 1 second
  digitalWrite(buzzerPin, LOW);
}

void sendSMS(String message) {
  gsm.println("AT+CMGF=1"); // Set SMS to text mode
  delay(100);
  gsm.println("AT+CMGS=\"+7448350027\""); // Replace with your phone number
  delay(100);
  gsm.println(message);
  delay(100);
  gsm.write(26); // ASCII code for CTRL+Z
  delay(1000);
}

GSM SIM900 Code

/*
 * Animal Deterrence System
 *
 * This system uses an Arduino UNO to interface with a PIR sensor, an ultrasonic
 * sensor, a GSM module, and a buzzer. The ESP32-CAM is used for capturing images.
 * When the PIR sensor or ultrasonic sensor detects an animal, the system sends
 * an SMS alert via the GSM module and triggers the buzzer alarm.
 */

#include <SoftwareSerial.h>

// Pin definitions
const int pirPin = 2; // PIR sensor output
const int trigPin = 3; // Ultrasonic sensor TRIG
const int echoPin = 4; // Ultrasonic sensor ECHO
const int buzzerPin = 5; // Buzzer
const int gsmRxPin = 10; // GSM module RX
const int gsmTxPin = 11; // GSM module TX

// Variables
long duration;
int distance;
SoftwareSerial gsm(gsmRxPin, gsmTxPin); // RX, TX

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

  // Initialize pins
  pinMode(pirPin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzerPin, OUTPUT);

  // Initialize GSM module
  sendSMS("System Initialized");
}

void loop() {
  // Check PIR sensor
  if (digitalRead(pirPin) == HIGH) {
    triggerAlarm();
    sendSMS("Animal Detected by PIR Sensor");
  }

  // Check Ultrasonic sensor
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(tr