Skip to content

Desk Sonar Sweeper

A little sweeping sound sensor that draws a radar screen and beeps when something gets close.

Try it

Simulated time

Behavior simulation: shows what it should do. It does not run the code.

Try this: Drag the object distance below 30 cm and listen: the buzzer beeps each sweep, faster as you move it closer. Press the button to change the alarm distance.

Controls

  • Object distance in front of the sensor80 cm
  • Object angle (where the object sits)90 deg
  • Alarm distance button (15 / 30 / 50 cm)

What it does

Servo angle
Sensor cradle angle
Radar screen
Buzzer
Something too close
Dot distance on screen
Alarm distance setting
Screen on

What it does

A small ultrasonic distance sensor sits on a servo that sweeps from side to side, 0 to 180 degrees. At each angle it measures how far away things are, and a small OLED screen draws a radar-style fan with a sweep line and dots where objects are. If something comes closer than a distance you set, a buzzer beeps, and the beeps get faster the closer it is. It comes fully built in a small case and runs off USB power.

Try it above: Drag the object distance below 30 cm and listen: the buzzer beeps each sweep, faster as you move it closer. Press the button to change the alarm distance.

Safety

  • Small moving servo arm could pinch small fingers (very low force)
  • Small parts; not for children under 3
  • Buzzer can be loud close to the ears; mute switch included

What’s inside

23 parts. We buy, make and put these together for you.

Brain

Runs the program and makes the decisions.

$25.70
  • Arduino Nano1×

    $25.70

    The small brain that moves the servo, reads the distance, draws the radar picture and sounds the beeper.

    • 18 × 45 × 8 mm
    • Firmware: arduino-cpp, pre-loaded
    • Runs on: 5 to 12 V
    • Draws: about 20 mA
    • Weight: 7 g
    list price, checked Oct 5, 2026 at a generic supplierView

Senses

Measures the world around it.

$3.95
  • HC-SR04 ultrasonic distance sensor (5 V)1×

    $3.95

    Sends out a click of sound too high to hear and times the echo to tell how far away things are.

    • 46 × 20 × 16 mm
    • Logic: 5 V, matches the Nano, no level shifter needed
    • Range: 2 to 200 cm used
    • Runs on: 4.5 to 5.5 V
    • Draws: about 15 mA
    list price, checked Oct 5, 2026 at AdafruitView

Controls

What you press, turn or flip.

$2.65
  • Panel-mount push button, 16 mm1×

    $0.95

    Press to change the alarm distance between 15, 30 and 50 cm.

    • 18 × 18 × 29 mm
    • Pullup: uses the board's built-in pull-up
    • Runs on: 0 to 12 V
    • Weight: 4.6 g
    list price, checked Oct 5, 2026 at AdafruitView
  • Panel slide switch, SPDT (mute)1×

    $0.80

    Slide it to silence the buzzer completely.

    • 20 × 6 × 10 mm
    • Type: SPDT panel-mount slide switch
    estimate
  • Mini rocker power switch1×

    $0.90

    Turns the whole radar on and off.

    • 15 × 5 × 10 mm
    • Rating: 3 A 12 V DC
    estimate

Lights, sound and screen

How it tells you what it is doing.

$11.93
  • SH1106 1.3" OLED, 128x64, I2C1×

    $10.98

    Draws the radar fan, the sweep line, the dots and the numbers.

    • 35 × 30 × 10 mm
    • I2c addr: 0x3C
    • Resolution: 128x64
    • Runs on: 3.3 to 5 V
    • Draws: about 25 mA
    list price, checked Oct 6, 2026 at AmazonView
  • Active buzzer, 5 V1×

    $0.95

    Beeps when something is too close, faster as it gets closer.

    • 12 × 12 × 10 mm
    • Runs on: 3 to 5.5 V
    • Draws: about 25 mA
    list price, checked Oct 5, 2026 at AdafruitView

Motion

Everything that moves.

$8.98
  • SG90 micro servo, 9 g1×

    $7.98

    Turns the sensor smoothly from side to side, 0 to 180 degrees.

    • 32 × 12 × 30 mm
    • Sweep: 0-180 degrees
    • Runs on: 4.8 to 6 V
    • Draws: about 150 mA
    • Weight: 9 g

    Pack of 4, you use 1, the 3 spares are yours.

    list price, checked Oct 5, 2026 at AmazonView
  • 3D printed sensor cradle1×

    $1.00

    Holds the distance sensor on top of the servo so it turns with it.

    • 48 × 18 × 24 mm
    • Material: PLA
    Made by usestimate

