DIY Arduino Radar Simulation with HC-SR04, Servo, and Processing
If you're searching for the ultimate DIY radar system, a radar project with Arduino code, or even a DIY radar defense system, you've come to the right place. This complete guide walks you through building a fully functional Arduino radar using an Arduino Uno, an HC-SR04 ultrasonic sensor, and a servo motor. Whether you're a beginner or an advanced maker—and whether you want to build physically or simulate in Proteus 8—this project delivers everything: schematic, wiring, full source code, Processing visualization, and step-by-step simulation instructions.
📡 Project Overview: Your Complete Arduino Radar System
This Arduino radar project mimics real radar behavior by rotating an ultrasonic sensor across a 150° field of view and detecting obstacles in real time. The Arduino Uno controls a servo that sweeps the HC-SR04 from 15° to 165°. At each angle, the sensor measures distance, and the data is streamed over serial to a PC running a Processing sketch, which renders a live radar display.
The entire system can also be simulated in Proteus 8, making it ideal for students, educators, or remote learners who want to validate logic before building hardware. This isn’t just a toy—it’s a practical introduction to scanning systems, real-time data visualization, and embedded sensing.
How It Works
- The servo rotates the ultrasonic sensor in precise angular steps.
- At each angle, the HC-SR04 emits a pulse and calculates distance from the echo.
- The Arduino formats data as
"Angle,Distance"and sends it via Serial. - Processing receives this stream and draws a sweeping radar arc with red dots for detected objects.
- In Proteus, you can simulate the entire circuit and test serial output—no physical hardware required.
🛠️ Hardware Components
- Arduino Uno – main controller
- HC-SR04 Ultrasonic Sensor – distance measurement
- SG90 Micro Servo – enables angular scanning
- Breadboard and jumper wires – for clean assembly
- USB cable – for power and serial communication
All components are affordable, widely available, and perfect for prototyping.
⚙️ Wiring Diagram (Pin Connections)
| Component | Arduino Pin | Notes |
|---|---|---|
| HC-SR04 VCC | 5V | Power |
| HC-SR04 GND | GND | Common ground |
| HC-SR04 TRIG | D10 | Trigger output |
| HC-SR04 ECHO | D11 | Echo input |
| Servo (SG90) VCC | 5V | Power (use external supply if unstable) |
| Servo GND | GND | Shared ground |
| Servo Signal | D12 | PWM control signal |
💡 Tip: If the Arduino resets during servo movement, power the servo from an external 5V source (but keep grounds connected).
🧠 Arduino Code (sketch_oct1a.ino)
#include <Servo.h>
Servo radarServo;
const int trigPin = 10;
const int echoPin = 11;
void setup() {
radarServo.attach(12);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
radarServo.write(90); // Start facing forward
delay(1000);
}
void loop() {
// Sweep from 15° to 165°
for (int angle = 15; angle <= 165; angle += 1) {
radarServo.write(angle);
delay(20);
int distance = readDistance();
if (distance > 0 && distance < 400) { // Valid range: ~2cm to 400cm
Serial.print(angle);
Serial.print(",");
Serial.println(distance);
}
}
// Sweep back from 165° to 15°
for (int angle = 165; angle >= 15; angle -= 1) {
radarServo.write(angle);
delay(20);
int distance = readDistance();
if (distance > 0 && distance < 400) {
Serial.print(angle);
Serial.print(",");
Serial.println(distance);
}
}
}
int readDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
int distance = duration * 0.034 / 2; // Convert to cm
return distance;
}
This code:
- Sweeps the servo back and forth smoothly
- Measures distance at every degree
- Sends clean
"Angle,Distance"data over serial - Filters out invalid readings (e.g., 0 cm or >400 cm)
🖥️ Processing Radar Visualization
Install Processing IDE, then run this sketch to see your radar display:
import processing.serial.*;
Serial port;
String angle = "";
String distance = "";
String data = "";
String noObject;
float ang, dist;
void setup() {
size(800, 600);
smooth();
println(Serial.list());
port = new Serial(this, Serial.list()[0], 9600);
port.bufferUntil('\n');
}
void draw() {
background(0);
// Draw radar arc background
fill(0, 255, 0, 20);
stroke(0, 255, 0);
arc(width/2, height, 600, 600, PI, TWO_PI);
// Draw grid lines
for (int i = 0; i < 5; i++) {
noFill();
stroke(0, 100, 0);
ellipse(width/2, height, 120*(i+1), 120*(i+1));
}
// Draw sweep line
stroke(0, 255, 0);
line(width/2, height, width/2 - cos(radians(ang)) * dist * 2, height - sin(radians(ang)) * dist * 2);
// Plot detected objects
stroke(255, 0, 0);
point(width/2 - cos(radians(ang)) * dist * 2, height - sin(radians(ang)) * dist * 2);
}
void serialEvent(Serial port) {
data = port.readStringUntil('\n');
if (data != null) {
data = trim(data);
String[] parts = split(data, ',');
if (parts.length == 2) {
angle = parts[0];
distance = parts[1];
ang = Float.parseFloat(angle);
dist = Float.parseFloat(distance);
}
}
}
📌 Note: Select the correct COM port in Serial.list()[0]. Update the index if needed.
🔍 Simulating in Proteus 8
- Build the circuit in Proteus ISIS using the pin table above.
- Add an Arduino Uno, HC-SR04, and servo from the library (ensure servo model supports angle control).
- Compile the Arduino code in IDE → Sketch > Export Compiled Binary to get the
.hexfile. - Load the .hex into the virtual Arduino in Proteus.
- Add a VIRTUAL TERMINAL or COMPIM to monitor serial output.
- Run simulation—you should see
"Angle,Distance"data stream in real time.
For full radar visualization in simulation, connect Proteus to Processing via a virtual COM port (e.g., com0com), then run the Processing sketch as usual.
🛡️ Real-World Applications
While educational, this system can be extended for:
- Perimeter security – detect intruders in a yard
- Robot navigation – obstacle mapping for autonomous bots
- Smart parking – monitor vehicle approach angles
- Interactive art – motion-reactive installations
Upgrade to LiDAR or add Wi-Fi (ESP32) for advanced detection and cloud alerts.
✅ Why This Project Matters
This Arduino radar teaches foundational embedded skills:
- Servo control with precise angular positioning
- Ultrasonic time-of-flight distance calculation
- Serial communication between microcontroller and PC
- Real-time data visualization using Processing
It’s one of the most rewarding beginner-to-intermediate projects—combining hardware, firmware, and software in one cohesive system.
📥 Download Full Project Files
Download Code, Proteus Simulation & PDF Guide
Includes:
- Arduino
.inosource code - Processing
.pdevisualization sketch - Proteus
.pdsprjsimulation file - Printable wiring diagram and documentation
Now you know how to build, simulate, and visualize a complete Arduino radar system—from theory to live display. Whether you call it a DIY radar, sweep radar, or Arduino security scanner, this project is your gateway to smarter, sensor-driven electronics.
Start small. Simulate first. Then build with confidence.
Explore More from Embed Electronics Blog
0 Comments