Radar Guard 5.0

Note

🌟 Welcome to the SunFounder Facebook Community! Whether you’re into Raspberry Pi, Arduino, or ESP32, you’ll find inspiration, help ideas here.

  • ✅ Be the first to get free learning resources.

  • ✅ Stay updated on new products & exclusive giveaways.

  • ✅ Share your creations and get real feedback.

  • 👉 Need faster updates or support? Click [here] join our Facebook community

  • 👉 Or join our WhatsApp group: Click [here]

Kit purchase

Looking for parts? Check out our all-in-one kits below — packed with components, beginner-friendly guides, and tons of fun.

../_images/elite_explore_kit.png

Name

Includes Arduino board

PURCHASE LINK

Ultimate Sensor Kit

Arduino Uno R4 Minima

BUY

Elite Explorer Kit

Arduino Uno R4 WiFi

BUY

3 in 1 Ultimate Starter Kit

Arduino Uno R4 Minima

BUY

Universal Maker Sensor Kit

×

BUY

Course Introduction

This project uses an ultrasonic sensor, a servo motor, and an Arduino to create a simple radar system with LED and buzzer alerts.

The servo rotates the sensor to scan for obstacles. If an object is within a set distance, a red LED and buzzer are activated. Otherwise, a green LED shows it’s clear.

Angle and distance data are sent via the serial port for monitoring.

Note

If this is your first time working with an Arduino project, we recommend downloading and reviewing the basic materials first.

Required Components

In this project, we need the following components:

SN

COMPONENT INTRODUCTION

QUANTITY

PURCHASE LINK

1

Arduino UNO R4 Minima

1

BUY

2

USB Type-C cable

1

3

Breadboard

1

BUY

4

Wires

Several

BUY

5

Ultrasonic Sensor Module

1

BUY

6

Digital Servo Motor

1

BUY

7

Buzzer

1

8

LED

2

BUY

9

1kΩ resistor

2

BUY

Wiring

../_images/radar_guard5.0_bb.png

Common Connections:

  • LED

    • Connect the LEDs anode to the 3, 4 on Arduino, and the LEDs cathode to a 1kΩ resistor then to negative power bus on the breadboard.

  • Buzzer

    • +: Connect to breadboard’s positive power bus.

    • -: Connect to transistor.

  • Digital Servo Motor

    • Connect to breadboard’s positive power bus.

    • Connect to breadboard’s negative power bus.

    • Connect to 12 on the Arduino.

  • Ultrasonic Sensor Module

    • Trig: Connect to 10 on the Arduino.

    • Echo: Connect to 11 on the Arduino.

    • GND: Connect to breadboard’s negative power bus.

    • VCC: Connect to breadboard’s red power bus.

Writing the Code

Note

  • Build the circuit.

  • Upload the code to the Arduino board using Arduino IDE.

  • In the Arduino IDE, check the current Arduino port(COMx).

  • The ArduinoRadarGUI is used here. You can click here ArduinoSonarGUI.zip to download it.

  • Open ArduinoLidarGUI.pde in the Processing IDE .

  • Modify the code in line 35 to ensure the correct port number(COMx).

  • Run the Processing sketch to visualize the Lidar data.

/*
  Modified Arduino Radar Code with LED and Buzzer Alerts
*/

#include <Servo.h>

// Ultrasonic sensor pins
const int trigPin = 10;
const int echoPin = 11;

const int servoPin = 12;
Servo myServo;

// LEDs and buzzer pins
const int redLED = 7;
const int greenLED = 6;
const int buzzerPin = 5;

// Distance threshold in cm
const int threshold = 50;

long duration;
int distance;

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(buzzerPin, OUTPUT);

  Serial.begin(9600);
  myServo.attach(servoPin);
}

void loop() {
  for (int i = 15; i <= 165; i++) {
    myServo.write(i);
    delay(30);
    distance = calculateDistance();
    alertSystem(distance);
    sendData(i, distance);
  }
  for (int i = 165; i > 15; i--) {
    myServo.write(i);
    delay(30);
    distance = calculateDistance();
    alertSystem(distance);
    sendData(i, distance);
  }
}

int calculateDistance() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  float distance = pulseIn(echoPin, HIGH) / 58.00;
  return (int)distance;
}

void alertSystem(int dist) {
  if (dist > 0 && dist <= threshold) {
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);

    int beepDelay = map(dist, 1, threshold, 50, 300); // Closer = faster beep
    digitalWrite(buzzerPin, HIGH);
    delay(5);
    digitalWrite(buzzerPin, LOW);
    delay(beepDelay);
  } else {
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, HIGH);
    digitalWrite(buzzerPin, LOW);
  }
}

void sendData(int angle, int dist) {
  Serial.print(angle);
  Serial.print(",");
  Serial.print(dist);
  Serial.print(".");
}