Arduino Radar Project with OLED Display — Step-by-Step Guide

Learn how to build an Arduino radar project with an OLED display. Includes circuit diagram, full code, pinout, and step-by-step instructions. Buy components from Electronixity — shipped across India.

  • 12 min read

Introduction

Have you ever wanted to build your own mini radar system using an Arduino? In this project, I’ll show you how to build an Arduino radar project using an ultrasonic sensor, a servo motor, and an OLED display.

The working principle is simple. A servo motor rotates the ultrasonic sensor from side to side while the Arduino measures the distance to nearby objects. The OLED display shows a radar-style scanning screen with the current angle, measured distance, and approximate position of detected objects.

This is a fun electronics project for beginners, STEM students, and robotics enthusiasts. It also helps you understand ultrasonic distance measurement, servo motor control, and graphical displays.

I’ve built and tested this project myself, and you can watch the demonstration below to see how it works.

YouTube Video: will be uploaded soon

Below, you’ll find the components list, wiring instructions, complete Arduino code, and troubleshooting tips to help you build your own radar system.

Components Required

You’ll need the following components to build this Arduino radar system.

ComponentQuantityPurchase Link
Arduino Uno1Amazon.com – affiliate link
HC-SR04 ultrasonic sensor1Amazon.com – affiliate link
SG90 micro servo motor1Amazon.com – affiliate link
0.96-inch SSD1306 I2C OLED display, 128 × 64 pixels1Amazon.com – affiliate link
Breadboard1Amazon.com – affiliate link
Male-to-male jumper wiresAs neededAmazon.com – affiliate link
USB cable compatible with Arduino Uno1Amazon.com – affiliate link
Regulated 5V power supply for the servo1, recommendedAmazon.com – affiliate link

How the Main Components Work

Arduino Uno

The Arduino Uno is the main controller of this project. It controls the servo motor, reads distance measurements from the ultrasonic sensor, calculates object positions, and updates the OLED display.

Key specifications:

  • Microcontroller: ATmega328P on the classic Uno R3
  • Operating voltage: 5V
  • Digital I/O pins: 14
  • Analog input pins: 6
  • Clock speed: 16 MHz

HC-SR04 Ultrasonic Sensor

The HC-SR04 measures distance by transmitting ultrasonic sound waves and detecting their reflections from nearby objects.

The Arduino sends a trigger pulse to the sensor. The sensor then emits an ultrasonic burst and produces an echo pulse whose duration depends on how long the sound takes to travel to the object and return.

The distance is calculated using the following formula:

Distance (cm) = Echo duration in microseconds × 0.0343 ÷ 2

The division by two accounts for the sound’s round trip.

Typical HC-SR04 specifications:

  • Operating voltage: 5V
  • Commonly specified measuring range: approximately 2–400 cm
  • Ultrasonic frequency: 40 kHz
  • Trigger pulse: at least 10 microseconds

Actual detection range depends on the object’s size, surface, angle, and surrounding conditions.

SG90 Servo Motor

The SG90 servo motor rotates the ultrasonic sensor horizontally. The Arduino commands the servo to move to different angles, allowing the sensor to scan a wider area.

Typical specifications:

  • Operating voltage: approximately 4.8–6V, depending on the model
  • Movement range: approximately 180 degrees for many versions
  • Control method: servo position pulses

The actual movement range depends on the servo model. Avoid forcing the shaft beyond its mechanical limits.

OLED Display

The OLED display provides a visual representation of the radar scan. It shows the current scanning angle, measured distance, radar arcs, and the approximate location of detected objects.

This project uses a 128 × 64-pixel SSD1306 I2C OLED display. Most modules use I2C address 0x3C, although some use 0x3D.

Wiring Connections

Before making connections, disconnect the Arduino from USB power.

HC-SR04 to Arduino Uno

HC-SR04 PinArduino Uno Pin
VCC5V
GNDGND
TRIGDigital pin 10
ECHODigital pin 11

