Autonomous Smart Military Defense System
by tushar _electronics in Circuits > Arduino
40 Views, 0 Favorites, 0 Comments
Autonomous Smart Military Defense System
The Smart Military Defense System is an autonomous security solution designed to protect borders and restricted military zones without risking human lives. In modern warfare and surveillance, manual patrolling faces challenges like blind spots and delayed response times. This project addresses those challenges by deploying an automated system that monitors a dedicated area using advanced sensors.
When an unauthorized movement or threat is detected within the range, the system instantly triggers an alert mechanism. It simultaneously activates a defensive tracking setup (like a servo-guided laser or automated turret placeholder) to point towards the intruder, simulating an immediate tactical counter-measure. This project is ideal for students, hobbyists, and tech enthusiasts looking to understand modern robotics, sensor integration, and defense automation.
Supplies
The following components and tools are required to build this Smart Military Defense System:
Microcontrollers & Boards:
- Arduino Uno (or any compatible microcontroller) x 1
- Breadboard (Full size or mini) x 1
Sensors & Input Modules:
- PIR Motion Sensor (To detect human movement) x 1
- Ultrasonic Sensor HC-SR04 (To measure enemy distance) x 1
Actuators & Indicators:
- Servo Motor SG90 (For automated turret movement) x 2
- 5V Laser Diode (Simulating the defense weapon) x 1
- Active Buzzer (For immediate security alarm) x 1
- LED Lights (Red and Green for system status) x 2
Power & Connectivity:
- 9V Battery or 5V Power Adapter x 1
- Jumper Wires (Male-to-Male & Male-to-Female) x As required
Software & Tools:
- Arduino IDE (To upload the source code)
- Hot Glue Gun & Soldering Iron (For physical assembly)
Circuit Connections and Wiring Diagram
In this step, we will connect all the electronic components to the microcontroller. The PIR motion sensor and Ultrasonic sensor act as the input eyes of our defense system, while the servo motor, buzzer, and laser diode act as the defensive outputs.
Follow these connection guidelines carefully:
- Connect the PIR Sensor VCC to 5V, GND to GND, and Out to Digital Pin 2.
- Connect the Ultrasonic Sensor VCC to 5V, Trig to Pin 3, Echo to Pin 4, and GND to GND.
- Connect the Servo Motor Signal to Pin 9, VCC to 5V, and GND to GND.
- Connect the Laser/Buzzer positive terminal to Pin 13 and negative to GND.
Ensure all connections are secure on the breadboard before powering up the system to avoid any short circuits.
Project Demo and Working Video
Here is the live demonstration of the Smart Military Defense System in action. The video showcases how the system automatically tracks movements and triggers the alarm system when an intruder breaches the secured border line.
Downloads
Source Code and Logic Implementation
With the hardware connections successfully configured, we now implement the core intelligence of our Smart Military Defense System using the ESP32. This system leverages advanced programming logic to handle real-time automated tracking, status updates on dual displays (OLED and LCD), and multi-tier hazard alerts across two separate sectors.
Below is the complete ESP32 source code for the project. Copy this code, paste it into your Arduino IDE (with ESP32 board support) or your Wokwi simulator, and upload it to your board.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_NeoPixel.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define PIR_PIN 13
#define TRIG_PIN 12
#define ECHO_PIN 14
#define BUZZER_A 25
#define NEO_A 26
#define BUZZER_B 33
#define NEO_B 27
#define NUM_LEDS 16
Adafruit_NeoPixel ringA(NUM_LEDS, NEO_A, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ringB(NUM_LEDS, NEO_B, NEO_GRB + NEO_KHZ800);
int virtualDistance = 180;
bool enemyApproaching = true;
unsigned long prevAutoMillis = 0;
const long enemySpeedInterval = 250;
unsigned long prevBuzzerMillis = 0;
bool buzzerToggle = false;
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
ledcAttach(BUZZER_A, 1200, 8);
ledcAttach(BUZZER_B, 1200, 8);
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println("OLED Link Error"); }
lcd.init();
lcd.backlight();
ringA.begin(); ringA.show();
ringB.begin(); ringB.show();
lcd.setCursor(0, 0); lcd.print("GRID INITIALIZED");
lcd.setCursor(0, 1); lcd.print("RADAR VISUAL OK ");
delay(1500);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - prevAutoMillis >= enemySpeedInterval) {
prevAutoMillis = currentMillis;
if (enemyApproaching) {
virtualDistance -= 5;
if (virtualDistance <= 15) enemyApproaching = false;
} else {
virtualDistance += 5;
if (virtualDistance >= 180) enemyApproaching = true;
}
}
oled.clearDisplay();
drawFuturisticRadarUI(virtualDistance);
setRingColor(ringA, 0, 255, 0);
setRingColor(ringB, 0, 255, 0);
if (virtualDistance < 150) {
if (virtualDistance > 80 && virtualDistance <= 150) {
ledcWrite(BUZZER_B, 0);
setRingColor(ringA, 255, 100, 0);
lcd.setCursor(0, 0); lcd.print("ALERT: SECTOR A ");
lcd.setCursor(0, 1); lcd.print("ENEMY: " + String(virtualDistance) + "cm ");
if (currentMillis - prevBuzzerMillis >= 250) {
prevBuzzerMillis = currentMillis;
buzzerToggle = !buzzerToggle;
}
if(buzzerToggle) {
ledcWrite(BUZZER_A, 128);
} else {
ledcWrite(BUZZER_A, 0);
}
}
else if (virtualDistance <= 80) {
setRingColor(ringA, 255, 0, 0);
setRingColor(ringB, 255, 0, 0);
lcd.setCursor(0, 0); lcd.print("🚨 BREACH: ZONE B");
lcd.setCursor(0, 1); lcd.print("CTRL ROOM IMPACT");
ledcWrite(BUZZER_A, 128);
ledcWrite(BUZZER_B, 128);
}
} else {
ledcWrite(BUZZER_A, 0);
ledcWrite(BUZZER_B, 0);
lcd.setCursor(0, 0); lcd.print("GRID ONLINE: ");
lcd.setCursor(0, 1); lcd.print("SYSTEM SECURE ");
}
oled.display();
}
void drawFuturisticRadarUI(int distance) {
// Radar Semicircle Arcs
oled.drawCircle(64, 63, 60, WHITE);
oled.drawCircle(64, 63, 38, WHITE);
// Center Control Room Core Circle (Radius 14)
oled.drawCircle(64, 63, 14, WHITE);
oled.drawLine(4, 63, 124, 63, WHITE);
oled.setTextSize(1);
oled.setTextColor(WHITE);
// 📍 EXACT TARGET ALIGNMENT: Sectors are positioned right above the central Control Room Circle Line!
oled.setCursor(24, 44); oled.print("Sec A"); // Left side just above the core arc boundary
oled.setCursor(76, 44); oled.print("Sec B"); // Right side just above the core arc boundary
// Control Room core mark centered inside its circle
oled.setCursor(53, 52); oled.print("CTRL");
if (distance < 150) {
int mappedRadius = map(constrain(distance, 10, 150), 10, 150, 10, 58);
oled.fillCircle(64, 63 - mappedRadius, 3, WHITE);
oled.drawCircle(64, 63 - mappedRadius, 6, WHITE);
oled.setCursor(2, 4); oled.print(String(distance) + "cm");
} else {
oled.setCursor(2, 4); oled.print("SCAN");
}
}
void setRingColor(Adafruit_NeoPixel &targetRing, uint8_t r, uint8_t g, uint8_t b) {
for(int i=0; i<NUM_LEDS; i++) {
targetRing.setPixelColor(i, targetRing.Color(r, g, b));
}
targetRing.show();
}
: Advantages and Practical Applications
The Smart Military Defense System offers significant improvements over conventional security and surveillance methods. Here are the key advantages of this system:
- Strategic Autonomous Operations: Eliminates human casualty risks by substituting physical presence in dangerous combat or high-alert border sectors with smart automation networks.
- High-Fidelity Tactical Telemetry: Outperforms simple alarm setups by using dual screen readouts to plot target location tracking profiles alongside general system updates.
- Proactive Area Escalation: Minimizes false triggers by managing distance thresholds dynamically, letting field responders prioritize genuine perimeter risks efficiently.
- Consolidated Control Node: Manages multi-sector zones independently (two distinct alert nodes) utilizing standard power rails under a single microcontroller framework.
Live Wokwi Simulation and Virtual Testing
If you want to test and review this project virtually before building it with physical components, you can access the complete live interactive simulation via the link below. The virtual environment includes the fully pre-configured ESP32 microcontroller setup, dual displays, custom radar tracking logic, and perimeter alarm sensors.
🌐 Live Project Simulator Link: https://wokwi.com/projects/479401240142383105