Here is a simple radar system using a BBC micro:bit, an ultrasonic sensor (HC-SR04), and optionally a servo motor to rotate the sensor.

π§ Components Needed
| Component | Quantity |
|---|---|
| BBC micro:bit | 1 |
| Ultrasonic sensor (HC-SR04) | 1 |
| Servo motor (SG90) (optional) | 1 |
| Breadboard & jumper wires | As needed |
| Battery pack for micro:bit | 1 |
π§ Working Principle
- Ultrasonic sensor sends sound waves.
- It measures the time for echo to return.
- Distance is calculated based on speed of sound.
- Optional: The servo motor rotates the sensor to scan an area.
- Micro:bit displays distance on LED screen, or sends data to a graphical interface (like a radar screen on a PC via serial).
π Circuit Diagram
Without Servo:
- VCC (HC-SR04) β 3V (micro:bit)
- GND (HC-SR04) β GND
- Trig β Pin 0
- Echo β Pin 1
With Servo:
- Servo signal wire β Pin 2
- Servo VCC β External 5V source (important!)
- Servo GND β Common ground with micro:bit

π» MakeCode (Blocks or JavaScript)
Here is a basic version using MakeCode JavaScript:
let distance = 0
basic.forever(function () {
pins.digitalWritePin(DigitalPin.P0, 0)
control.waitMicros(2)
pins.digitalWritePin(DigitalPin.P0, 1)
control.waitMicros(10)
pins.digitalWritePin(DigitalPin.P0, 0)
let duration = pins.pulseIn(DigitalPin.P1, PulseValue.High)
distance = duration / 58
basic.showNumber(distance)
basic.pause(500)
})
Note: Use extension for
servomotor if you add one:
Go to Advanced > Extensions > Search forservo.PYTHON CODE
from microbit import *
import timedef measure_distance():
# Trig pin LOW
pin0.write_digital(0)
time.sleep_us(2)# Trig pin HIGH for 10us pin0.write_digital(1) time.sleep_us(10) pin0.write_digital(0) # Echo sΓΌresini oku duration = pin1.read_pulse(PinValue.HIGH) # Mesafeyi cm olarak hesapla distance = (duration / 2) / 29.1 return distancewhile True:
distance = measure_distance()
display.scroll(str(round(distance)) + “cm”)
sleep(500)
π₯οΈ Optional: Radar Display on PC
To visualize data on a radar-style interface:
- Send angle + distance via serial (USB).
- Use Processing or Python with matplotlib/pygame to draw radar lines.
π Learning Outcomes
- Distance measurement using ultrasonic sensor
- Understanding pulseIn() for echo timing
- Data visualization techniques
- Optional: Servo motor control + angle-distance mapping