SG90 Servo Motor to Arduino Uno

Servo WireConnection
RedRegulated 5V supply
Brown or blackGND
Orange, yellow, or whiteDigital pin 9

Wire colors may vary, so check your servo’s documentation.

A servo can draw more current than the Arduino’s onboard 5V supply can comfortably provide. If the Arduino resets or the OLED flickers, use a suitable regulated 5V external supply for the servo. Connect the external supply’s ground to Arduino GND. Do not connect two independent 5V power outputs together.

OLED Display to Arduino Uno

OLED PinArduino Uno R3 Pin
VCC5V, if supported by the module; otherwise use its specified voltage
GNDGND
SDAA4
SCLA5

These SDA and SCL connections apply to the classic Arduino Uno R3.

Double-check the connections before powering on the circuit. Make sure the sensor can rotate freely without pulling on the wires.

Library Installation

This project requires the Servo, Adafruit GFX, and Adafruit SSD1306 libraries.

Step 1: Install Arduino IDE

Download and install the Arduino IDE from the official website:

https://www.arduino.cc/en/software

Connect your Arduino Uno to your computer using a USB cable.

Step 2: Install Adafruit SSD1306

  1. Open Arduino IDE.
  2. Go to Sketch > Include Library > Manage Libraries.
  3. Search for Adafruit SSD1306.
  4. Install the library by Adafruit.

Step 3: Install Adafruit GFX

Search for Adafruit GFX Library in Library Manager and install it.

Install any additional dependencies if prompted.

Step 4: Check the Servo Library

The Servo library is usually included with the Arduino IDE. If it is missing, search for Servo in Library Manager and install it.

Complete Arduino Radar Project Code

The following sketch is designed for an Arduino Uno, HC-SR04 ultrasonic sensor, SG90 servo motor, and SSD1306 I2C OLED display.

The servo scans from 0 to 180 degrees and then returns to the starting position. At each angle, the Arduino measures the distance and displays a radar-style visualization.

