DIY Speed Radar Using ESP8266 NodeMCU and HC-SR04 Sensor

ESP8266 29-04-26
16 0

Tutorial plan

1- Objective of the project

2- Required Components

3- Circuit Connections of system

4- Micropython program of ESP8266

 

 

Objective of the project

The objective of this DIY speed radar project is to measure the speed of a moving object such as a car, a person, or a small robot. It uses simple and affordable components to reproduce the basic idea of real speed radars. The system calculates speed and displays it in real time, while also providing an alert if a predefined speed limit is exceeded. This makes it a useful educational project for understanding motion, timing, and sensor-based measurement systems.

The functioning of the system is based on the principle that speed equals distance divided by time. Two HC-SR04 ultrasonic sensor sensors are placed a fixed distance apart along the path of the moving object. When the object passes in front of the first sensor, it detects the object and sends a signal to the ESP8266 NodeMCU, which records the starting time. As the object continues moving, it eventually passes in front of the second sensor, which triggers another signal and allows the NodeMCU to record the ending time.

The system then calculates the time difference between the two detections. Since the distance between the sensors is known in advance, the NodeMCU computes the speed using the formula speed = distance / time. The result can be converted into more familiar units such as kilometers per hour. This simple method provides a reliable estimation of the object’s speed as long as the sensors are properly aligned and the distance between them is accurately measured.

The calculated speed is displayed on an LCD I2C display, allowing the user to see the result instantly. In addition, a buzzer electronic component is used as an alert system. If the measured speed exceeds a predefined threshold, the buzzer emits a sound to warn that the speed limit has been surpassed. This feature simulates real-world speed monitoring systems and adds an interactive aspect to the project.

 

Required Components

1. ESP8266 NodeMCU board

The ESP8266 NodeMCU is the central controller of the project. It is a microcontroller board with built-in Wi-Fi capability that processes all the data from the sensors. It measures the time between detections, calculates the speed, controls the display, and activates the buzzer when necessary. Its compact size and ease of programming make it ideal for this type of embedded system project.

2. HC-SR04 sensor

HC-SR04

The two HC-SR04 ultrasonic sensor modules are used to detect the presence of a moving object. Each sensor emits ultrasonic waves and measures the time it takes for the echo to return after bouncing off an object. In this project, instead of measuring distance continuously, they act as detection points. When an object passes in front of each sensor, it triggers a timing event that allows the system to calculate speed.

3- Buzzer :

The buzzer is used to notify the user through sound based on the measured speed. When the calculated speed exceeds a predefined limit, the buzzer turns on to warn that the object is moving too fast.

4. LCD Display with I2C Module

The I2C LCD screen is used to display real-time information such as the measured speed, system status, and warning messages.

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 ESP8266 board, 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 ESP8266 board

HC-SR04 ESP8266 board
VCC 3 V
Trig D5
Echo D6
GND GND

 

2- Connecting the second HC-SR04 sensor to the ESP8266 board

HC-SR04 ESP8266 board
VCC 3 V
Trig D7
Echo D8
GND GND

 

3- Connecting the Buzzer to the ESP8266 board

Buzzer ESP8266 board
 (+) Terminal D3
(-) Terminal GND

 

4- Connection of LCD I2C display to ESP8266 board

LCD I2C display ESP8266 board
VCC 5V of GPIO card
GND GND
SDA D2
SCL D1

 

Micropython program of ESP8266

This Micropython program implements a DIY speed radar system using an ESP8266 microcontroller, two HC-SR04 ultrasonic sensors, an I2C LCD display, and a buzzer. The main purpose of the system is to measure the speed of a moving object by calculating the time it takes to travel between two fixed points.

You need to install this libraries : i2c_lcd et lcd_api for I2C LCD screen

At the beginning, the program defines key parameters such as the distance between the two sensors, the detection threshold, and the maximum allowed speed. It also configures all the hardware components: the two ultrasonic sensors (each with a trigger and echo pin), the buzzer for alerts, and the LCD screen for displaying information. When the system starts, it shows an initialization message on the LCD to indicate that the radar is ready.

The program includes several functions to organize its operation. One function measures the distance using an ultrasonic sensor by sending a pulse and calculating how long it takes for the echo to return. Another function checks whether an object is detected based on a distance threshold. Additional functions manage the LCD display and control the buzzer sound.

In the main loop, the system continuously waits for an object to pass in front of the first sensor. When this happens, it records the exact time. Then it waits for the same object to reach the second sensor and records a second timestamp. Using these two times, the program calculates the time difference, which represents how long the object took to travel between the sensors.

Once the time is known, the program calculates the speed using the formula speed = distance ÷ time and converts it into kilometers per hour. The result is displayed on the LCD screen along with the predefined speed limit. If the measured speed exceeds this limit, the system displays a warning message (“OVER”) and activates the buzzer repeatedly as an alarm. If the speed is within the limit, it displays “OK” and emits a short beep.

Finally, the program pauses briefly before restarting the process, allowing continuous monitoring of moving objects. Overall, this program demonstrates how to combine sensors, timing functions, and output devices to build a simple yet effective speed measurement system.

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