|
|
Arduino Nano R3 |
x 1 | |
|
|
SG90 Micro-servo motor |
x 1 | |
|
|
Ultrasonic Sensor - HC-SR04 |
x 1 | |
|
|
TFT display 240 x 320 ILI9341 driver chip |
x 1 | |
|
|
Resistor, 2.2 kohm |
x 5 | |
|
|
Resistor, 3.3 kohm |
x 5 |
|
Soldering Iron Kit |
|
|
arduino IDEArduino
|
DIY Arduino ultrasonic Sonar - Radar on TFT display
Ultrasonic sonar is devices that use sound waves with frequencies higher than the upper audible limit of human hearing (typically above 20 kHz) to measure distances to objects. They work on the principle of sending out a sound wave, and then measuring the time it takes for the sound wave to bounce back after hitting an object. By calculating the time difference between sending and receiving the sound wave, the distance to the object can be determined using the speed of sound in air. In some of my previous videos, you can see several different builds of such a device with special functionalities. All of them display the result on a PC monitor using an additional program written in the Processing application.
This time I will describe to you a simple way how to make an independent Sonar, where the results are displayed on a TFT color display in the form of a radar image, which is why it is often mistakenly called radar instead of sonar.
I got the idea quite by accident from a picture on the internet, and then after a little research I found that project on Github. The original project was made on a 1.8 inch display which is really a very small surface for this purpose. So I reworked the code for a larger 3.2 inch TFT display, where the image is much clearer.

The device is really simple to make and consists of only a few components
- Arduino Nano microcontroller board
- TFT display with a resolution of 240 x 320 pixels and an ILI9341 driver chip
- Ultrasonic sensor type HC-SR04
- small 9G Servo
- and several resistors that serve to shift the display signal from 5V to 3.3V level
The servo and ultrasonic sensor are housed in a separate box, which I used from a previous project, and connected to the main box with flat cables.

Now let's see how the device works in real conditions:
At the beginning, I separated the ultrasonic sensor from the servo in order to calibrate the graphic presentation with the real distance of the object. As you can see, the real distance fully corresponds to the distance shown on the display.

Now we mount the sensor on the servo and place the obstacles to be detected. At power on, the servo is tested first, then the Radar like screen is drawn on the display and scanning begins.

Obstacles are marked with red dots. In the lower left corner, the scanning area is displayed, and on the right, the distance between the sensor and the obstacle in centimeters. The three green arcs with marked distances serve us for easier visibility and an idea of the real distance. If the nearest obstacle is greater than 1 meter, yellow dots are drawn on the last arc, indicating an out of range condition. Scanning is performed first from 180 to 0 degrees, and then vice versa, from 0 to 180 degrees.

For the sake of stability during operation, the device is preferably powered by an external power source, but it also works via USB on the Arduino. All display colors can be easily changed in the code according to the user's preference.
And finally a short conclusion. Most such devices show the scan result on a PC monitor which requires an additional application and code. This is a very simple, easy to make, visually effective, and self-contained device intended for both beginners and more advanced DIYers. I've used cases from previous projects, but it's desirable to have it all in one case with a slanted front display to visually simulate a real radar system.