Code
1#include <Wire.h>2#include <Adafruit_GFX.h>3#include <Adafruit_SSD1306.h>4#include <Servo.h>5 6// -------------------- OLED CONFIG --------------------7#define SCREEN_WIDTH 1288#define SCREEN_HEIGHT 649Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);   // -1 = no reset pin10 11// Radar origin (bottom center of screen)12const int ORIGIN_X = SCREEN_WIDTH / 2;13const int ORIGIN_Y = SCREEN_HEIGHT - 1;14const int RADAR_RADIUS = 60;      // max radius in pixels (should fit inside 64px height)15 16// -------------------- PINS --------------------17const int SERVO_PIN = 3;18const int TRIG_PIN  = 12;19const int ECHO_PIN  = 11;20 21// -------------------- SERVO CONFIG --------------------22const int MIN_ANGLE = 15;23const int MAX_ANGLE = 165;24 25Servo radarServo;26int servoAngle = MIN_ANGLE;   // starting angle27int servoStep  = 1;           // step per frame28bool sweepingForward = true;  // true: MIN_ANGLE -> MAX_ANGLE, false: back29 30// -------------------- ULTRASONIC CONFIG --------------------31const float MAX_DISTANCE_CM = 30.0; // anything farther is "no object"32 33// -------------------- FUNCTIONS --------------------34 35// Simple typing animation for a given text and total duration36void showTypingAnimation(const char* msg, uint16_t totalDurationMs)37{38  uint8_t len = strlen(msg);39  if (len == 0) return;40 41  // Calculate delay per character so full word takes ~totalDurationMs42  uint16_t perCharDelay = totalDurationMs / len;43 44  display.clearDisplay();45  display.setTextSize(1);46  display.setTextColor(WHITE);47 48  // Vertically center the text (roughly)49  uint8_t y = (SCREEN_HEIGHT - 8) / 2; // 8px font height50  display.setCursor((SCREEN_WIDTH - (len * 6)) / 2, y);51  // 6px per char (5px width + 1px space) for default font52 53  Serial.println(F("[SPLASH] Showing 'Alpha Electronz' typing animation"));54 55  for (uint8_t i = 0; i < len; i++) {56    display.print(msg[i]);57    display.display();58    delay(perCharDelay);59  }60 61  // small extra hold (optional)62  delay(300);63}64 65float readDistanceCm()66{67  // Trigger ultrasonic pulse68  digitalWrite(TRIG_PIN, LOW);69  delayMicroseconds(2);70  digitalWrite(TRIG_PIN, HIGH);71  delayMicroseconds(10);72  digitalWrite(TRIG_PIN, LOW);73 74  // Read echo time (timeout ~25ms => ~4m)75  long duration = pulseIn(ECHO_PIN, HIGH);76 77  if (duration == 0) {78    // No echo received in time79    Serial.println(F("[US] Timeout: no echo"));80    return -1;81  }82 83  // Convert time to distance (cm)84  float distance = duration / 58.0;  // HC-SR04 constant85 86  Serial.print(F("[US] duration="));87  Serial.print(duration);88  Serial.print(F(" us, distance="));89  Serial.print(distance);90  Serial.println(F(" cm"));91 92  return distance;93}94 95// Draw static radar circles and baseline96void drawRadarGrid()97{98  // Concentric circles99  display.drawCircle(ORIGIN_X, ORIGIN_Y, RADAR_RADIUS, WHITE);100  display.drawCircle(ORIGIN_X, ORIGIN_Y, RADAR_RADIUS * 2 / 3, WHITE);101  display.drawCircle(ORIGIN_X, ORIGIN_Y, RADAR_RADIUS / 3, WHITE);102 103  // Baseline (left-right)104  display.drawLine(ORIGIN_X - RADAR_RADIUS, ORIGIN_Y,105                   ORIGIN_X + RADAR_RADIUS, ORIGIN_Y, WHITE);106}107 108// Map servo angle to radar sweep angle (0..180° left->right)109float servoAngleToRad(int angle)110{111  // Clamp to valid range112  if (angle < MIN_ANGLE) angle = MIN_ANGLE;113  if (angle > MAX_ANGLE) angle = MAX_ANGLE;114 115  // Map servo angle (MIN_ANGLE..MAX_ANGLE) to display angle (0..180)116  // 0° -> right, 90° -> up, 180° -> left117  long displayDeg = map(angle, MIN_ANGLE, MAX_ANGLE, 0, 180);118 119  // NO extra inversion here – so sweep direction matches servo movement120  float rad = displayDeg * PI / 180.0;121  return rad;122}123 124void setup()125{126  Serial.begin(9600);127  Serial.println(F("\n=== Radar Setup Start ==="));128 129  pinMode(TRIG_PIN, OUTPUT);130  pinMode(ECHO_PIN, INPUT);131 132  radarServo.attach(SERVO_PIN);133  radarServo.write(servoAngle);134  Serial.print(F("[SERVO] Initial angle: "));135  Serial.println(servoAngle);136  delay(500);137 138  // OLED init139  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {140    Serial.println(F("[OLED] SSD1306 allocation failed!"));141    // If OLED init fails, stay here142    while (true) {143      pinMode(LED_BUILTIN, OUTPUT);144      digitalWrite(LED_BUILTIN, HIGH);145      delay(200);146      digitalWrite(LED_BUILTIN, LOW);147      delay(200);148    }149  }150 151  Serial.println(F("[OLED] SSD1306 initialized OK."));152  Serial.println(F("=== Radar Setup Done ==="));153 154  // --- Typing splash for "Alpha Electronz" ---155  showTypingAnimation("Alpha Electronz", 5000); // ~5 seconds total156 157  // Then show radar initializing and start normal project158  display.clearDisplay();159  display.setTextSize(1);160  display.setTextColor(WHITE);161  display.setCursor(0, 0);162  display.println(F("Radar Initializing..."));163  display.display();164  delay(1000);165}166 167void loop()168{169  // Move servo to current angle170  radarServo.write(servoAngle);171  Serial.print(F("[SERVO] Angle: "));172  Serial.println(servoAngle);173  delay(15);  // small delay for smooth motion174 175  // Read distance176  float distance = readDistanceCm();177  bool objectDetected = false;178 179  if (distance > 0 && distance <= MAX_DISTANCE_CM) {180    objectDetected = true;181    Serial.print(F("[OBJ] Detected at "));182    Serial.print(distance);183    Serial.println(F(" cm"));184  } else {185    Serial.println(F("[OBJ] No valid object in range"));186    distance = MAX_DISTANCE_CM; // clamp for drawing187  }188 189  // Prepare drawing190  display.clearDisplay();191 192  // Draw grid193  drawRadarGrid();194 195  // Calculate radar line angle196  float rad = servoAngleToRad(servoAngle);197 198  // End point of radar sweep line (max radius)199  int endX = ORIGIN_X + (int)(RADAR_RADIUS * cos(rad));200  int endY = ORIGIN_Y - (int)(RADAR_RADIUS * sin(rad)); // minus because screen Y grows downward201 202  // Draw sweeping line203  display.drawLine(ORIGIN_X, ORIGIN_Y, endX, endY, WHITE);204 205  // If object detected, draw a blip on the line206  if (objectDetected) {207    float normalized = distance / MAX_DISTANCE_CM;208    if (normalized > 1.0) normalized = 1.0;209    int rTarget = (int)(RADAR_RADIUS * normalized);210 211    int objX = ORIGIN_X + (int)(rTarget * cos(rad));212    int objY = ORIGIN_Y - (int)(rTarget * sin(rad));213 214    display.fillCircle(objX, objY, 2, WHITE);215 216    // Show text info217    display.setTextSize(1);218    display.setCursor(0, 0);219    display.print(F("OBJ: "));220    display.print((int)distance);221    display.println(F("cm"));222 223    display.setCursor(0, 10);224    display.print(F("Angle: "));225    display.print(servoAngle);226    display.println(F(" deg"));227  } else {228    display.setTextSize(1);229    display.setCursor(0, 0);230    display.println(F("No object"));231    display.setCursor(0, 10);232    display.print(F("Angle: "));233    display.print(servoAngle);234    display.println(F(" deg"));235  }236 237  display.display();238 239  // Update servo angle for next frame (back-and-forth sweep)240  if (sweepingForward) {241    servoAngle += servoStep;242    if (servoAngle >= MAX_ANGLE) {243      servoAngle = MAX_ANGLE;244      sweepingForward = false;245      Serial.println(F("[SERVO] Reached max, reversing sweep"));246    }247  } else {248    servoAngle -= servoStep;249    if (servoAngle <= MIN_ANGLE) {250      servoAngle = MIN_ANGLE;251      sweepingForward = true;252      Serial.println(F("[SERVO] Reached min, reversing sweep"));253    }254  }255 256  // Small delay to control sweep speed (tune as you like)257  delay(10);258}

