Create Your Own Speed Radar with Micro:bit and HC-SR04

Micro:bit 06-04-26
13 0

Tutorial plan

1- Objective of the project

2- Required Components

3- Circuit Connections of system

4- Micropython program of Micro:bit

 

 

Objective of the project

The primary goal of this project is to build a compact, portable speed radar system using the Micro:bit microcontroller, a HC-SR04 ultrasonic distance sensor, an I2C LCD display, and a buzzer. This system aims to detect the speed of moving objects in real time and provide both visual and audible feedback. By combining these components, users can learn how distance measurements and timing calculations translate into speed detection, while also exploring programming logic and embedded electronics principles. This project is suitable for educational purposes, experimentation, and hobbyist applications where understanding motion detection and microcontroller interfacing is the main focus.

Functioning:

The speed radar operates by using the HC-SR04 ultrasonic sensor to measure the distance between the sensor and a moving object at two consecutive points in time. The Micro:bit calculates the object's speed using the difference in distance over the measured time interval. The calculated speed is then displayed on the I2C LCD, providing an immediate visual output. Additionally, a buzzer is integrated to signal when an object exceeds a predefined speed threshold, giving instant audible feedback. The program running on the Micro:bit continuously monitors the sensor data, updates the LCD, and controls the buzzer, allowing the system to function autonomously and accurately detect object motion in real time.

 

Required Components

1. BBC Micro:bit (Microcontroller)

Micro:bit board

he Micro:bit serves as the main processing unit. It reads data from the ultrasonic sensor, performs speed calculations, controls the LCD display, and activates the buzzer.

2. GPIO Extension Card for Micro:bit

The GPIO expansion card for the Micro:bit card

The GPIO extension card Expands the number of usable input/output pins on the Micro:bit, making it easier to connect multiple components.

3. HC-SR04 sensor

HC-SR04

This sensor measures distance by emitting ultrasonic waves and calculating the time it takes for the echo to return. In this project, it is used to measure the position of a moving object at two time intervals, which allows the Micro:bit to compute the object’s speed.

4. LCD Display with I2C Module

The LCD I2C display is used to allow the system to show information to the user. It can display the selected amount.

5. Breadboard 

Breadboard

A breadboard is used to assemble the circuit without soldering. It makes it easy to connect and modify the components during testing and development.

6. Jumper Wires

Jumper wires

Jumper wires are used to connect the Micro:bit, HC-SR04 sensors, and LCD display together. They ensure proper electrical connections between all components.

 

Circuit Connections of system

 

1- Connecting the first HC-SR04 sensor to the Micro:bit board

HC-SR04 Micro:bit
VCC 3.3 V
Trig P0
Echo P1
GND GND

 

2- Connecting the second HC-SR04 sensor to the Micro:bit board

HC-SR04 Micro:bit
VCC 3.3 V
Trig P2
Echo P8
GND GND

 

3- Connection of LCD I2C display to Micro:bit

LCD I2C display Micro:bit board
VCC 5V of GPIO card
GND GND
SDA P20
SCL P19

 

Micropython program of Micro:bit

This Micropython program turns a Micro:bit into a simple speed radar using two HC-SR04 ultrasonic sensors, an I2C LCD display, and a buzzer. It measures the time an object takes to travel between two points and calculates its speed. The results are displayed on the LCD, and a buzzer alerts when the speed exceeds a set limit.

 

Program Structure:

1- Configuration Section:

Defines constants for sensor separation (DISTANCE), object detection threshold (THRESHOLD), speed limit (SPEED_LIMIT), and the I2C

LCD address (I2C_ADDR).

2- LCD Functions:

Low-level functions (lcd_write, lcd_byte) handle communication with the I2C LCD.

High-level functions (lcd_cmd, lcd_data, lcd_init, lcd_clear, lcd_move, lcd_puts) initialize the LCD, position the cursor, and display text.

3- Ultrasonic Sensor Functions:

measure_distance(trig, echo): Triggers the HC-SR04 sensor and calculates the distance to an object in centimeters.

object_detected(trig, echo): Returns True if an object is within the threshold distance.

4- Initialization:

The LCD is initialized, and a “Microbit RADAR READY” message is displayed for 5 seconds.

5- Main Loop:

Waits for an object to pass sensor 1 and records the timestamp (t1).

Waits for the object to pass sensor 2 and records the timestamp (t2).

Calculates the time difference (delta_t) and computes the speed in km/h.

Updates the LCD with the measured speed, speed limit, and status (“OVER SPEED” or “OK”).

Triggers the buzzer if the object exceeds the speed limit.

Waits 5 seconds before repeating the detection cycle.

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

Pictures of the articles

Robotic site created by Mohamed Ali Haj Salah - Teacher info