Explore the development of a radar system using Arduino and a servo motor, and how Processing software is used for visualization.
In this blog post, we explore the development of a radar system using an Arduino and a servo motor. This project showcases how you can create a simple yet effective radar system to detect objects and visualize their position.
Check out the radar system in action in this YouTube Shorts video. It demonstrates the radar's capabilities and how the data is visualized in real-time.
Below is the circuit diagram for the radar system:
Here are the connection details for the components:
To visualize the radar output, we use the Processing software. Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. It is used here to display the radar readings and provide a graphical representation of the detected objects.
#include <Servo.h>
#include
const int trigPin = 8;
const int echoPin = 7;
long duration;
int distance;
Servo myServo;
void setup()
{
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(115200);
myServo.attach(9); // Defines on which pin is the servo motor attached
}
void loop()
{
for(int i=15;i<=165;i++)
{
myServo.write(i);
delay(30);
distance = calculateDistance();
Serial.print(i);
Serial.print(",");
Serial.print(distance);
Serial.print(".");
}
for(int i=165;i>15;i--){
myServo.write(i);
delay(30);
distance = calculateDistance();
Serial.print(i);
Serial.print(",");
Serial.print(distance);
Serial.print(".");
}
}
int calculateDistance()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
return distance;
}
import processing.serial.*;
Serial myPort;
int[] distances = new int[180];
void setup() {
size(800, 600);
myPort = new Serial(this, "COM3", 9600);
myPort.bufferUntil('\n');
}
void draw() {
background(255);
translate(width / 2, height / 2);
stroke(0);
noFill();
ellipse(0, 0, 300, 300);
for (int i = 0; i < distances.length; i++) {
float angle = radians(i);
float distance = distances[i];
float x = cos(angle) * distance;
float y = sin(angle) * distance;
point(x, y);
}
}
void serialEvent(Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
int angle = (frameCount % 180);
distances[angle] = int(inString);
}
}
This radar system project illustrates how to integrate hardware and software to create a functional and interactive radar. By using Processing for visualization, we can gain valuable insights into the radar's performance and the environment it is scanning.