Radar system using arduino nano

In this tutorial, we are going to make a RADAR system using Arduino nano, an ultrasonic sensor, and a servo motor. The word RADAR stands for “Radio Detection and Ranging”. This RADAR system can detect both stationary and moving objects within its range.

In this project, we are going to use an ultrasonic sensor to detect objects at a certain distance and angles.

Ultrasonic sensor

ultrasonic sensor

You can see in the above picture that the ultrasonic sensor consists of two major parts. The first part is a transmitter and the other part is a receiver. This sensor has 4 pins






+5v DC supply


Data output


Command input


0v DC

The ultrasonic sensor is used to detect objects at a certain distance. It can also measure the distance between the object and the sensor by the concept of sound navigation and ranging (SONAR). The operating frequency of the ultrasonic sensor is 40KHz.

Servo motor

servo motor

The above picture shows a servo motor. A servo motor is a simple DC motor with some gears. It provides more control when compared to a simple dc motor. We can control the rotation of the motor with respect to speed and direction. The servo motor is based on the concept of a closed-loop mechanism, which means it uses feedback to control every action of the motor.

Generally, DC motors work according to the given power supply, but servo motors work according to signals given to them.

Servo motors are generally used in engineering projects and toys like airplanes, cars, etc.

Working of RADAR

The ultrasonic sensor consists of two parts. The transmitter and the receiver. The transmitter part transmits the ultrasonic waves. These waves when hitting any object returns back and get received by the receiver. In this way, the object gets detected.

Now we need to find the distance of the object from the sensor. To calculate distance we need two different data that is the speed of sound wave (332 meters per second) and the time taken by the wave to return to the receiver.

The formula for calculating distance is

D = ½ T x S


D = distance between object and sensor

T = time taken by the sound wave to return to the receiver.

S = speed of sound






Pin D2

Trigger pin of ultrasonic sensor.

Pin D3

Echo pin of ultrasonic sensor.

Pin D9

Servo signal pin.


Positive supply of ultrasonic sensor and servo motor.


Ground supply of ultrasonic sensor and servo motor.

We are not going to use any power supply for this circuit. The circuit can power itself from the connected computer through cable. If you want to operate it without cable, then provide Arduino nano with 5v dc supply.

Arduino code

#include <Servo.h> //include library of servo

Servo myServo;     //create an object of your name

int dis;

void setup() {

  pinMode(2, OUTPUT); //define Arduino pin for trig

  pinMode(3, INPUT);  //define Arduino pin for echo

  Serial.begin(9600); //it tells Arduino to get ready to send and receive messages with a bit rate of 9600 bits per second.

  myServo.attach(9);  //connect servo data pin to pin 9 of arduino


void loop()


  for (int x = 0; x <= 180; x++) // define angle to turn left


{ //servo turn left

    myServo.write(x); //rotate servo as defined in x


    Serial.print(x);  //print servo angle


    Serial.print(dis); //print ultrasonic distance readings


    delay(50);  // delay 50 micro second before turning right


  for (int y = 179; y > 0; y–) // define angle to turn right


{//servo turn right

    myServo.write(y); //rotate servo


    Serial.print(y);  //print servo angle


    Serial.print(dis); //print ultrasonic distance readings


    delay(50); // delay 50 microsecond before turning left




//ultrasonic sensor code

int distance()


  digitalWrite(2, LOW); // put pin 2 (trig) low

  delayMicroseconds(4); // delay 4 microsecond

  digitalWrite(2, HIGH); // put pin 2 (trig) high

  delayMicroseconds(10); // delay 10 micro second

  digitalWrite(2, LOW); // put pin 2 (trig) low



  int t = pulseIn(3, HIGH); // data from sensor to arduino

  int cm = t*0.032 / 2; //time convert distance

  return cm; //return value



Processing code

The output screen of the radar is built using processing software. The code for processing software is given below

Serial myport;//create serial object

PFont f;

int Angle, Distance;

String angle=””;   // to print angle

String distance=””;  // to print distance

String data;

int index1=0;

int index2=0;

float pixsDistance;

void setup() {

  size(1600, 700);//screen size


  printArray(PFont.list());  // show font list your computer

  f = createFont(“David Bold”, 28); // define font name and size


  String portName = Serial.list()[0];//set COM port

  myport = new Serial(this, portName, 9600);



void draw() {


  fill(0, 10);

  rect(0, 0, width, 700);

  fill(98, 245, 31);







//get ardunio board serial values

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());

  // converts the String variables into Integer

  Angle = int(angle);

  Distance = int(distance);


//Half circle and lines

void radararea() {


  translate(625, 680);



  stroke(98, 245, 31);

  // draws the arc lines

  arc(0, 0, 1150, 1150, PI, TWO_PI);

  arc(0, 0, 850, 850, PI, TWO_PI);

  arc(0, 0, 550, 550, PI, TWO_PI);

  arc(0, 0, 250, 250, PI, TWO_PI);

  // draws the angle lines

  line(-450, 0, 450, 0);

  line(0, 0, -600*cos(radians(30)), -600*sin(radians(30)));

  line(0, 0, -600*cos(radians(60)), -600*sin(radians(60)));

  line(0, 0, -600*cos(radians(90)), -600*sin(radians(90)));

  line(0, 0, -600*cos(radians(120)), -600*sin(radians(120)));

  line(0, 0, -600*cos(radians(150)), -600*sin(radians(150)));

  line(-960*cos(radians(30)), 0, 960, 0);



//Green box net

void greenmesh() {

  stroke(98, 245, 31);


  for (int x=0; x<=700; x+=5) {

    line(0, x, width, x);


  for (int y=0; y<=1250; y+=5) {

    line(y, 0, y, height);



//print text

void words() {

  fill(98, 245, 31);

  text(“180′”, 10, 670);

  fill(98, 245, 31);

  text(“0′”, 1210, 670);

  fill(98, 245, 31);

  text(“30′”, 1160, 380);

  fill(98, 245, 31);

  text(“60′”, 940, 160);

  fill(98, 245, 31);

  text(“90′”, 615, 70);

  fill(98, 245, 31);

  text(“120′”, 310, 150);

  fill(98, 245, 31);

  text(“150′”, 80, 370);


  text(“SriTu Tech Radar system”, 20, 30);


  text(“Angle — “+Angle+” ‘”, 20, 60);


  text(“Distance — “+Distance+” cm”, 20, 90);


//Drawing green lines

void greenLine() {



  stroke(30, 250, 60);//green color

  translate(625, 680);

  line(0, 0, 600*cos(radians(Angle)), -600*sin(radians(Angle)));



//Drawing red lines

void redline() {


  translate(625, 680);


  stroke(255, 10, 10); //red color

  pixsDistance = Distance*22.5;

  // limiting the range to 40 cm

  if (Distance<40) {

    line(pixsDistance*cos(radians(Angle)), -pixsDistance*sin(radians(Angle)), 600*cos(radians(Angle)), -600*sin(radians(Angle)));




Visit YouTube


Discover more projects-

  1. 0-9 counter using arduino nano
Share This Post

1 thought on “Radar system using arduino nano”

Leave a Comment