RADAR USING ARDUINO 

What is Arduino Radar? 

Arduino Radar is a simple Radar Application using Arduino and Processing. This Arduino Radar is implemented with the help of Processing Applications. 
In this article, you will know how to design a simple DIY Arduino radar. 
Radar is a long-range object detection system that uses radio waves to establish certain parameters of an object like its range, speed, and position. Radar technology is used in aircraft, missiles, marine, weather predictions, and automobiles. 
Even though the title says Arduino Radar, technically it is based on Sonar technology as I will be using an Ultrasonic Sensor to determine the presence of any object in a limited range. 

OVERVIEW 

The Arduino Radar Project is more of a visual project than it is a circuit implementation. Of course, I will be using different hardware like Arduino UNO, HC-SR04 (Ultrasonic Sensor) and Servo Motor but the main aspect is the visual representation in the Processing Application. 
We will collect the information from the Ultrasonic Sensor with the help of Arduino and pass it to Processing where a simple Graphics application is implemented to mimic a Radar Screen. 

HOW TO DO IT? 

Components Required 

Hardware 

  • Arduino UNO  
  • HC-SR04 Ultrasonic Sensor   
  • TowerPro SG90 Servo Motor   
  • Mounting Bracket for Ultrasonic Sensor (optional)   
  • Connecting Wires   
  • Jumper Cables   
  • 5V Power Supply   
  • USB Cable (for Arduino)   

Software 

  • Arduino IDE 
  • Processing Application 

Circuit Diagram of Arduino Radar 

The circuit diagram of this Radar is very simple as it involves very little hardware. 

Illustration of circuit diagram 

A radar sweeps an area to detect the objects in the range. Similarly, in the Arduino radar, we are using an ultrasonic sensor to scan for objects. To move it in our entire range we are using servo motor for the movement of the sensor. 

WORKING  

The basic structure of our radar is as follows 
After the making connections: 
Initially, upload the code to Arduino after making the connections. You can observe the servo sweeping from 00 to 1800 and again back to 00. Since the Ultrasonic Sensor is mounted over the Servo, it will also participate in the sweeping action. 
Now, open the processing application and paste the above-given sketch. In the Processing Sketch, make necessary changes in the COM Port selection and replace it with the COM Port number to which your Arduino is connected to. 
If you note the Processing Sketch, I have used the output display size as 1280×720 (assuming almost all computers nowadays have a minimum resolution of 1366×768) and calculated this resolution. 
In the future, I will upload a new Processing sketch where you can enter the desired resolution (like 1920×1080) and all the calculations will be automatically adjusted to this resolution. 
Now, run the sketch in the Processing and if everything goes well, a new Processing window opens up like the one shown below.   
Graphical representation of the data from the Ultrasonic Sensor is represented in a Radar type display. If the Ultrasonic Sensor detects any object within its range, the same will be displayed graphically on the screen.   

Code 

There are two codes for this project: one for the Arduino UNO and the other for the Processing. 

Arduino Code 

The code for Arduino UNO is given below. 
 
#include <Servo.h> 
  
const int trigPin = 9; 
const int echoPin = 10; 
  
long duration; 
int distinCM; 
  
Servo radarServo; 
  
void setup()  
{ 
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 
  Serial.begin(9600); 
  radarServo.attach(11); 
} 
void loop()  
{ 
  for(int i=0;i<=180;i++) 
  { 
radarServo.write(i); 
delay(50); 
     
digitalWrite(trigPin, LOW);  
delayMicroseconds(2); 
digitalWrite(trigPin, HIGH);  
delayMicroseconds(10); 
digitalWrite(trigPin, LOW); 
duration = pulseIn(echoPin, HIGH); 
distinCM = duration*0.034/2; 
     
Serial.print(i); 
Serial.print("*"); 
Serial.print(distinCM); 
Serial.print("#"); 
  } 
   
  for(int i=180;i>=0;i--) 
  { 
radarServo.write(i); 
delay(50); 
digitalWrite(trigPin, LOW);  
delayMicroseconds(2); 
digitalWrite(trigPin, HIGH);  
delayMicroseconds(10); 
digitalWrite(trigPin, LOW); 
duration = pulseIn(echoPin, HIGH); 
distinCM = duration*0.034/2; 
     
Serial.print(i); 
Serial.print("*"); 
Serial.print(distinCM); 
Serial.print("#"); 
  } 
} 
 
Processing Code 
The code for Processing Application is given below. 
 
import processing.serial.*; 
import processing.opengl.*; 
import toxi.geom.*; 
import toxi.processing.*; 
  
ToxiclibsSupport gfx; 
  
  
Serial port; 
String serialAngle; 
String serialDistance; 
String serialData; 
float objectDistance; 
int radarAngle, radarDistance; 
int index=0; 
  
void setup()  
{ 
  size (1280, 720); 
  gfx = new ToxiclibsSupport(this); 
  smooth(); 
   
  //println(Serial.list()); 
   
  //String portName = Serial.list()[0]; 
  String portName = "COM4"; 
  port = new Serial(this, portName, 9600); 
   
  //port = new Serial(this,"COM4", 9600); 
  port.bufferUntil('#'); 
} 
  
void draw()  
{ 
  //fill(10,255,10); 
  noStroke(); 
   
  fill(0,4);  
  rect(0, 0, 1280, 720); 
  fill(10,255,10); 
   
  //Radar Arcs and Lines 
  pushMatrix(); 
   
  translate(640,666); 
  noFill(); 
  strokeWeight(2); 
  stroke(10,255,10);   
  arc(0,0,1200,1200,PI,TWO_PI); 
  arc(0,0,934,934,PI,TWO_PI); 
  arc(0,0,666,666,PI,TWO_PI); 
  arc(0,0,400,400,PI,TWO_PI); 
  strokeWeight(4); 
  line(-640,0,640,0); 
  line(0,0,-554,-320); 
  line(0,0,-320,-554); 
  line(0,0,0,-640); 
  line(0,0,320,-554); 
  line(0,0,554,-320); 
   
  popMatrix(); 
  
  //Ultrasonic Lines 
  pushMatrix(); 
   
  strokeWeight(5); 
  stroke(10,255,10); 
  translate(640,666); 
  line(0,0,640*cos(radians(radarAngle)),-640*sin(radians(radarAngle))); 
   
  popMatrix(); 
  
  //Object Detection Lines 
  pushMatrix(); 
   
  translate(640,666); 
  strokeWeight(5); 
  stroke(255,10,10); // red color 
  objectDistance = radarDistance*15; 
  
  if(radarDistance<40) 
  { 
line(objectDistance*cos(radians(radarAngle)),-objectDistance*sin(radians(radarAngle)),633*cos(radians(radarAngle)),-633*sin(radians(radarAngle))); 
  } 
   
  popMatrix(); 
} 
  
void serialEvent (Serial port)  
{ 
  serialData = port.readStringUntil('#'); 
  serialData = serialData.substring(0,serialData.length()-1); 
   
  index = serialData.indexOf("*"); 
   
  serialAngle= serialData.substring(0, index); 
  serialDistance= serialData.substring(index+1, serialData.length()); 
   
  radarAngle = int(serialAngle); 
  radarDistance = int(serialDistance); 

 

Object detection 

 After writing the code in both Arduino and processing we are ready to go for object detection. The output in the processing is as follows 
Graphical representation of the data from the Ultrasonic Sensor is represented in a Radar type display. If the Ultrasonic Sensor detects any object within its range, the same will be displayed graphically on the screen.   
Spread knowledge

Leave a Comment

Your email address will not be published. Required fields are marked *