Power

Where its energy comes from.

$8.50
  • USB-C 5 V power input board1×

    $2.50

    The socket on the case where the USB cable plugs in to power everything.

    • 18 × 5 × 14 mm
    • Mount: screwed into case wall
    • Voltage: 5 V
    estimate
  • USB wall charger, 5 V 2 A1×

    $6.00

    Plugs into the wall and gives the radar safe 5 V power.

    • 28 × 27 × 28 mm
    • Output: 5 V 2 A, UL listed
    estimate

Small electronics and wiring

Resistors, connectors and cables that join it all up.

$40.59
  • PN2222 NPN transistor (2N2222 equivalent)1 packs

    $1.95

    Acts as a small switch so the buzzer's current does not strain the board's pin.

    • 5 × 4 × 5 mm
    • Runs on: 0 to 40 V
    list price, checked Oct 5, 2026 at AdafruitView
  • Resistor 1 kΩ, 1/4 W, 5 %1×

    $0.75

    Limits the current from the board into the buzzer transistor.

    • 6 × 3 × 3 mm
    • Value: 1 kohm
    • Runs on: 0 to 300 V

    Pack of 25, you use 1, the 24 spares are yours.

    list price, checked Oct 5, 2026 at AdafruitView
  • Electrolytic capacitor 100 µF 25 V1×

    $7.99

    Smooths the power when the servo starts moving so the board does not reset.

    • 6 × 6 × 11 mm
    • Value: 100 uF 25 V
    • Runs on: 0 to 25 V

    Pack of 50, you use 1, the 49 spares are yours.

    list price, checked Oct 6, 2026 at AmazonView
  • USB-C cable, 1.5 m1×

    $3.00

    Connects the radar to a USB charger.

    • 12 × 22 × 7 mm
    • Length: 1500 mm
    estimate
  • Perma-Proto half-size solderable breadboard PCB1×

    $4.50

    A sturdy board inside the case where all the parts are joined together.

    • 81 × 51 × 2 mm
    • Weight: 12 g
    list price, checked Oct 5, 2026 at AdafruitView
  • Female pin headers, 2.54 mm strip1 sets

    $1.50

    Lets the Nano plug into the circuit board so it can be replaced.

    estimate
  • Hook-up wire 22 AWG solid core, 6 x 25 ft1 sets

    $15.95

    Neat wires inside the case connecting sensor, screen, switches and power.

    • 25 × 5.1 × 5.1 cm
    • Weight: 340.7 g
    list price, checked Oct 5, 2026 at AdafruitView
  • Heat-shrink tubing assortment1 packs

    $4.95

    Covers wire joints so nothing can short.

    • 15 × 0.5 × 0.5 cm
    list price, checked Oct 5, 2026 at AdafruitView

Body and structure

The case, frame and panels.

$4.00
  • 3D printed case with lid1×

    $4.00

    Holds everything, with a window for the screen and holes for the button, switches and USB socket.

    • 12 × 11 × 4.8 cm
    • Size: 120 x 50 x 110
    • Material: PLA
    Made by usestimate

Fixings

Screws, bolts and ties that hold it together.

$16.34
  • Brass heat-set insert, M3 x 4 mm8×

    $5.95

    Strong metal threads in the plastic case for the screws.

    • 4 × 4 × 4 mm

    Pack of 50, you use 8, the 42 spares are yours.

    list price, checked Oct 5, 2026 at AdafruitView
  • M3 socket head screw (6-30 mm)12×

    $9.99

    Hold the lid, circuit board, screen and servo in place.

    • 6 × 6 × 13 mm
    • Length: 8-12

    Pack of 1120, you use 12, the 1108 spares are yours.

    list price, checked Oct 5, 2026 at AmazonView
  • Rubber bumper feet4×

    $0.40

    Stop the radar sliding on the desk when the servo moves.

    • 11 × 9.8 × 0.3 cm
    estimate

Parts total (23 lines)

$122.64

