This document provides a detailed overview of a drone surveillance system. The system includes multiple brushless motors controlled by Electronic Speed Controllers (ESCs), an MPU-6050 for motion sensing, a GPS module for location tracking, and an ESP32 microcontroller for overall control. Additionally, an ESP32-CAM is used for capturing images, and a PDB XT60 is used for power distribution. The system is powered by a LiPo battery.
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <TinyGPS++.h>
#include <HardwareSerial.h>
// Define pins for HC-SR04
const int trigPin = 12; // Change this to your trig pin
const int echoPin = 13; // Change this to your echo pin
// Define pins for MPU6050
Adafruit_MPU6050 mpu;
// Define pins for GPS
HardwareSerial mySerial(1); // Use UART1 for GPS
TinyGPSPlus gps;
void setup() {
// Start serial communication
Serial.begin(115200);
// Initialize HC-SR04
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// Initialize MPU6050
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
// Initialize GPS
mySerial.begin(9600, SERIAL_8N1, 16, 17); // Adjust RX, TX pins for GPS
}
void loop() {
// HC-SR04 Distance Measurement
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
float distance = (duration * 0.034) / 2; // Calculate distance in cm
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Read from MPU6050
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
Serial.print("Accel X: "); Serial.print(a.acceleration.x); Serial.print(" m/s^2");
Serial.print(" | Accel Y: "); Serial.print(a.acceleration.y); Serial.print(" m/s^2");
Serial.print(" | Accel Z: "); Serial.print(a.acceleration.z); Serial.print(" m/s^2");
Serial.println();
// Read from GPS
while (mySerial.available() > 0) {
gps.encode(mySerial.read());
if (gps.location.isUpdated()) {
Serial.print("Latitude= "); Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= "); Serial.print(gps.location.lng(), 6);
Serial.println();
}
}
delay(1000); // Delay for readability
}
/*
* Development of Drone Surveillance Technology Using ESP32
* This code interfaces with an ESP32, MPU-6050, GPS NEO 6M, and ESP32-CAM.
* The ESP32 reads data from the MPU-6050 (IMU), and GPS.
* It also controls the ESCs for the brushless motors and captures images using the ESP32-CAM.
*/
#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <WiFi.h>
#include <ESP32Servo.h>
// Pin Definitions