Rahul Lodwal
Published © MIT

Radar system using Raspberry Pi pico

A smart Radar System using Raspberry Pi Pico that detects nearby objects in real time using an ultrasonic sensor and displays scanning

BeginnerFull instructions provided3 hours3
Radar system using Raspberry Pi pico

Things used in this project

Hardware components

Raspberry Pi Zero
Raspberry Pi Zero
×1
Ultrasonic Sensor - HC-SR04
SparkFun Ultrasonic Sensor - HC-SR04
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Windows 10 IoT Core
Microsoft Windows 10 IoT Core
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Extraction Tool, 6 Piece Screw Extractor & Screwdriver Set
Extraction Tool, 6 Piece Screw Extractor & Screwdriver Set
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)
Plier, Long Nose
Plier, Long Nose
Breadboard, 170 Pin
Breadboard, 170 Pin
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Custom 3D-Printable Enclosure for Raspberry Pi Pico Radar System

Modular Exploded View: The diagram showcases an Exploded Assembly, highlighting the relationship between the internal electronics (Pico, Servo, Sensor) and the mechanical housing. This layout is essential for understanding how the parts fit during the final assembly stage.
Integrated Rotation Mechanism: The base features a dedicated mounting point for the SG90 Servo Motor. The HC-SR04 sensor is mounted on a custom rotating bracket, ensuring a 180° field of view without the wires getting tangled or the sensor being obstructed by the casing.
Precision I/O Cutouts:
USB Port: A side opening is precisely placed to allow easy access for the Micro-USB/USB-C cable to power and program the Pico.
Wiring Port: A secondary opening is provided for external power or additional peripheral connections.
Thermal Management & Durability: * Ventilation Holes: Small perforated patterns are included on the lid and side walls to prevent heat buildup during continuous operation.
M2.5 Screw Bosses: The enclosure uses standard screw mounting pillars to securely fasten the lid to the base, ensuring the device remains rigid during the high-speed movements of the servo.
Ergonomics & Aesthetics: The design features rounded corners (fillets) for a modern, consumer-ready look while maintaining a compact footprint suitable for desktop prototyping or classroom demonstrations.

Schematics

Raspberry Pi Pico Based Ultrasonic Radar System Wiring Guide

Microcontroller Architecture: The Raspberry Pi Pico acts as the central processing unit, managing the timing for the ultrasonic pulses and the Pulse Width Modulation (PWM) for the servo rotation.
Ultrasonic Sensor (HC-SR04) Interface:
TRIG (GP3): Configured as an Output. It sends a 10µs pulse to trigger the ultrasonic wave.
ECHO (GP2): Configured as an Input. It measures the duration of the returning sound wave to calculate the distance of an object.
Servo Motor (SG90) Control:
SIGNAL (GP15): Utilizes a PWM (Pulse Width Modulation) signal to precisely control the angular position of the sensor, enabling a 180-degree sweep.
Power Distribution:
VCC (5V): Both the sensor and the motor are powered via the VBUS pin (Pin 40), which provides a steady 5V from the USB input.
GND: A common ground is established between all components to ensure a stable reference voltage and signal integrity.
Visual Layout: The diagram uses a top-down logical flow, with color-coded wiring to distinguish between Power (Red), Ground (Black), and Logic signals (Orange/Yellow), making it ideal for educational prototyping.

Code

Radar System using Raspberry Pi Pico and Ultrasonic Sensor

C/C++
This project is a smart mini radar system made using Raspberry Pi Pico, HC-SR04 ultrasonic sensor, and servo motor. The servo rotates the sensor from left to right, while the ultrasonic sensor detects nearby objects and measures their distance in real time. The collected data can be displayed on Serial Monitor or radar visualization software. It is a low-cost and educational project useful for learning embedded systems, automation, robotics, and obstacle detection
#include <Servo.h>

// Pins
const int trigPin = 8;
const int echoPin = 9;
const int servoPin = 10;

// Servo object
Servo radarServo;

// Variables
long duration;
int distance;

void setup() {
  Serial.begin(9600);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  radarServo.attach(servoPin);
}

void loop() {

  // Left to Right Scan
  for (int angle = 15; angle <= 165; angle++) {
    radarServo.write(angle);
    delay(30);

    distance = getDistance();

    Serial.print(angle);
    Serial.print(",");
    Serial.print(distance);
    Serial.print(".");
  }

  // Right to Left Scan
  for (int angle = 165; angle >= 15; angle--) {
    radarServo.write(angle);
    delay(30);

    distance = getDistance();

    Serial.print(angle);
    Serial.print(",");
    Serial.print(distance);
    Serial.print(".");
  }
}

// Distance Function
int getDistance() {

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

  distance = duration * 0.034 / 2;

  return distance;
}

Credits

Rahul Lodwal
1 project • 0 followers

Comments