$102.54 from supplier list prices, $20.10 estimated. Preparation and shipping are added when you order.

How it goes together

The step-by-step instructions that come with your order, 2 steps. Try them here first.

Before you start

Desk Sonar Sweeper goes together in 2 steps, about 5 min in all. No soldering and no coding.

Already done in our workshop

  • Print the case and sensor cradle
  • Build the main circuit board
  • Wire the panel parts
  • Mount everything in the case
  • Fit the sensor on the servo
  • Load the program and test
  • Close up and pack

2 steps

Code

The code it runs1 file, 297 lines. We load it onto the board for you.

Uses: U8g2, Servo

RadarSweep.ino
/*  ===========================================================================  Tinkerly - Mini Sonar Radar  ===========================================================================  What this program does (in plain words):   - A small servo motor swings an ultrasonic distance sensor slowly from    0 to 180 degrees and back again, forever (about 90 degrees per second).  - Every few degrees the sensor measures how far away things are    (it can see from about 2 cm up to 200 cm).  - The 1.3 inch screen draws a half-circle "radar" picture: range rings,    a moving sweep line, and a dot wherever something was found.    The top line shows the current angle, the alarm distance and the    measured distance as numbers.  - When the sweep line passes an angle again, the old dot there is replaced    by the new reading, so the picture always stays up to date.  - If anything on the screen is closer than the alarm distance    (30 cm to start with) the buzzer beeps. The closer it is, the faster    it beeps.  - Pressing the round button cycles the alarm distance: 15 -> 30 -> 50 cm.    The new setting is shown big on the screen for 2 seconds.  - No echo, or something further than 200 cm, means: no dot, no beep.  - The MUTE slide switch on the case cuts the buzzer's power directly,    so it works even without the program knowing about it.   Wiring used (Arduino Nano):    D2 -> sensor TRIG        D3 -> sensor ECHO    D4 -> buzzer transistor (through 1 kOhm resistor)    D5 -> servo signal       D7 -> push button (other side to GND)    A4 -> screen SDA         A5 -> screen SCL   Libraries: U8g2 (screen), Servo (built into the Arduino IDE).  ===========================================================================*/ #include <Arduino.h>#include <Wire.h>#include <Servo.h>#include <U8g2lib.h> // ---------------------------------------------------------------------------// Pins (must match the wiring list exactly)// ---------------------------------------------------------------------------const uint8_t PIN_TRIG   = 2;const uint8_t PIN_ECHO   = 3;const uint8_t PIN_BUZZER = 4;const uint8_t PIN_SERVO  = 5;const uint8_t PIN_BUTTON = 7; // ---------------------------------------------------------------------------// Settings you might want to tweak// ---------------------------------------------------------------------------const uint8_t  ANGLE_STEP     = 3;     // degrees moved per stepconst uint16_t STEP_MS        = 33;    // time per step -> about 90 deg/secondconst uint8_t  MAX_RANGE_CM   = 200;   // anything further is ignoredconst uint8_t  MIN_RANGE_CM   = 2;     // anything closer is not trustedconst uint32_t ECHO_TIMEOUT_US = 12500; // ~215 cm round trip, then give upconst uint16_t MESSAGE_MS     = 2000;  // how long the alarm setting is shownconst uint8_t  DEBOUNCE_MS    = 30;    // ignore button bounce // The three alarm distances the button cycles throughconst uint8_t ALARM_CHOICES[3] = {15, 30, 50}; // One memory slot per angle step: 0..180 in steps of 3 = 61 slotsconst uint8_t NUM_SLOTS = 180 / ANGLE_STEP + 1; // ---------------------------------------------------------------------------// Screen geometry for the radar fan// ---------------------------------------------------------------------------const int16_t CX = 64;      // centre of the half circle (bottom middle)const int16_t CY = 63;const int16_t RADIUS = 52;  // pixels that represent 200 cm // ---------------------------------------------------------------------------// Objects// ---------------------------------------------------------------------------// SH1106 128x64 screen on the hardware I2C pins (A4/A5), full picture bufferU8G2_SH1106_128X64_NONAME_F_HW_I2C display(U8G2_R0, U8X8_PIN_NONE);Servo sweepServo; // ---------------------------------------------------------------------------// Program state// ---------------------------------------------------------------------------uint8_t  dots[NUM_SLOTS];      // distance in cm found at each angle (0 = none)int16_t  sweepAngle = 0;       // where the servo is pointing nowint8_t   sweepDir   = 1;       // +1 = going up, -1 = going downuint8_t  lastDistance = 0;     // latest reading (0 = nothing)uint8_t  alarmIndex = 1;       // start at 30 cmuint32_t lastStepMs = 0;uint32_t messageUntil = 0;     // show the alarm setting until this time // Button debouncebool     buttonStable = HIGH;bool     buttonLastRaw = HIGH;uint32_t buttonChangedMs = 0; // Buzzer timinguint32_t beepCycleStart = 0; // ---------------------------------------------------------------------------// Measure the distance once with the ultrasonic sensor.// Returns cm (2..200) or 0 if nothing useful came back.// ---------------------------------------------------------------------------uint8_t measureDistanceCm() {  digitalWrite(PIN_TRIG, LOW);  delayMicroseconds(2);  digitalWrite(PIN_TRIG, HIGH);      // a 10 microsecond "ping"  delayMicroseconds(10);  digitalWrite(PIN_TRIG, LOW);   // Wait for the echo, but never longer than ~12 ms  unsigned long echoUs = pulseIn(PIN_ECHO, HIGH, ECHO_TIMEOUT_US);  if (echoUs == 0) return 0;         // no echo = nothing in range   unsigned long cm = echoUs / 58;    // sound: ~58 us per cm there and back  if (cm < MIN_RANGE_CM || cm > MAX_RANGE_CM) return 0;  return (uint8_t)cm;} // ---------------------------------------------------------------------------// Turn an angle + distance into a point on the screen// (0 degrees = right side of the fan, 180 = left side)// ---------------------------------------------------------------------------void polarToScreen(int16_t angleDeg, int16_t radiusPx, int16_t &x, int16_t &y) {  float rad = angleDeg * (PI / 180.0);  x = CX + (int16_t)(radiusPx * cos(rad));  y = CY - (int16_t)(radiusPx * sin(rad));} // ---------------------------------------------------------------------------// Find the closest object currently on the radar (0 = none)// ---------------------------------------------------------------------------uint8_t closestDot() {  uint8_t best = 0;  for (uint8_t i = 0; i < NUM_SLOTS; i++) {    if (dots[i] > 0 && (best == 0 || dots[i] < best)) best = dots[i];  }  return best;} // ---------------------------------------------------------------------------// Draw the whole screen// ---------------------------------------------------------------------------void drawScreen(uint8_t closest) {  uint8_t alarmCm = ALARM_CHOICES[alarmIndex];  char line[24];   display.clearBuffer();   // --- Big message after pressing the button ---  if (millis() < messageUntil) {    display.setFont(u8g2_font_6x10_tf);    display.drawStr(22, 14, "ALARM DISTANCE");    display.setFont(u8g2_font_logisoso24_tf);    snprintf(line, sizeof(line), "%u cm", alarmCm);    int16_t w = display.getStrWidth(line);    display.drawStr((128 - w) / 2, 52, line);    display.sendBuffer();    return;  }   // --- Top line: angle, alarm setting, distance ---  display.setFont(u8g2_font_5x7_tf);  if (lastDistance > 0) {    snprintf(line, sizeof(line), "%3ddeg ALM%2u %3ucm", sweepAngle, alarmCm, lastDistance);  } else {    snprintf(line, sizeof(line), "%3ddeg ALM%2u ---cm", sweepAngle, alarmCm);  }  bool tooClose = (closest > 0 && closest < alarmCm);  if (tooClose) {    // Inverted top bar = warning: something is too close    display.drawBox(0, 0, 128, 9);    display.setDrawColor(0);    display.drawStr(10, 7, line);    display.setDrawColor(1);  } else {    display.drawStr(10, 7, line);  }   // --- Radar fan: half circles for 50/100/150/200 cm and a base line ---  for (uint8_t ring = 1; ring <= 4; ring++) {    int16_t r = (RADIUS * ring) / 4;    display.drawCircle(CX, CY, r, U8G2_DRAW_UPPER_LEFT | U8G2_DRAW_UPPER_RIGHT);  }  display.drawHLine(CX - RADIUS, CY, RADIUS * 2 + 1);   // --- Dots for every object found ---  for (uint8_t i = 0; i < NUM_SLOTS; i++) {    if (dots[i] == 0) continue;    int16_t r = ((int16_t)dots[i] * RADIUS) / MAX_RANGE_CM;    int16_t x, y;    polarToScreen(i * ANGLE_STEP, r, x, y);    display.drawDisc(x, y, 1);  }   // --- The moving sweep line ---  int16_t sx, sy;  polarToScreen(sweepAngle, RADIUS, sx, sy);  display.drawLine(CX, CY, sx, sy);   display.sendBuffer();} // ---------------------------------------------------------------------------// Button: change alarm distance on each press (debounced, no delay())// ---------------------------------------------------------------------------void handleButton() {  bool raw = digitalRead(PIN_BUTTON);  if (raw != buttonLastRaw) {    buttonLastRaw = raw;    buttonChangedMs = millis();  }  if ((millis() - buttonChangedMs) > DEBOUNCE_MS && raw != buttonStable) {    buttonStable = raw;    if (buttonStable == LOW) {               // pressed (pulls to GND)      alarmIndex = (alarmIndex + 1) % 3;     // 15 -> 30 -> 50 -> 15      messageUntil = millis() + MESSAGE_MS;    }  }} // ---------------------------------------------------------------------------// Buzzer: beep faster the closer the nearest object is// ---------------------------------------------------------------------------void handleBuzzer(uint8_t closest) {  uint8_t alarmCm = ALARM_CHOICES[alarmIndex];  if (closest == 0 || closest >= alarmCm) {    digitalWrite(PIN_BUZZER, LOW);           // nothing too close: quiet    return;  }  // Beep period: 120 ms when very close, up to 800 ms near the alarm edge  long period = map(closest, MIN_RANGE_CM, alarmCm, 120, 800);  period = constrain(period, 120, 800);   uint32_t now = millis();  if (now - beepCycleStart >= (uint32_t)period) beepCycleStart = now;  bool on = (now - beepCycleStart) < (uint32_t)(period / 2);  // on half the time  digitalWrite(PIN_BUZZER, on ? HIGH : LOW);} // ---------------------------------------------------------------------------// Setup: runs once at power-on// ---------------------------------------------------------------------------void setup() {  pinMode(PIN_TRIG, OUTPUT);  pinMode(PIN_ECHO, INPUT);  pinMode(PIN_BUZZER, OUTPUT);  digitalWrite(PIN_BUZZER, LOW);  pinMode(PIN_BUTTON, INPUT_PULLUP);         // button pulls the pin to GND   for (uint8_t i = 0; i < NUM_SLOTS; i++) dots[i] = 0;   display.setBusClock(400000);               // fast I2C for smooth drawing  display.begin();   sweepServo.attach(PIN_SERVO);  sweepServo.write(0);                       // start at one end   // Short start-up screen while the servo reaches its start point  display.clearBuffer();  display.setFont(u8g2_font_6x10_tf);  display.drawStr(28, 30, "SONAR RADAR");  display.drawStr(34, 46, "starting...");  display.sendBuffer();  delay(600);                                // one-time, at start-up only   lastStepMs = millis();} // ---------------------------------------------------------------------------// Main loop: everything is timed with millis(), nothing waits long// ---------------------------------------------------------------------------void loop() {  handleButton();   uint32_t now = millis();  if (now - lastStepMs >= STEP_MS) {    lastStepMs = now;     // 1) Measure at the angle the servo has just reached    lastDistance = measureDistanceCm();    dots[sweepAngle / ANGLE_STEP] = lastDistance;   // replaces the old dot     // 2) Move on to the next angle, turning around at the ends    sweepAngle += sweepDir * ANGLE_STEP;    if (sweepAngle >= 180) { sweepAngle = 180; sweepDir = -1; }    if (sweepAngle <= 0)   { sweepAngle = 0;   sweepDir = 1;  }    sweepServo.write(sweepAngle);     // 3) Redraw the radar picture    drawScreen(closestDot());  }   // Buzzer is checked every loop so the beep rhythm stays even  handleBuzzer(closestDot());} 

Comments

No comments yet

Ask the maker a question, or say what you would change. Comments are public.

Sign in to comment. It is free.

More in games

See all in Games