Arduino Radar - Version 2.0 © GPL3+

This project is an Arduino radar. It is a simulation of a radar.

  • 3,374 views
  • 9 comments
  • 23 respects

Components and supplies

Necessary tools and machines

3drag
3D Printer (generic)

Apps and online services

About this project

Arduino Radar Rotates for 150°.

  • It measures the distance from the object to ultrasonic sensor.
  • It displays the distance graphically on the screen.
  • If the object is close to the sensor, displays will draw red line.
  • If the object is far or if there is nothing in front of the sensor, the display will draw blue lines.

Processing (code):

Create Display

To create a display that shows the position of the object and distance, I have to draw on a gray background coordinate system quarters.

Function drawRadar(); draws white lines that represent the coordinate system.

This is translated with the center for 700px x and y axes.

Display Example

After switching on this function the display looks like this:

  • drawObject(); function draws a red line if the object is close to the sensor.
  • drawLine(); function draws a blue line if the object is far.

  • drawText(); function prints text on the screen.

Code

Arduino IDE codeArduino
Code for Arduino IDE
#include <Servo.h> 
Servo myServo; 
int trigPin = 10;
int echoPin = 11;
long duration;
int distance;

void setup() {
  Serial.begin(9600);
  myServo.attach(12); 
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 
}

void loop() {
 print_serial();
}
void print_serial(){
  for(int i=165;i>15;i--){  
  myServo.write(i);
  delay(30);
  distance = measures_the_distance();
  Serial.print(i);
  Serial.print(",");
  Serial.print(distance);
  Serial.print(".");
  }
  for(int i=15;i<=165;i++){  
  myServo.write(i);
  delay(30);
  distance = measures_the_distance();
  Serial.print(i); 
  Serial.print(","); 
  Serial.print(distance); 
  Serial.print("."); 
  }
}
int measures_the_distance(){ 
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH); 
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH); 
  distance= duration*0.034/2;
  return distance;
}
Processing codeProcessing
code for Processing IDE
import processing.serial.*; 
import java.awt.event.KeyEvent; 
import java.io.IOException;
Serial myPort;
String angle="";
String distance="";
String data="";
String noObject;
float pixsDistance;
int iAngle, iDistance;
int index1=0;
int index2=0;
PFont orcFont;

void setup() {
 size (1900,1200);
 smooth();
 myPort = new Serial(this,"COM6", 9600); 
 myPort.bufferUntil('.'); 
}

void draw() {
  
  fill(98,245,31);
  noStroke();
  fill(0,4); 
  rect(0, 0, width, 1010); 
  
  drawRadar(); 
  drawLine();
  drawObject();
  drawText();
}

void serialEvent (Serial myPort) { 
  data = myPort.readStringUntil('.');
  data = data.substring(0,data.length()-1);
  
  index1 = data.indexOf(","); 
  angle= data.substring(0, index1);
  distance= data.substring(index1+1, data.length()); 
  
  iAngle = int(angle);
  iDistance = int(distance);
}

void drawRadar() {
  pushMatrix();
  translate(700,700); 
  noFill();
  strokeWeight(2);
  stroke(255,245,255);
  // draws the arc lines
  arc(0,0,1800,1800,PI,TWO_PI);
  arc(0,0,1400,1400,PI,TWO_PI);
  arc(0,0,1000,1000,PI,TWO_PI);
  arc(0,0,600,600,PI,TWO_PI);
 
  line(-960,0,960,0);
  line(0,0,-960*cos(radians(30)),-960*sin(radians(30)));
  line(0,0,-960*cos(radians(60)),-960*sin(radians(60)));
  line(0,0,-960*cos(radians(90)),-960*sin(radians(90)));
  line(0,0,-960*cos(radians(120)),-960*sin(radians(120)));
  line(0,0,-960*cos(radians(150)),-960*sin(radians(150)));
  line(-960*cos(radians(30)),0,960,0);
  popMatrix();
}
void drawObject() {
  pushMatrix();
  translate(700,700);
  strokeWeight(9);
  stroke(255,0,0); 
  pixsDistance = iDistance*22.5;
  if(iDistance<40)
     line(pixsDistance*cos(radians(iAngle)),-pixsDistance*sin(radians(iAngle)),950*cos(radians(iAngle)),-950*sin(radians(iAngle)));
  popMatrix();
}
void drawLine() {
  pushMatrix();
  strokeWeight(9);
  stroke(30,10,250);
  translate(700,700); 
  line(0,0,950*cos(radians(iAngle)),-950*sin(radians(iAngle))); 
  popMatrix();
}

void drawText() {
  
  pushMatrix();
  fill(0,0,0);
  noStroke();
  rect(0, 1010, width, 600);
  textSize(25);
  fill(255,255,255);
  translate(800,650);
  rotate(-radians(-60));
  text("30°",0,0);
  resetMatrix();
  translate(740,600);
  rotate(-radians(-30));
  text("60°",0,0);
  resetMatrix();
  translate(680,590);
  rotate(radians(0));
  text("90°",0,0);
  resetMatrix();
  translate(620,620);
  rotate(radians(-30));
  text("120°",0,0);
  resetMatrix();
  translate(590,680);
  rotate(radians(-60));
  text("150°",0,0);
resetMatrix();
  translate(50,650);
  rotate(radians(0));
  fill(5,0,0);
  text("PoliArdo team Serbia",2,5);
    fill(255,255,255);
  text("PoliArdo team Serbia",0,0);
  popMatrix(); 
}

Custom parts and enclosures

Mask and stand for ultrasonic sensor

Schematics

Arduino connection components
Uwofoo2tjd6hgk76xz5f cvwswipltq

Comments

Similar projects you might like

Radar Using Ultrasonic with Processing

Project showcase by Shahir nasar

  • 473 views
  • 0 comments
  • 1 respect

Arduino Based Radar System

Project tutorial by Nekhil ravi

  • 8,246 views
  • 10 comments
  • 34 respects

Radar Project

Project showcase by Team Siraj Msm

  • 4,389 views
  • 1 comment
  • 9 respects

Two Ultrasonic Sensor Arduino Radar - Continuous Rotation

Project showcase by Team MicroLab Greece

  • 9,180 views
  • 7 comments
  • 28 respects

360 Radar (that encodes data onto an image)

Project tutorial by Alireza Karkon

  • 5,414 views
  • 3 comments
  • 30 respects

Talking Clock 2 - New Version (Bilingual: EN-PT)

Project tutorial by LAGSILVA

  • 6,318 views
  • 19 comments
  • 31 respects
Add projectSign up / Login