Radar

The Radar project is an ideal tool for understanding the basics of robotics. It shows how to connect a servo motor, an ultrasonic sensor and an LED strip to create a device that maps the environment. The radar gradually rotates, measures the distance to objects and converts it into a light signal. It is suitable for all ages and does not require any previous knowledge of electronics.

Description

Ultrasonic distance sensor (Sonar) allows you to measure the distance of objects by reflecting a sound pulse. The sensor sends a short ultrasonic signal that is reflected from the obstacle and returns. From the measured return time and the speed of sound, the distance is calculated according to the relationship: distance = (time × speed of sound) / 2

Connection

Ultrasonic sensor (US-015)

VCC: Connect the 3V3 output of the micro:bit - it provides power to the sensor.
GND: connect to GND pin MB3.
Trig: connect to pin P9 – it is used to send an ultrasonic pulse.
Echo: connect to pin P8 – it receives the reflected signal and allows distance calculation.

LED strip

DIN (signal): connect to pin P1 – controls the lighting of individual LEDs.
VCC: Connect the 3V3 output of the micro:bit.
GND: connect to the ground pin of the micro:bit (GND).

Servo motor

Signal wire: connect to pin P0 – allows servo rotation control.
VCC: Connect the 3V3 output of the micro:bit.
GND: connect to the ground pin of the micro:bit (GND).

Power supply

INPUT +: connect the positive pole of the battery box.
INPUT –: connect the negative pole of the battery box (GND).

Warning: Always make sure the micro:bit is disconnected from power before connecting any devices to avoid damaging the electronics.

scheme_radar

Program

Basic program

After starting the program, it sets the LED strip (6 diodes on pin P1), the limit distances (1–40 cm) and the initial position of the servo on pin P0. The ultrasonic sensor (Trig P8, Echo P9) constantly measures the distance to the obstacle in centimeters.

The servo rotates continuously from 0° to 180° and back, simulating a radar scan of the space. The measured distance is converted into the number of lit LEDs - green for greater distances, orange for medium distances and red for small distances.

Sound notification

After starting the program, it sets the LED strip (6 diodes on pin P1), brightness, limit distances (1–40 cm), measurement filtration using the coefficient alpha and the servo's initial position on pin P0. The ultrasonic sensor (Trig P8, Echo P9) continuously measures the distance, and the value is smoothed (combining the previous and new values) to make the measurement more stable. The servo rotates continuously from 0° to 180° and back, simulating radar.

The measured distance is mapped to the number of lit LEDs – green indicates a greater distance, orange a medium distance and red a short distance. If the object is very close (≤ 2 LEDs), the micro:bit emits an audible alert.

Tasks

Task 1: LED strip – distance visualization

Add a function to your sonar that will display the measured distance using an LED strip. Set a critical distance (e.g. 10 cm) and adjust the behavior of the diodes accordingly. If the object is closer than the set value, a larger number of diodes will light up red.

Questions to ponder:

  • How does the number of lit LEDs change as you approach the object?
  • How can colors be used to distinguish between safe and dangerous distances?
  • Is it clearer to display the distance gradually (multiple diodes), or just by changing the color?

Task 2: Audible warning at short distance

Add a sound signal to your sonar when an object approaches. Set a critical distance (e.g. 15 cm). If the object is closer than the set value, the micro:bit will start emitting an audio signal (beep).

  • Program continuous beeping at very close range.
  • Or, modify the program so that the beep rate increases as the object approaches.

 

Questions to ponder:

  • How can sound be used to warn of danger well in advance?
  • Is a continuous tone more effective, or a gradually accelerating beep?
  • Where could a similar principle be used in practice?