Detects animals entering a farm and scares them off with a buzzer and light.
Built and tested by Drisya K S · Industrial Robotics Institute

A farm protection system that detects cows, goats, dogs, monkeys or wild animals crossing the boundary. An IR or PIR sensor watches the edge of the field; when something is detected, the ESP32 sounds a buzzer, lights an LED and can switch on a siren or floodlight through a relay.
| Component | Qty |
|---|---|
| ESP32 Dev Board | 1 |
| IR or PIR Motion Sensor | 1 |
| Buzzer | 1 |
| LED (optional) | 1 |
| Resistor 220Ω (for LED) | 1 |
| Relay Module (optional, for siren/light) | 1 |
| Jumper Wires | As needed |
| Power Supply (5V / battery) | 1 |
| From | Connect to |
|---|---|
| Sensor VCC | 3.3V |
| Sensor GND | GND |
| Sensor OUT | GPIO 34 |
| Buzzer + | GPIO 25 |
| Buzzer − | GND |
| LED + (via resistor) | GPIO 26 |
| Relay IN | GPIO 27 |
| Relay VCC / GND | 5V / GND |
Complete, tested Arduino C++ code for this project. Copy it into Arduino IDE and upload it to the ESP32.
int sensorPin = 34;
int buzzer = 25;
int led = 26;
int relay = 27;
void setup() {
Serial.begin(115200);
pinMode(sensorPin, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
pinMode(relay, OUTPUT);
Serial.println("Animal Intrusion Detection System Started");
}
void loop() {
int intrusion = digitalRead(sensorPin);
if (intrusion == LOW) { // animal detected
digitalWrite(buzzer, HIGH);
digitalWrite(led, HIGH);
digitalWrite(relay, HIGH);
Serial.println("Animal Detected!");
} else {
digitalWrite(buzzer, LOW);
digitalWrite(led, LOW);
digitalWrite(relay, LOW);
Serial.println("No Intrusion");
}
delay(1000);
}A farm protection system that detects cows, goats, dogs, monkeys or wild animals crossing the boundary. An IR or PIR sensor watches the edge of the field; when something is detected, the ESP32 sounds a buzzer, lights an LED and can switch on a siren or floodlight through a relay.
You need: ESP32 Dev Board (1), IR or PIR Motion Sensor (1), Buzzer (1), LED (optional) (1), Resistor 220Ω (for LED) (1), Relay Module (optional, for siren/light) (1), Jumper Wires, Power Supply (5V / battery) (1). Software: Arduino IDE.
Yes. It is rated beginner and takes about 1–2 hours to build, using the ESP32. The guide on this page explains every connection and step.
The complete, tested Arduino C++ code is free on this page. Copy it into Arduino IDE and upload it to the board.
Yes. IRI sells a kit with the parts for this project (PRJ-133). Message IRI on WhatsApp at +91 86060 82634 for the kit price and delivery details.