Arduino Air Defense Simulator: Smart Target Tracking System Using Ultrasonic Sensor and Pan-Tilt Servos

 


In this project, we design and build a safe air defense simulator using Arduino. The system can detect objects automatically using an ultrasonic sensor, scan the environment, and track the closest object with a pan-tilt servo mechanism. A relay module is used to trigger a visual or audio alert (LED or buzzer) when a “target” is detected within a specified range.

This project is ideal for students interested in robotics, automation, and IoT systems, providing a realistic simulation of a defense targeting system without any dangerous components. It demonstrates how sensors and actuators can work together to create an intelligent, automated system.

🔧 Components Required

  • Arduino Uno
  • HC-SR04 Ultrasonic Sensor
  • 3x Servo Motors (Scan, Pan, Tilt)
  • Relay Module
  • pulse genarater
  • Jumper Wires
  • External 5V Power Supply (for servos)
  • LED or Buzzer (for alert output)

⚙️ How the System Works

The system operates in two main stages: scanning and tracking.

  1. Scanning Stage:
    • A servo rotates the ultrasonic sensor from left to right.
    • Arduino measures the distance to nearby objects continuously.
    • It identifies the closest object and records the angle of detection.
  2. Tracking Stage:
    • The pan servo rotates the base to align with the detected target.
    • The tilt servo adjusts vertically based on the distance.
    • When the target is within the defined range (e.g., less than 50 cm), the relay module triggers a safe alert using an LED or buzzer.

This creates a realistic “air defense” simulation, giving the appearance of an automated targeting system.


🔌 Circuit Explanation

  • Ultrasonic Sensor: Connect TRIG and ECHO to digital pins for distance measurement.
  • Servos: Connect PWM pins for precise movement control; supply with external 5V power.
  • Relay Module: Connect to a digital pin; used to activate visual/audio alert safely.

🔌 CIRCUIT CONNECTIONS

🔹 Ultrasonic Sensor (HC-SR04)

  • VCC → 5V
  • GND → GND
  • TRIG → D2
  • ECHO → D3

🔹 Servos

  • Scan Servo (Ultrasonic rotation) → D9
  • Pan Servo (Base rotation) → D10
  • Tilt Servo (Up/Down) → D11

👉 Use external 5V supply (2A) for servos
👉 Connect all GNDs together

🔹 Relay Module (Safe Output)

  • IN → D7
  • VCC → 5V
  • GND → GND

👉 Connect relay output to LED / buzzer only

All ground connections must be common to prevent erratic behavior.

Code

#include <Servo.h>


#define TRIG_PIN 2

#define ECHO_PIN 3

#define RELAY_PIN 7


Servo scanServo;

Servo panServo;

Servo tiltServo;


long duration;

int distance;


int bestAngle = 90;

int minDistance = 999;


int getDistance() {

  digitalWrite(TRIG_PIN, LOW);

  delayMicroseconds(2);


  digitalWrite(TRIG_PIN, HIGH);

  delayMicroseconds(10);

  digitalWrite(TRIG_PIN, LOW);


  duration = pulseIn(ECHO_PIN, HIGH);

  return duration * 0.034 / 2;

}


void setup() {

  pinMode(TRIG_PIN, OUTPUT);

  pinMode(ECHO_PIN, INPUT);

  pinMode(RELAY_PIN, OUTPUT);


  scanServo.attach(9);

  panServo.attach(10);

  tiltServo.attach(11);


  panServo.write(90);

  tiltServo.write(90);


  digitalWrite(RELAY_PIN, LOW);


  Serial.begin(9600);

}


void loop() {


  minDistance = 999;


  // 🔍 Scan for target

  for (int angle = 30; angle <= 150; angle += 3) {

    scanServo.write(angle);

    delay(60);


    int d = getDistance();


    if (d > 5 && d < minDistance) {

      minDistance = d;

      bestAngle = angle;

    }

  }


  Serial.print("Best Angle: ");

  Serial.print(bestAngle);

  Serial.print(" Distance: ");

  Serial.println(minDistance);


  // 🎯 Target tracking

  if (minDistance < 50) {

    panServo.write(bestAngle);

    delay(300);


    int tiltAngle = map(minDistance, 10, 50, 120, 70);

    tiltServo.write(tiltAngle);


    digitalWrite(RELAY_PIN, HIGH); // Alert

  } else {

    digitalWrite(RELAY_PIN, LOW);

  }


  delay(500);

}

💻 Code Explanation

  • Uses the Servo library for smooth motor movement.
  • Custom function calculates distances using the ultrasonic sensor.
  • The scanning servo sweeps the area, identifying the closest target.
  • Pan and tilt servos align with the target angle.
  • Relay triggers when the target is within threshold distance.

This safe simulation demonstrates real-time decision making, scanning, and automated tracking.


🚀 Features

  • Automatic environment scanning
  • Real-time object detection
  • Pan-tilt tracking system
  • Relay-based alert mechanism (LED/Buzzer)
  • Expandable and upgradeable

🔮 Future Improvements

  • ESP32 integration for wireless control and monitoring.
  • Add ESP32-CAM for visual tracking and object recognition.
  • Implement machine learning to detect specific targets.
  • Add a web-based dashboard to visualize targets and system activity.

🎯 Conclusion

This Arduino Air Defense Simulator is a safe and impressive educational project that combines automation, robotics, and IoT. It’s suitable for final-year students aiming to demonstrate advanced tracking systems, motion control, and decision-making in a realistic yet safe simulation environment.

Air defense system Arduino
Rocket launcher simulator project
Arduino target tracking system
Ultrasonic sensor tracking Arduino
Pan-tilt servo Arduino project
Arduino robotics final year project
DIY automation project Arduino
Object tracking system Arduino
Safe defense system Arduino
Iran Airdefence
WW3
War
figtherjet

Comments