RADAR USING ARDUINO UNO

                              RADAR (RADIO WAVES TO DETERMINE THE RANGE) 







Radar is an object-detection system that uses radio waves to determine the range, angle, or velocity of objects. It can be used to detect aircraftshipsspacecraftguided missilesmotor vehiclesweather formations, and terrain. A radar system consists of a transmitter producing electromagnetic waves in the radio or microwaves domain, a transmitting antenna, a receiving antenna (often the same antenna is used for transmitting and receiving) and a receiver and processor to determine properties of the object(s). Radio waves (pulsed or continuous) from the transmitter reflect off the object and return to the receiver, giving information about the object's location and speed.
Radar was developed secretly for military use by several nations in the period before and during World War II. A key development was the cavity magnetron in the UK, which allowed the creation of relatively small systems with sub-meter resolution. The term RADAR was coined in 1940 by the United States Navy as an acronym for RAdio Detection And Ranging[1][2] or RAdio Direction And Ranging.[3][4] The term radar has since entered English and other languages as a common noun, losing all capitalization



USING DEVICE 
1. ARDUINO UNO
2. ULTRASONIC SENSOR
3. SERVO MOTOR
4. SOME WIRES (JUMPER WIRES) 


ARDUINO CODE


  1. // Includes the Servo library
  2. #include <Servo.h>. 
  3. // Defines Tirg and Echo pins of the Ultrasonic Sensor
  4. const int trigPin = 10;
  5. const int echoPin = 11;
  6. // Variables for the duration and the distance
  7. long duration;
  8. int distance;
  9. Servo myServo; // Creates a servo object for controlling the servo motor
  10. void setup() {
  11.   pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  12.   pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  13.   Serial.begin(9600);
  14.   myServo.attach(12); // Defines on which pin is the servo motor attached
  15. }
  16. void loop() {
  17.   // rotates the servo motor from 15 to 165 degrees
  18.   for(int i=0;i<=180;i++){  
  19.   myServo.write(i);
  20.   delay(30);
  21.   distance = calculateDistance();// Calls a function for calculating the distance measured by the Ultrasonic sensor for each degree
  22.   
  23.   Serial.print(i); // Sends the current degree into the Serial Port
  24.   Serial.print(","); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
  25.   Serial.print(distance); // Sends the distance value into the Serial Port
  26.   Serial.print("."); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
  27.   }
  28.   // Repeats the previous lines from 165 to 15 degrees
  29.   for(int i=180;i>0;i--){  
  30.   myServo.write(i);
  31.   delay(30);
  32.   distance = calculateDistance();
  33.   Serial.print(i);
  34.   Serial.print(",");
  35.   Serial.print(distance);
  36.   Serial.print(".");
  37.   }
  38. }
  39. // Function for calculating the distance measured by the Ultrasonic sensor
  40. int calculateDistance(){ 
  41.   
  42.   digitalWrite(trigPin, LOW); 
  43.   delayMicroseconds(2);
  44.   // Sets the trigPin on HIGH state for 10 micro seconds
  45.   digitalWrite(trigPin, HIGH); 
  46.   delayMicroseconds(10);
  47.   digitalWrite(trigPin, LOW);
  48.   duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
  49.   distance= duration*0.034/2;
  50.   return distance;
  51. }





                                                                      PROCESSING CODE 





  1. import processing.serial.*; // imports library for serial communication
  2. import java.awt.event.KeyEvent; // imports library for reading the data from the serial port
  3. import java.io.IOException;
  4. Serial myPort; // defines Object Serial
  5. // defubes variables
  6. String angle="";
  7. String distance="";
  8. String data="";
  9. String noObject;
  10. float pixsDistance;
  11. int iAngle, iDistance;
  12. int index1=0;
  13. int index2=0;
  14. PFont orcFont;
  15. void setup() {

  16.  size (1430, 800); // ***CHANGE THIS TO YOUR SCREEN RESOLUTION***
  17.  smooth();
  18.  myPort = new Serial(this,"COM6", 9600); // starts the serial communication
  19.  myPort.bufferUntil('.'); // reads the data from the serial port up to the character '.'. So actually it reads this: angle,distance.
  20. }
  21. void draw() {

  22.   fill(98,245,31);
  23.   // simulating motion blur and slow fade of the moving line
  24.   noStroke();
  25.   fill(0,4);
  26.   rect(0, 0, width, height-height*0.065);

  27.   fill(98,245,31); // green color
  28.   // calls the functions for drawing the radar
  29.   drawRadar();
  30.   drawLine();
  31.   drawObject();
  32.   drawText();
  33. }
  34. void serialEvent (Serial myPort) { // starts reading data from the Serial Port
  35.   // reads the data from the Serial Port up to the character '.' and puts it into the String variable "data".
  36.   data = myPort.readStringUntil('.');
  37.   data = data.substring(0,data.length()-1);

  38.   index1 = data.indexOf(","); // find the character ',' and puts it into the variable "index1"
  39.   angle= data.substring(0, index1); // read the data from position "0" to position of the variable index1 or thats the value of the angle the Arduino Board sent into the Serial Port
  40.   distance= data.substring(index1+1, data.length()); // read the data from position "index1" to the end of the data pr thats the value of the distance

  41.   // converts the String variables into Integer
  42.   iAngle = int(angle);
  43.   iDistance = int(distance);
  44. }
  45. void drawRadar() {
  46.   pushMatrix();
  47.   translate(width/2,height-height*0.074); // moves the starting coordinats to new location
  48.   noFill();
  49.   strokeWeight(2);
  50.   stroke(98,245,31);
  51.   // draws the arc lines
  52.   arc(0,0,(width-width*0.0625),(width-width*0.0625),PI,TWO_PI);
  53.   arc(0,0,(width-width*0.27),(width-width*0.27),PI,TWO_PI);
  54.   arc(0,0,(width-width*0.479),(width-width*0.479),PI,TWO_PI);
  55.   arc(0,0,(width-width*0.687),(width-width*0.687),PI,TWO_PI);
  56.   // draws the angle lines
  57.   line(-width/2,0,width/2,0);
  58.   line(0,0,(-width/2)*cos(radians(30)),(-width/2)*sin(radians(30)));
  59.   line(0,0,(-width/2)*cos(radians(60)),(-width/2)*sin(radians(60)));
  60.   line(0,0,(-width/2)*cos(radians(90)),(-width/2)*sin(radians(90)));
  61.   line(0,0,(-width/2)*cos(radians(120)),(-width/2)*sin(radians(120)));
  62.   line(0,0,(-width/2)*cos(radians(150)),(-width/2)*sin(radians(150)));
  63.   line((-width/2)*cos(radians(30)),0,width/2,0);
  64.   popMatrix();
  65. }
  66. void drawObject() {
  67.   pushMatrix();
  68.   translate(width/2,height-height*0.074); // moves the starting coordinats to new location
  69.   strokeWeight(9);
  70.   stroke(255,10,10); // red color
  71.   pixsDistance = iDistance*((height-height*0.1666)*0.025); // covers the distance from the sensor from cm to pixels
  72.   // limiting the range to 40 cms
  73.   if(iDistance<40){
  74.     // draws the object according to the angle and the distance
  75.   line(pixsDistance*cos(radians(iAngle)),-pixsDistance*sin(radians(iAngle)),(width-width*0.505)*cos(radians(iAngle)),-(width-width*0.505)*sin(radians(iAngle)));
  76.   }
  77.   popMatrix();
  78. }
  79. void drawLine() {
  80.   pushMatrix();
  81.   strokeWeight(9);
  82.   stroke(30,250,60);
  83.   translate(width/2,height-height*0.074); // moves the starting coordinats to new location
  84.   line(0,0,(height-height*0.12)*cos(radians(iAngle)),-(height-height*0.12)*sin(radians(iAngle))); // draws the line according to the angle
  85.   popMatrix();
  86. }
  87. void drawText() { // draws the texts on the screen

  88.   pushMatrix();
  89.   if(iDistance>40) {
  90.   noObject = "Out of Range";
  91.   }
  92.   else {
  93.   noObject = "In Range";
  94.   }
  95.   fill(0,0,0);
  96.   noStroke();
  97.   rect(0, height-height*0.0648, width, height);
  98.   fill(98,245,31);
  99.   textSize(25);

  100.   text("10cm",width-width*0.3854,height-height*0.0833);
  101.   text("20cm",width-width*0.281,height-height*0.0833);
  102.   text("30cm",width-width*0.177,height-height*0.0833);
  103.   text("40cm",width-width*0.0729,height-height*0.0833);
  104.   textSize(40);
  105.   text("Indian Lifehacker B.K IMPS ", width-width*0.875, height-height*0.0277);
  106.   text("Angle: " + iAngle +" °", width-width*0.48, height-height*0.0277);
  107.   text("Distance: ", width-width*0.26, height-height*0.0277);
  108.   if(iDistance<40) {
  109.   text("          " + iDistance +" cm", width-width*0.225, height-height*0.0277);
  110.   }
  111.   textSize(25);
  112.   fill(98,245,60);
  113.   translate((width-width*0.4994)+width/2*cos(radians(30)),(height-height*0.0907)-width/2*sin(radians(30)));
  114.   rotate(-radians(-60));
  115.   text("30°",0,0);
  116.   resetMatrix();
  117.   translate((width-width*0.503)+width/2*cos(radians(60)),(height-height*0.0888)-width/2*sin(radians(60)));
  118.   rotate(-radians(-30));
  119.   text("60°",0,0);
  120.   resetMatrix();
  121.   translate((width-width*0.507)+width/2*cos(radians(90)),(height-height*0.0833)-width/2*sin(radians(90)));
  122.   rotate(radians(0));
  123.   text("90°",0,0);
  124.   resetMatrix();
  125.   translate(width-width*0.513+width/2*cos(radians(120)),(height-height*0.07129)-width/2*sin(radians(120)));
  126.   rotate(radians(-30));
  127.   text("120°",0,0);
  128.   resetMatrix();
  129.   translate((width-width*0.5104)+width/2*cos(radians(150)),(height-height*0.0574)-width/2*sin(radians(150)));
  130.   rotate(radians(-60));
  131.   text("150°",0,0);
  132.   popMatrix();

  133. }


processing software 

1. processing 3



Comments

Popular Posts