Arduino UNO and ESP32-CAM Animal Deterrence System with GSM Alerts
View and Edit Project In Cirkit Designer
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
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
HC-SR04 Ultrasonic Sensor
- Description: Ultrasonic distance sensor.
- Pins: VCC, TRIG, ECHO, GND
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
Buzzer
- Description: Simple piezoelectric buzzer.
- Pins: PIN, GND
ESP32-CAM
- Description: Camera module based on the ESP32.
- Pins: 5V, GND, IO12, IO13, IO15, IO14, IO2, IO4, VOT, VOR, VCC, IO0, IO16, 3V3
5V Battery
- Description: Power source for the circuit.
- Pins: +, -
PIR/Motion Sensor
- Description: Passive Infrared sensor for motion detection.
- Pins: GND, OUTPUT, VCC
Resistor
- Description: 3.3 Ohms resistor.
- Pins: pin1, pin2
Wiring Details
Arduino UNO
- 5V: Connected to VCC of PIR/Motion Sensor, GSM SIM900, and HC-SR04 Ultrasonic Sensor.
- GND: Connected to GND of PIR/Motion Sensor, GSM SIM900, Buzzer, HC-SR04 Ultrasonic Sensor, 5V Battery, and ESP32-CAM.
- D11: Connected to D1 of GSM SIM900.
- D10: Connected to D0 of GSM SIM900 and pin1 of Resistor.
- D5: Connected to PIN of Buzzer.
- D4: Connected to ECHO of HC-SR04 Ultrasonic Sensor.
- D3: Connected to TRIG of HC-SR04 Ultrasonic Sensor.
- D2: Connected to OUTPUT of PIR/Motion Sensor.
HC-SR04 Ultrasonic Sensor
- VCC: Connected to 5V of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
- TRIG: Connected to D3 of Arduino UNO.
- ECHO: Connected to D4 of Arduino UNO.
GSM SIM900
- 5V: Connected to 5V of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
- D1: Connected to D11 of Arduino UNO.
- D0: Connected to D10 of Arduino UNO and pin1 of Resistor.
Buzzer
- PIN: Connected to D5 of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
ESP32-CAM
- 5V: Connected to + of 5V Battery.
- GND: Connected to GND of Arduino UNO.
- IO13: Connected to D1 of GSM SIM900.
- IO12: Connected to pin2 of Resistor.
5V Battery
- +: Connected to 5V of ESP32-CAM.
- -: Connected to GND of Arduino UNO.
PIR/Motion Sensor
- VCC: Connected to 5V of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
- OUTPUT: Connected to D2 of Arduino UNO.
Resistor
- pin1: Connected to D10 of Arduino UNO and D0 of GSM SIM900.
- pin2: Connected to IO12 of ESP32-CAM.
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