Important: If your OLED uses I2C address 0x3D instead of 0x3C, change the OLED_ADDRESS definition. This sketch displays the current scan and measurement rather than keeping a history of previously detected objects

Testing the Project

After uploading the code, follow these steps.

  1. Connect the Arduino to your computer or a suitable power source.
  2. Confirm that the OLED displays the startup message.
  3. Check whether the servo rotates the sensor from side to side.
  4. Place a flat object approximately 30–50 cm in front of the sensor.
  5. Observe the OLED as the sensor scans toward the object.
  6. Move the object closer or farther away and observe how the displayed position changes.

Expected results:

  • The servo continuously scans between 0 and 180 degrees.
  • The OLED displays the current angle and measured distance.
  • A target dot appears when an object is detected within the configured display range.
  • The dot moves closer to or farther from the radar center as the measured distance changes.

Keep in mind that the sensor measures one direction at a time, so the object marker updates as the servo reaches the object’s direction.

Troubleshooting

Problem 1: OLED Display Is Blank

Possible causes: Incorrect I2C address, reversed SDA/SCL connections, incorrect power, or an incompatible display controller.

Solution: Check the wiring and confirm the OLED uses the SSD1306 controller. Try address 0x3D if 0x3C does not work. An I2C scanner sketch can help identify the correct address.

