Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

Building a Radar System with Arduino Uno, Sonar Sensor, Servo Motor, and TFT Display

Introduction

Creating a radar system is a fascinating project that brings together various electronic components to build a functional and visually engaging device. In this guide, we’ll demonstrate how to use an Arduino Uno, a sonar sensor, a servo motor, and a TFT display to build your own radar system. Follow along to integrate these components and see how they work together to create a radar-like experience.

Materials Needed

  • Jumper Wires and Breadboard

Circuit Diagram

Code

#include <Servo.h>
#include <TFT.h>  // Arduino LCD library
#include <SPI.h>

// Pin definitions
#define cs   10
#define dc   9
#define rst  8

Servo servo;
TFT TFTscreen = TFT(cs, dc, rst);

int interval = 0;
double distance = 0;
char rc_Printout[4];

void setup() { 
  servo.attach(6);  // Servo signal pin
  pinMode(2, OUTPUT); // Trig pin
  pinMode(3, INPUT);  // Echo pin
  Serial.begin(9600);
  TFTscreen.begin();
  TFTscreen.background(0, 0, 0);
}

void loop() {
  int r_beam = 100; // Beam radius
  TFTscreen.stroke(255, 255, 255);
  TFTscreen.circle(80, 128, r_beam + 2);
  TFTscreen.setTextSize(2);
  TFTscreen.text("Dist(cm)", 0, 0);

  // Right rotation  
  for (int i = 0; i < 180; i++) {
    servo.write(i);
    measure_dist();
    Serial.print(i);
    Serial.print("\n");
    delay(20);

    int r = distance * 2;
    String r_Printout = String(r / 2);

    TFTscreen.stroke(0, 0, 0);
    TFTscreen.setTextSize(2);
    TFTscreen.text(rc_Printout, 100, 0);
    
    r_Printout.toCharArray(rc_Printout, 4); 
    TFTscreen.stroke(255, 255, 255);
    TFTscreen.setTextSize(2);
    TFTscreen.text(rc_Printout, 100, 0);
    
    TFTscreen.stroke(70, 70, 70);
    TFTscreen.line(80, 128, 80 + r_beam * cos((360 - i) * 3.14 / 180), 128 + r_beam * sin((360 - i) * 3.14 / 180));
    TFTscreen.stroke(0, 255, 0);
    TFTscreen.circle(80 + r * cos((360 - i) * 3.14 / 180), 128 + r * sin((360 - i) * 3.14 / 180), 2);
  }
  
  TFTscreen.background(0, 0, 0);
  
  TFTscreen.stroke(255, 255, 255);
  TFTscreen.circle(80, 128, r_beam + 2);
  TFTscreen.setTextSize(2);
  TFTscreen.text("Dist(cm)", 0, 0);

  // Left rotation  
  for (int i = 180; i > 0; i--) {
    servo.write(i);
    measure_dist();
    Serial.print(i);
    Serial.print("\n");
    delay(20);

    int r = distance * 2;
    String r_Printout = String(r / 2);

    TFTscreen.stroke(0, 0, 0);
    TFTscreen.setTextSize(2);
    TFTscreen.text(rc_Printout, 100, 0);

    r_Printout.toCharArray(rc_Printout, 4);

    TFTscreen.stroke(255, 255, 255);
    TFTscreen.setTextSize(2);
    TFTscreen.text(rc_Printout, 100, 0);

    TFTscreen.stroke(70, 70, 70);
    TFTscreen.line(80, 128, 80 + r_beam * cos((360 - i) * 3.14 / 180), 128 + r_beam * sin((360 - i) * 3.14 / 180));
    TFTscreen.stroke(0, 255, 0);
    TFTscreen.circle(80 + r * cos((360 - i) * 3.14 / 180), 128 + r * sin((360 - i) * 3.14 / 180), 2);
  }
  
  TFTscreen.background(0, 0, 0);  
}

void measure_dist() { 
  Serial.read();
  // Pulse
  digitalWrite(2, HIGH);
  delayMicroseconds(100);
  digitalWrite(2, LOW);
  // Measure the interval 
  interval = pulseIn(3, HIGH);
  distance = interval * 0.017; // cm 
  Serial.print(interval, DEC);
  Serial.print("\t");
  Serial.print(distance, 1);
  Serial.print("\n");
}

NOTE:

This radar system project demonstrates how to integrate a sonar sensor, servo motor, and TFT display with an Arduino Uno to create a functional radar-like device. It’s a great way to learn about sensor integration, motor control, and display interfacing. Customize and expand on this project to suit your needs and enjoy the process of creating your own radar system!

    Leave a Reply

    Your email address will not be published.

    Need Help?