Tech Gyan Set
Published © MIT

AI-Powered Leopard Alert System Using ESP32 & YOLO for Real-

ESP32 aur YOLO AI par based ek smart alert system jo real-time me leopard detect karke turant warning deta hai. ” πŸ†πŸš¨

BeginnerShowcase (no instructions)8 hours24
AI-Powered Leopard Alert System Using ESP32 & YOLO for Real-

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

πŸ”Ή PART-1: AI / YOLO LEOPARD DETECTION (Python Code)

C/C++
pip install ultralytics opencv-python pyserial

βœ… leopard_detection.py

C/C++
import cv2
import serial
import time
from ultralytics import YOLO

# ESP32 Serial Port (change COM port as needed)
esp32 = serial.Serial('COM5', 9600, timeout=1)
time.sleep(2)

# Load trained YOLO model
model = YOLO("best.pt")

# Camera input
cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    if not ret:
        break

    results = model(frame)

    leopard_detected = False

    for r in results:
        for box in r.boxes:
            cls = int(box.cls[0])
            conf = float(box.conf[0])

            if conf > 0.7:   # confidence threshold
                leopard_detected = True

                x1, y1, x2, y2 = map(int, box.xyxy[0])
                cv2.rectangle(frame, (x1,y1), (x2,y2), (0,0,255), 2)
                cv2.putText(frame, "LEOPARD DETECTED",
                            (x1, y1-10),
                            cv2.FONT_HERSHEY_SIMPLEX,
                            0.7, (0,0,255), 2)

    if leopard_detected:
        print("🚨 Leopard Detected!")
        esp32.write(b'1')   # Send alert to ESP32
        time.sleep(5)

    cv2.imshow("Leopard Detection", frame)

    if cv2.waitKey(1) & 0xFF == 27:
        break

cap.release()
cv2.destroyAllWindows()

βœ… esp32_leopard_alert.ino

C/C++
#define BUZZER_PIN 12
#define LED_PIN 13

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);

  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(LED_PIN, LOW);

  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    char data = Serial.read();

    if (data == '1') {
      digitalWrite(BUZZER_PIN, HIGH);
      digitalWrite(LED_PIN, HIGH);

      delay(5000);   // alert duration

      digitalWrite(BUZZER_PIN, LOW);
      digitalWrite(LED_PIN, LOW);
    }
  }
}

πŸ”Ή PART-3: ESP32 + WiFi + Mobile Alert (OPTIONAL)

C/C++
// Pseudo logic
if (leopardDetected) {
   Blynk.notify("🚨 Leopard Detected Near Your Area!");
}

πŸ”Ή PART-4: YOLO DATASET CONFIG (leopard.yaml)

C/C++
path: dataset
train: images/train
val: images/val

nc: 1
names: ['leopard']

Credits

Tech Gyan Set
3 projects β€’ 0 followers
Thanks to Tech Gyan Set .

Comments