Tushar Gupta
Published © MIT

Autonomous Smart Military Defense System

An ESP32-based autonomous border defense system with automated tracking, dynamic alerts, and real-time custom dual-OLED display diagnostics.

IntermediateFull instructions provided5 hours21
Autonomous Smart Military Defense System

Things used in this project

Story

Read more

Custom parts and enclosures

working image

you se the best workng condition
File missing, please reupload.

working image

you see the best workng condition

Schematics

Autonomous Smart Military Defense System - images

This images demonstrates the working prototype of our autonomous border security grid. It showcases real-time threat detection using a PIR sensor, adaptive distance tracking with an ultrasonic matrix, dynamic multi-colored indicator rings, and active radar sweep telemetry on dual-OLED displays.

Code

Main_ESP32_Firmware

Arduino
Complete source code for autonomous targeting and dual display radar grid simulation.
// Autonomous Smart Military Defense System Prototype
// Built on Wokwi Simulator - Designed by Tushar Gupta

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 displayNormal(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 displayRadar(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

const int PIR_PIN = 12;
const int TRIG_PIN = 14;
const int ECHO_PIN = 27;
const int BUZZER_PIN = 26;

void setup() {
  Serial.begin(115200);
  pinMode(PIR_PIN, INPUT);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  if(!displayNormal.begin(SSD1306_SWITCHCAPVCC, 0x3C)) Serial.println("Display 1 Error");
  if(!displayRadar.begin(SSD1306_SWITCHCAPVCC, 0x3D)) Serial.println("Display 2 Error");
  
  displayNormal.clearDisplay();
  displayNormal.setTextSize(1);
  displayNormal.setTextColor(WHITE);
  displayNormal.setCursor(0, 10);
  displayNormal.println("SYSTEM READY");
  displayNormal.display();
}

void loop() {
  long duration;
  int distance;
  int intruderDetected = digitalRead(PIR_PIN);

  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  duration = pulseIn(ECHO_PIN, HIGH);
  distance = duration * 0.034 / 2;

  if (intruderDetected == HIGH) {
    handleAlert(distance);
  } else {
    resetSystem();
  }
  delay(200);
}

void handleAlert(int dist) {
  displayNormal.clearDisplay();
  displayRadar.clearDisplay();
  
  displayNormal.setCursor(0,0);
  displayNormal.setTextSize(2);
  displayNormal.println("!! ALERT !!");
  displayNormal.setTextSize(1);
  displayNormal.print("Distance: ");
  displayNormal.print(dist);
  displayNormal.println(" cm");
  displayNormal.display();

  displayRadar.drawCircle(64, 63, 50, WHITE); 
  if (dist < 20) {
    analogWrite(BUZZER_PIN, 255); 
  } else {
    analogWrite(BUZZER_PIN, 100);
  }
  displayRadar.display();
}

void resetSystem() {
  noTone(BUZZER_PIN);
  displayNormal.clearDisplay();
  displayNormal.setCursor(0,10);
  displayNormal.setTextSize(1);
  displayNormal.println("Border Status: SECURE");
  displayNormal.display();
}
Main_ESP32_Firmwar

Credits

Tushar Gupta
1 project • 0 followers
Thanks to WOKWI.

Comments