Problem 2: Servo Motor Does Not Rotate

Possible causes: Incorrect signal pin, insufficient current, loose wiring, or missing common ground.

Solution: Verify that the signal wire connects to digital pin 9. Check the servo power supply and connect the external supply’s ground to Arduino GND. Test the servo separately if necessary.

Problem 3: Incorrect Distance Readings

Possible causes: Poor target angle, soft surfaces, excessive distance, or sensor movement during measurement.

Solution: Test with a large, flat object placed directly in front of the sensor. Increase the servo settling delay if necessary and check the sensor connections.

Problem 4: Radar Dots Appear in the Wrong Direction

Possible causes: Incorrect sensor mounting or a different servo orientation.

Solution: Check which physical direction corresponds to 0 and 180 degrees. Adjust the angle mapping if the displayed radar is mirrored.

Problem 5: Arduino Resets or OLED Flickers

Possible causes: Insufficient power for the servo or loose connections.

Solution: Use a regulated 5V supply with sufficient current for the servo and connect its ground to Arduino GND. Avoid overloading the Arduino’s onboard 5V supply.

Ideas to Expand the Project

Once your basic radar is working, you can add more features.

  1. PC Radar Visualization: Send the angle and distance readings to a computer and create a more detailed radar interface using Python and Pygame.
  2. Buzzer Alert: Add a buzzer to sound when an object is detected within a specified distance.
  3. Obstacle-Avoidance Robot: Mount the sensor on a mobile robot and use the measurements to help the robot navigate around obstacles.
  4. Persistent Target Tracking: Store previous measurements and redraw detected objects across multiple frames to create a radar trail.
  5. Wireless Monitoring: Add an ESP32 or another wireless module to transmit measurements to a computer or mobile dashboard.

These upgrades can help you learn more about robotics, embedded programming, and sensor integration.

Frequently Asked Questions

How do you make an Arduino radar using an ultrasonic sensor?

Connect an HC-SR04 ultrasonic sensor to an Arduino, mount it on a servo motor, and program the Arduino to scan different angles while measuring distance. An OLED display can show the scan direction and approximate object positions.

Can I make an Arduino radar without an OLED display?

Yes. You can send angle and distance measurements to the Serial Monitor or a computer-based visualization. An OLED is useful if you want a standalone radar display.

What is the maximum range of an Arduino ultrasonic radar?

The HC-SR04 is commonly specified for approximately 2–400 cm under suitable conditions. Actual performance varies with the target and environment. This tutorial uses a 200 cm display range.

Why is a servo motor used in an Arduino radar project?

The servo rotates the ultrasonic sensor so it can measure distances in multiple directions. Without the servo, the sensor generally measures objects within its fixed detection area.

Is an Arduino ultrasonic radar the same as a real radar system?

No. This project uses ultrasonic sound waves rather than radio waves. It recreates the scanning and visualization concept of radar for educational purposes, but it is not a true radio radar system.

Conclusion

This Arduino radar project is a great way to explore ultrasonic distance measurement, servo motor control, and OLED graphics using affordable electronics components.

With an Arduino Uno, an HC-SR04 ultrasonic sensor, an SG90 servo motor, and a small OLED display, you can build a working radar-style scanning system and learn how the different components communicate.

Start with the basic circuit, test the code, and experiment with different distances and angles. Once everything works, you can add a buzzer, a computer visualization, wireless monitoring, or persistent target tracking.

Watch the project demonstration on YouTube to see the radar in action. If you found this tutorial useful, please like the video, subscribe to the channel, and leave a comment with your questions or suggestions for future Arduino projects.