Ultrasonic Radar System

by thomas383 in Circuits > Arduino

23 Views, 0 Favorites, 0 Comments

Ultrasonic Radar System

z7587204596770_2f96a66010d0e8c9bff47ca1f88ccd07.jpg
z7587204599626_ecb0b6b7902de1dcd685aa187edc4278.jpg

The project is a radar system that can detect objects from up to 200 cm away from the sensor, with a full sweeping motor to enhance the radius the radar can detect.

Downloads

Supplies

R (5).jpg
Screenshot 2026-03-04 203826.png
HC-SR04 Ultrasonic Sensor.jpg
Modulo-IIC-I2C-LCD-Display-0-1200x1200.jpg
IICLCD2-800x800.jpg
  1. Arduino Uno
  2. SG90 Servo
  3. Ultrasonic Sensor - SR04
  4. I2C Translator
  5. LCD Screen

Create a Virtual Circuit

Screenshot 2026-03-04 205229.png

Create an online circuit on TinkerCad that outlines the majority of the components needed.

Wire the Circuit Based on the Sketch

z7536567557887_7eb476db02ec3364d8fb22450b5b3e20.jpg
  1. Connect 5V pin and GND pin to the red (+) and blue (-) rails of the breadboard respectively
  2. Connect the VCC and GND of both the Servo Motor and the Ultrasonic Sensor into the Red and Blue rails
  3. Connect the Servo Motor's control wire into the Digital 12 pin
  4. Connect the trigPin of the Ultrasonic sensor into the Digital 11 pin
  5. Connect the echoPin of the Ultrasonic Sensor into the Digital 10 pin
  6. Connect the VCC and GND of the LCD screen directly into the 5V and GND pin of the Arduino
  7. Wire the SDA into A4, SCL into A5

Circuit Debugging

z7584096572063_dac1d1351607be2696a9721983313ce1.jpg

Essentially, the circuit couldn't support the current spikes caused by the servo motor (500 mA - 800 mA), so we inserted the MB-102 as a second power provider.

After testing, we found out that the MB-102 causes voltage dips which stops all components from finishing their task, therefore we wired the LCD screen straight into the Arduino Uno and removed the MB-102 completely.

Coding (servo Motor)

  1. Test code for Servo Motor

#include <Servo.h>


Servo myServo;


int pos = 0; // current position


void setup() {

myServo.attach(12); // signal pin

}


void loop() {


// Move 0 → 180 smoothly

for(pos = 0; pos <= 180; pos++) {

myServo.write(pos);

delay(15); // small delay = smooth motion

}


delay(500);


// Move 180 → 0 smoothly

for(pos = 180; pos >= 0; pos--) {

myServo.write(pos);

delay(15);

}


delay(500);

}


Coding (Ultrasonic Sensor)

  1. Test code for Ultrasonic Sensor:

const int trigPin = 11;

const int echoPin = 10;


void setup() {

Serial.begin(9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

}


void loop() {


digitalWrite(trigPin, LOW);

delayMicroseconds(2);


digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);


long duration = pulseIn(echoPin, HIGH);


float distance = duration * 0.034 / 2;


Serial.print("Distance: ");

Serial.print(distance);

Serial.println(" cm");


delay(300);

}


Downloading LiquidCrystal_I2C

Go to Sketch --> Include Library --> Manage Libraries

Then search LiquidCrystal_I2C by Frank de Brabander

Press install --> Reopen Arduino IDE

Coding (i2C LCD)

z7584090663340_027c5978017e3a442f9201a3a7a5fd2d.jpg
  1. Test code for I2C LCD:

#include <Wire.h>

#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x27, 16, 2);


void setup() {

// Initialize I2C first

Wire.begin();

// Initialize LCD

lcd.init();

lcd.backlight();

lcd.clear();

// Display message

lcd.setCursor(0, 0);

lcd.print("LCD Test");

lcd.setCursor(0, 1);

lcd.print("OK");

}


void loop() {

// Nothing

}

Write the Entire Code for the Radar System

z7587355010760_25817c937c52a08fa3e5dd54ed988f7a.jpg

#include <Servo.h>

#include <Wire.h>

#include <LiquidCrystal_I2C.h>


// -------- PINS --------

const int trigPin = 11;

const int echoPin = 10;

const int servoPin = 12;


// -------- OBJECTS --------

Servo myServo;

LiquidCrystal_I2C lcd(0x27, 16, 2);


// -------- SETTINGS --------

const int DETECTION_THRESHOLD = 30; // Changed to 30cm


void setup() {


// Ultrasonic

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);


// Serial (for debugging)

Serial.begin(9600);


// Servo

myServo.attach(servoPin);


// LCD

Wire.begin();

lcd.init();

lcd.backlight();

lcd.clear();


lcd.setCursor(0, 0);

lcd.print("Radar Starting");

delay(2000);

lcd.clear();

}


void loop() {


// -------- SWEEP 0 → 180 --------

for(int pos = 0; pos <= 180; pos++) {


myServo.write(pos);

float distance = measureDistance();


displayData(distance);


delay(15);

}


delay(300);


// -------- SWEEP 180 → 0 --------

for(int pos = 180; pos >= 0; pos--) {


myServo.write(pos);

float distance = measureDistance();


displayData(distance);


delay(15);

}


delay(300);

}


// -------- FUNCTION: MEASURE DISTANCE --------

float measureDistance() {


digitalWrite(trigPin, LOW);

delayMicroseconds(2);


digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);


long duration = pulseIn(echoPin, HIGH, 30000);


float distance = duration * 0.034 / 2;


return distance;

}


// -------- FUNCTION: DISPLAY DATA --------

void displayData(float distance) {


// Serial output (for debugging)

Serial.print("Distance: ");

Serial.print(distance);

Serial.println(" cm");


// LCD display

lcd.clear();


// Line 1: Distance

lcd.setCursor(0, 0);

lcd.print("Dist:");

lcd.print(distance);

lcd.print("cm ");


// Line 2: Detection Status

lcd.setCursor(0, 1);


if(distance > 0 && distance < DETECTION_THRESHOLD) {

lcd.print("Object Detected!");

}

else {

lcd.print("No Object ");

}

}

Test the Entire Syst