Arduino Radar using Arduino Nano and TFT screen

In this Arduino Tutorial I will show you how you can make this cool looking Arduino Radar using the Arduino nano & the Arduino TFT screen. The following video shows the results of this project, read the tutorial below for more details.

Connect the Ultrasonic Sensor HC-SR04 to the pins number 2 and 3 and the servo motor to the pin number 6 on the Arduino Nano Board. Then connect the Arduino TFT screen according to my previous tutorial here.

The project has the following workflow: First the Arduino triggers the servo to move into an angle between 0 and 180 degrees then commands the ultrasonic sensor to measure distance of the obstacle if the obstacle is within the beam radius of 100 cm we draw a red otherwise we draw a green radial line.

Now let’s take a look at the code.So first we need to include the libraries for the TFT module, ultrasonic sensor and the servo motor, then define some variables needed for the program below as well as create the instances of the libraries

where 80, 128 is the center of the radar zone and 80 + r_beam * cos(( 360 – i) * 3.14 / 180 ) and 128 + r_beam * sin(( 360 – i) * 3.14 / 180 ) give us the corresponding x and y coordinate on the screen that marks the end of the line.

After that we then test the value of the ultrasonic sensor to check if the obstacle is within the radar zone. If this is true we draw a red circle marking the distance of the obstacle from the center of the radar zone

1

2

3

4

5

if(r>0&&r<=r_beam+2)

{

tft.stroke(RED);

tft.circle(80+r*cos((360-i)*3.14/180),128+r*sin((360-i)*3.14/180),2);

}

This process is repeated for the reverse movement of the servo motor

So that’s pretty much everything and here’s the complete code of the project:.