#include <Servo.h>
#include <SPI.h>
#include "Ucglib.h"
#define trigPin 6
#define echoPin 5
#define ServoPin 3
int Ymax = 240;
int Xmax = 320;
int Xcent = Xmax / 2;
int base = 210;
int scanline = 185;
Servo baseServo;
//Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);
Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);
void setup(void)
{
ucg.begin(UCG_FONT_MODE_SOLID);
ucg.setRotate90();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(115200);
baseServo.attach(ServoPin);
ucg.setFontMode(UCG_FONT_MODE_TRANSPARENT);
ucg.setColor(0, 0, 100, 0);
ucg.setColor(1, 0, 100, 0);
ucg.setColor(2, 20, 20,20);
ucg.setColor(3, 20, 20, 20);
ucg.drawGradientBox(0, 0, 320, 240);
ucg.setPrintDir(0);
ucg.setColor(0, 5, 0);
ucg.setPrintPos(70,120);
ucg.setFont(ucg_font_logisoso32_tf);
ucg.print("Mini Radar");
ucg.setColor(0, 255, 0);
ucg.setPrintPos(70,120);
ucg.print("Mini Radar");
ucg.setFont(ucg_font_courB14_tf);
ucg.setColor(20, 255, 20);
ucg.setPrintPos(90,200);
ucg.print("Testing...");
baseServo.write(90);
for(int x=0;x<180;x+=5)
{ baseServo.write(x);
delay(50);
}
ucg.print("OK!");
delay(500);
ucg.setColor(0,0, 0, 0);
ucg.setColor(1,0, 0, 0);
ucg.setColor(2,0, 0, 0);
ucg.setColor(3,0, 0, 0);
ucg.drawGradientBox(0, 0, 320, 240);
delay(10);
//ucg.clearScreen();
cls();
ucg.setFontMode(UCG_FONT_MODE_SOLID);
ucg.setFont(ucg_font_helvR08_hr); // or freedoomr10_tr
}
void cls()
{
ucg.setColor(0, 0, 0, 0);
for(int s=0;s<240;s++)
{
ucg.drawHLine(0,s,320);
delay(1);
}
//ucg.drawBox(0, 0, 160, 60);
}
int calculateDistance()
{
long duration;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
return duration*0.034/2;
}
void fix_font()
{
ucg.setColor(0, 180, 0);
ucg.setPrintPos(144,44);
ucg.print("1.00");
ucg.setPrintPos(144,100);
ucg.print("0.60");
ucg.setPrintPos(144,165);
ucg.print("0.30");
}
void fix()
{
ucg.setColor(0, 180, 0);
ucg.drawDisc(Xcent, base+1, 3, UCG_DRAW_ALL);
ucg.drawCircle(Xcent, base+1, 210, UCG_DRAW_UPPER_LEFT);
ucg.drawCircle(Xcent, base+1, 210, UCG_DRAW_UPPER_RIGHT);
ucg.drawCircle(Xcent, base+1, 135, UCG_DRAW_UPPER_LEFT);
ucg.drawCircle(Xcent, base+1, 135, UCG_DRAW_UPPER_RIGHT);
ucg.drawCircle(Xcent, base+1, 70, UCG_DRAW_UPPER_LEFT);
ucg.drawCircle(Xcent, base+1, 70, UCG_DRAW_UPPER_RIGHT);
ucg.drawLine(0, base+1, Xmax,base+1);
ucg.setColor(0, 180, 0);
for(int i= 40;i < 300; i+=2)
{
if (i % 10 == 0)
ucg.drawLine(185*cos(radians(i))+Xcent,base - 185*sin(radians(i)) , 205*cos(radians(i))+Xcent,base - 205*sin(radians(i)));
else
ucg.drawLine(195*cos(radians(i))+Xcent,base - 195*sin(radians(i)) , 205*cos(radians(i))+Xcent,base - 205*sin(radians(i)));
}
ucg.setColor(0,200,0);
ucg.drawLine(0,0,0,36);
for(int i= 0;i < 5; i++)
{
ucg.setColor(0,random(200)+50,0);
ucg.drawBox(2,i*8,random(28)+3,6);
}
ucg.setColor(0,180,0);
ucg.drawFrame(292,0,28,28);
ucg.setColor(0,60,0);
ucg.drawHLine(296,0,20);
ucg.drawVLine(292,4,20);
ucg.drawHLine(296,52,20);
ucg.drawVLine(318,4,20);
ucg.setColor(0,220,0);
ucg.drawBox(296,4,8,8);
ucg.drawBox(296,16,8,8);
ucg.drawBox(308,16,8,8);
ucg.setColor(0,100,0);
ucg.drawBox(308,4,8,8);
ucg.setColor(0,90,0);
ucg.drawTetragon(124,220,116,230,196,230,204,220);
ucg.setColor(0,160,0);
ucg.drawTetragon(134,220,126,230,186,230,194,220);
ucg.setColor(0,210,0);
ucg.drawTetragon(144,220,136,230,176,230,184,220);
}
void loop(void)
{
int distance;
fix();
fix_font();
for (int x=180; x > 4; x-=2){
baseServo.write(x);
int f = x - 4;
ucg.setColor(0, 255, 0);
ucg.drawLine(Xcent, base, scanline*cos(radians(f))+Xcent,base - scanline*sin(radians(f)));
f+=2;
ucg.setColor(0, 128, 0);
ucg.drawLine(Xcent, base, scanline*cos(radians(f))+Xcent,base - scanline*sin(radians(f)));
f+=2;
ucg.setColor(0, 0, 0);
ucg.drawLine(Xcent, base, scanline*cos(radians(f))+Xcent,base - scanline*sin(radians(f)));
ucg.setColor(0,200, 0);
distance = calculateDistance();
if (distance < 100)
{
ucg.setColor(255,0,0);
ucg.drawDisc(2.2*distance*cos(radians(x))+ Xcent,-2.2*distance*sin(radians(x))+base, 1, UCG_DRAW_ALL);
}
else
{
ucg.setColor(255,255,0);
ucg.drawDisc(208*cos(radians(x))+Xcent,-208*sin(radians(x))+base, 1, UCG_DRAW_ALL);
}
Serial.print(x);
Serial.print(" , ");
Serial.println(distance);
if (x > 70 and x < 110) fix_font();
ucg.setColor(255,255, 0);
ucg.setPrintPos(20,230);
ucg.print("DEG: ");
ucg.setPrintPos(54,230);
ucg.print(x);
ucg.print(" ");
ucg.setPrintPos(240,230);
ucg.print(" ");
ucg.print(distance);
ucg.print(" cm ");
}
//ucg.clearScreen();
delay(50);
cls();
fix();
fix_font();
for (int x=1; x < 176; x+=2){
baseServo.write(x);
int f = x + 4;
ucg.setColor(0, 255, 0);
ucg.drawLine(Xcent, base, scanline*cos(radians(f))+Xcent,base - scanline*sin(radians(f)));
f-=2;
ucg.setColor(0, 128, 0);
ucg.drawLine(Xcent, base, scanline*cos(radians(f))+Xcent,base - scanline*sin(radians(f)));
f-=2;
ucg.setColor(0, 0, 0);
ucg.drawLine(Xcent, base, scanline*cos(radians(f))+Xcent,base - scanline*sin(radians(f)));
ucg.setColor(0, 200, 0);
distance = calculateDistance();
if (distance < 100)
{
ucg.setColor(255,0,0);
ucg.drawDisc(2.2*distance*cos(radians(x))+Xcent,-2.2*distance*sin(radians(x))+base, 1, UCG_DRAW_ALL);
}
else
{
ucg.setColor(255,255,0);
ucg.drawDisc(208*cos(radians(x))+Xcent,-208*sin(radians(x))+base, 1, UCG_DRAW_ALL);
}
Serial.print(x);
Serial.print(" , ");
Serial.println(distance);
if (x > 70 and x < 110) fix_font();
ucg.setColor(255,255, 0);
ucg.setPrintPos(20,230);
ucg.print("DEG: ");
ucg.setPrintPos(54,230);
ucg.print(x);
ucg.print(" ");
ucg.setPrintPos(240,230);
ucg.print(" ");
ucg.print(distance);
ucg.print(" cm ");
}
//ucg.clearScreen(); //
delay(50);
cls();
}
DIY Arduino ultrasonic Sonar - Radar on TFT display
Raspberry Pi 5 7 Inch Touch Screen IPS 1024x600 HD LCD HDMI-compatible Display for RPI 4B 3B+ OPI 5 AIDA64 PC Secondary Screen(Without Speaker)
BUY NOW- Comments(0)
- Likes(0)
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Mirko Pavleski
-
Arduino 3D Printed self Balancing Cube
Self-balancing devices are electronic devices that use sensors and motors to keep themselves balanc...
-
Building a Vintage Tube-Style Internet Radio with Raspberry Pi & Rotary Encoder
Internet radio (also known as web radio or net radio) is a digital audio service transmitted via th...
-
DIY Smart Code Lock with CrowPanel 1.28 ESP32 Rotary Display
A code lock is a keyless security device—either mechanical or electronic—that restricts access to d...
-
SDR Panadapter for Vintage Tube Radios – Step-by-Step Tutorial
A radio panadapter (or panoramic adapter) is a device or software tool used in amateur radio and ot...
-
Oscilloscope Clock Simulation on a Round ESP32 Display
An oscilloscope clock is a circuit that turns an old analog oscilloscope into a stylish, retro-them...
-
DIY Simple GU32 Tube Stereo Amplifier (2x3W on 12VDC)
Vacuum tube amplifiers are often favored for their smooth harmonic distortion, especially in the low...
-
DIY 3-Display OLED Clock with Arduino and I2C Multiplexer
In this video I want to present you another unusual clock to add to my large collection of such DIY...
-
Build a 5-Day forecast Raspberry Pi Weather Dashboard (Step-by-Step)
Recently in one of my previous videos,I introduced you to the 7 inch Elecrow Pi Terminal and how to...
-
ESP32 Aneroid Barometer using Squareline Studio and LVGL on CrowPanel Round display
A barometer is a scientific instrument used to measure atmospheric pressure. Rising Pressure genera...
-
LINAMP Project – Winamp-Style Audio Front Panel on Raspberry Pi 5
Winamp is one of the most iconic and historically significant digital media players ever created. I...
-
Retro Style radio with CrowPanel 2.1inch round Display (TEA5767)
Some time ago I presented you a clock project with CrowPanel 2.1inch-HMI ESP32 Rotary Display 480*4...
-
Pi-Pico RX - SDR Radio with New Firmware and Features
A few months ago I presented you a wonderful SDR radio project by DawsonJon 101 Things. In short, i...
-
How to make simple Variable HIGH VOLTAGE Power Supply
High Voltage Power Supply is usually understood as a device that is capable of generating a voltage...
-
DIY 5-Day Rainfall Forecast Device - ESP32 E-Paper Project
In several of my previous projects I have presented ways to make weather stations, but this time I ...
-
Build simple Retro Style VFO (Variable frequency oscillator) with Crowoanel 1.28 inch Round Display
Today I received a shipment with a Small round LCD display from Elecrow. The device is packed in tw...
-
Human vs Robot – Rock Paper Scissors with MyCobot 280 M5Stack
Today I received a package containing the few Elephant Robotics products. The shipment is well pack...
-
How to Build a Simple Audio Spectrum Analyzer with Adjustable Settings
An audio spectrum analyzer is an electronic device or software tool that measures and visually disp...
-
How to Make a Digital Clock on a Vintage B&W TV using Arduino
These days I accidentally came across this small retro Black and White TV with a built-in Radio, so ...
-
-
ARPS-2 – Arduino-Compatible Robot Project Shield for Arduino UNO
914 0 2 -
-
A Compact Charging Breakout Board For Waveshare ESP32-C3
1476 3 6 -
AI-driven LoRa & LLM-enabled Kiosk & Food Delivery System
1436 2 0 -
-
-
-
ESP32-C3 BLE Keyboard - Battery Powered with USB-C Charging
1621 0 1 -
-
mammoth-3D SLM Voron Toolhead – Manual Drill & Tap Edition
1221 0 1







