0% found this document useful (0 votes)
5 views38 pages

Project Report Final

The project report details the development of an ultrasonic radar system utilizing the STM32 microcontroller, aimed at creating a cost-effective and efficient object detection system. The radar employs an ultrasonic sensor mounted on a servo motor to scan a specified angular range, with data visualized on a computer in real-time. The report highlights the advantages of STM32 over Arduino, discusses implementation challenges, and outlines future enhancements for the system.

Uploaded by

539 Malhar Patil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views38 pages

Project Report Final

The project report details the development of an ultrasonic radar system utilizing the STM32 microcontroller, aimed at creating a cost-effective and efficient object detection system. The radar employs an ultrasonic sensor mounted on a servo motor to scan a specified angular range, with data visualized on a computer in real-time. The report highlights the advantages of STM32 over Arduino, discusses implementation challenges, and outlines future enhancements for the system.

Uploaded by

539 Malhar Patil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NATIONAL INSTITUTE OF ELECTRONICS AND

INFORMATION TECHNOLOGY

CHENNAI

PROJECT REPORT

ON

STM32 MICROCONTROLLER BASED ULTRASONIC RADAR

SUBMITTED BY
Vivek Vishwas Deshmukh
Malhar Virendra Patil
Vaishnavi Pravin Salgude
Yogesh Balaji Kendre
Rushi Gajanan Bhasme

at

Embedded Systems GROUP,


NIELIT Chennai

July 2025
ABSTRACT

his project focuses on designing and implementing an ultrasonic radar system using the STM32
microcontroller. The primary objective of this project is to develop a low-cost, efficient radar
system capable of detecting objects within a specific angular range and displaying their
distance and angle on a computer screen in real time. The system uses an ultrasonic sensor
mounted on a servo motor to scan the surroundings. The servo motor rotates the sensor from
15° to 165°, and at each angle, the ultrasonic sensor measures the distance to the nearest object.
The STM32 microcontroller collects this data and sends it to a computer through serial
communication. The Processing software running on the computer receives this data and
visualises it on the screen in the form of a radar display showing the location of detected
objects.

Compared to other microcontrollers like Arduino Uno, STM32 offers better performance due
to its higher clock speed, better PWM resolution, and more memory, resulting in smoother
motor control and faster data processing. This makes the radar more accurate and reliable for
applications such as obstacle detection, security surveillance, environment mapping in
robotics, and industrial automation. The project also involved learning how to interface
multiple components like servo motors, ultrasonic sensors, and USB-TTL modules with
STM32, uploading bootloaders, writing embedded C code for motor and sensor control, and
developing Processing-based graphical user interfaces.

During the implementation, challenges such as driver installation issues and pin configuration
errors were faced and resolved, enhancing practical troubleshooting skills. The results showed
successful detection of objects within a range of 40 cm with clear graphical representation. In
future, the system can be improved by increasing the scanning range, adding alarms for object
detection, and integrating with mobile apps for remote monitoring. This project provides a
strong foundation for understanding radar principles and embedded system integration for real-
world problem-solving.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


2
About NIELIT

National Institute of Electronics and Information Technology (NIELIT), headquartered in New


Delhi is the capacity building arm of the Ministry of Electronics and Information Technology
(MeitY), mandated to carry out HR development and related activities in the area of
Information, Electronics and Communication Technology (IECT).

Since its inception in 2010, NIELIT Chennai has established itself as a premier institution
providing affordable quality education as per the job market requirements for candidates
primarily from Tamil Nadu. As of date NIELIT Chennai has imparted skill training to more
than 30, 000 youth of this region and conducted digital literacy certification for more than
25,000 candidates. NIELIT Chennai handles the activities of the NIELIT in Tamil Nadu,
Andhra, Telangana, and the Andaman and Nicobar Islands.

Presently NIELIT Chennai is implementing the following projects for Tamil Nadu: ISEA
(Information Security Education and Awareness), Future Skills PRIME capacity building
projects (3D Printing and Additive Manufacturing, Robotic Process Automation, IoT -
technology streams), and the aspirational district projects for SC/ST candidates at
Ramanathapuram and Virudhunagar funded by MeitY, Government of India. The centre also
received funding through the electronics product design and product testing capacity building
project funded by MeitY.

Other than training, the centre also provides services like; Private Cloud Setup using Citrix,
vSphere, Red Hat & FOSS Cloud, Hyper-converged Infrastructure (HCI) and Virtual Desktop
Infrastructure (VDI) Server Setup, High-Performance Computing (HPC) Setup with
100G/200G connectivity, Server and Virtual Lab Setup for BigData, AI & Information
Security, and Digital & Mobile Forensics Service.

NIELIT has also set up a Virtual Academy, a common End-to-End Platform to conduct Online
training courses including a virtual lab environment in the areas of IECT from foundation to
expert level targeting from school students to working professionals.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


3
DECLARATION

I undersigned hereby declare that the project report “STM32 MICROCONTROLLER BASED
ULTRASONIC RADAR”, submitted for partial fulfilment of the requirements of the
internship in ‘ Online Internship in Embedded C ’ at National Institute of Electronic & IT,
Chennai is a bonafide work done by me under supervision of Mr. Ishant Kumar Bajpai . This
submission represents my ideas in my own words and where ideas or words of others have
been included, I have adequately and accurately cited and referenced the original sources. I
also declare that I have adhered to academic honesty and integrity ethics and have not
misrepresented or fabricated any data, idea, fact, or source in my submission. I understand
that any violation of the above will cause disciplinary action by the institute and/or the
University and can also evoke penal action from the sources that have thus not been properly
cited or from whom proper permission has not been obtained. This report has not previously
formed the basis for awarding any degree, diploma or similar title of any other University.

Place: Pune

Date :20-07-2025

Student Name

Vaishnavi Pravin Salgude

Vivek Vishwas Deshmukh

Malhar Virendra Patil

Yogesh Balaji Kendre

Rushi Gajanan Bhasme

Project Coordinator Name

Raghavendran S

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


4
CONTENTS
Contents Page No.

ACKNOWLEDGEMENT 1

ABSTRACT 2

LIST OF FIGURES 6

CHAPTER 1. INTRODUCTION 7

CHAPTER 2. LITERATURE SURVEY 8

CHAPTER 3. METHODOLOGY 9

CHAPTER 4. HARWARE TOOLS AND COMPONENTS 14

CHAPTER 5. SOFTWARE TOOLS AND LANGUAGES 18

CHAPTER 6. IMPLEMENTATION 20

CHAPTER 7. RESULTS AND DISCUSSIONS 32

CHAPTER 8. CONCLUSION AND FUTURE SCOPE 36

REFERENCE 37

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


5
LIST OF FIGURES

No. Title Page No.


Figure 3.1 System Architecture Block Diagram 12

Figure 4.1 STM32F103C8T6 "Blue Pill" Pinout 14


Diagram
Figure 6.1 Full System Wiring Diagram 20

Figure 6.2 Bootloader Installation Wiring Diagram 21


Figure 6.3 System Logic Flowchart 31

Figure 7.1 Radar GUI Displaying Object at 77° and 32


10cm
Figure 7.2 Radar GUI Displaying Object at 121° and 32
22cm

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


6
CHAPTER 1
INTRODUCTION

Radar stands for Radio Detection and Ranging, traditionally using electromagnetic waves to
detect the presence, distance, and speed of objects. However, for short-range low-cost
applications, ultrasonic waves can be used as an alternative. In this project, an ultrasonic radar
system is developed using an STM32 microcontroller, an ultrasonic sensor (HC-SR04), and a
servo motor (SG90).

The ultrasonic sensor emits sound waves beyond human hearing range and measures the time
taken for the echo to return after hitting an object. The servo motor rotates the sensor to scan
from 15° to 165° creating a radar-like effect. The STM32 microcontroller collects the distance
data at each angle and sends it to a computer, where the Processing software visualises it as a
radar screen displaying object positions.

This system demonstrates how embedded systems, sensors, and real-time processing can be
combined to implement practical solutions in robotics, automation, and security surveillance.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


7
CHAPTER 2
LITERATURE SURVEY

Traditional radar systems are used extensively in military applications, aircrafts, ships, weather
forecasting, and automotive safety for long-distance object detection. However, these systems
use high-frequency electromagnetic waves and complex RF circuits, making them costly and
unsuitable for small-scale educational or robotic projects.

Ultrasonic radars, in contrast, use ultrasonic sensors to detect objects within short ranges
(typically up to a few meters). Previous studies and projects used Arduino Uno for such radars,
but Arduino’s limitations include lower clock speed (16 MHz), less PWM resolution (10 bits),
and small memory (2KB SRAM).

The STM32 microcontroller used in this project has several advantages:

• Higher Clock Speed: 72 MHz for faster data processing

• Better PWM Resolution: 16 bits for smoother servo control

• More SRAM: 20 KB to handle data efficiently

Thus, STM32-based radars are more reliable, precise, and responsive. This project builds upon
these benefits to create a practical and improved ultrasonic radar.

2.1 Overview of Microcontroller-Based Radar Systems

The concept of creating a low-cost radar system using ultrasonic sensors and a microcontroller
is well-established in the hobbyist and academic communities. A review of existing literature
reveals that the most common approach involves the use of the Arduino platform, particularly
the Arduino Uno board. These projects typically share a common architecture: an HC-SR04
ultrasonic sensor is mounted on a servo motor (like the SG90) to provide rotational scanning.
The Arduino microcontroller controls the servo's position and manages the ultrasonic sensor's
distance measurements.

For data visualization, the standard practice is to transmit the angle and distance data via a
serial connection to a host computer. A custom application, often developed in the Processing
IDE due to its simplicity and strong capabilities in serial communication and graphics, is used
to render the data onto a radar-like display. These systems effectively demonstrate the core
principles of radar and sonar and serve as excellent educational tools. However, their reliance

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


8
on the 8-bit Arduino platform can impose limitations on processing speed, memory, and
potential for future expansion.

2.2 The Ultrasonic Sensor (HC-SR04) in Ranging Applications

The HC-SR04 ultrasonic sensor is the cornerstone of most non-contact, short-range distance
measurement projects in the DIY and educational sectors. Its widespread adoption is due to its
low cost, ease of use, and reliable performance under a variety of conditions. The sensor
operates by emitting a short burst of 40 kHz ultrasonic sound from its transmitter module. It
then listens for the echo of this sound to be detected by its receiver module. The microcontroller
measures the time duration for which the sensor's "Echo" pin is held high, which is directly
proportional to the time-of-flight (ToF) of the sound wave.

The HC-SR04's key strengths include its immunity to ambient light conditions, which can
affect optical sensors, and its ability to detect transparent objects like glass. However, it is not
without limitations. Its theoretical maximum range of 400 cm is seldom achievable in practice;
factors like atmospheric absorption, target surface properties (size, shape, and material), and
the sensor's own power output typically limit the reliable range to a much shorter distance. The
sensor struggles with acoustically absorbent materials like foam or heavy fabric, which may
not produce a strong echo. Furthermore, surfaces that are highly angled relative to the sensor
can deflect the echo away from the receiver, resulting in a missed detection. These limitations
establish a set of realistic performance expectations for any system based on this sensor.

2.3 Justification for the STM32 Platform

While the Arduino platform is sufficient for basic implementations, this project deliberately
employs the STM32F103C8T6 microcontroller to create a more powerful and extensible
system. The choice to move beyond the conventional Arduino environment is a conscious
trade-off, accepting a potentially steeper learning curve in exchange for significantly enhanced
performance and future potential. The STM32 platform, based on the 32-bit ARM Cortex-M
architecture, offers substantial advantages over the 8-bit AVR architecture of the Arduino Uno.
This performance headroom is not merely a theoretical benefit; it directly translates into the
capacity for faster processing, smoother control, and the ability to implement more complex
algorithms in future iterations of the project, such as sensor fusion or on-device machine
learning.

The difficulties encountered during development, such as managing COM port drivers and
resolving pin naming conventions (A10 vs. PA10), are direct consequences of this choice.
Using the Arduino IDE as an abstraction layer over the STM32 hardware simplifies the initial
coding process but can obscure the underlying hardware specifics, leading to such
troubleshooting challenges. This experience itself is a valuable learning outcome, highlighting
the importance of understanding the hardware at a deeper level, even when using high-level

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


9
development tools. The quantitative differences between the platforms, summarized in the table
below, provide a clear and compelling justification for this design decision.

Arduino Uno
Feature STM32F103C8T6 Implication for this Project
(ATmega328P)

Higher processing power for faster


32-bit ARM Cortex-
CPU Core 8-bit AVR calculations and more complex
M3
algorithms.

Faster execution of loops, quicker


Clock
72 MHz 16 MHz sensor readings, and smoother
Frequency
servo control.

More memory for data buffering,


SRAM 20 KB 2 KB variables, and complex program
structures.

Flash Ability to store larger, more


64 KB 32 KB
Memory feature-rich programs.

PWM Finer, more precise control over the


16-bit 8-bit (typically)
Resolution servo motor's position.

ADC Indicates superior peripheral


12-bit (4096 levels) 10-bit (1024 levels)
Resolution quality for future sensor additions.

Table 2.1: Comparative Analysis of Microcontroller Platforms

2.4 Gaps in Existing Literature

A survey of publicly available project documentation and tutorials reveals a relative scarcity
of well-documented, introductory-level ultrasonic radar projects that are specifically based on
the STM32 platform. The vast majority of resources focus on the Arduino, leaving a gap in
accessible literature for students and hobbyists wishing to leverage the power of ARM Cortex-
M microcontrollers for this application. This project, therefore, serves as a valuable
contribution to this space. It not only provides a complete guide to building the system but also
documents the specific challenges and solutions associated with using the STM32 in a
simplified development environment (the Arduino IDE).

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


10
CHAPTER 3

METHODOLOGY
3.1 BLOCK DIAGRAM AND DETAILS:

Figure 3.1: System Architecture Block Diagram

1. Control Unit (STM32F103C8T6 Board): This is the core of the system. It runs the
embedded firmware that dictates the behavior of all other components. It generates control
signals, processes sensor data, and manages communication.

2. Sensing Unit (HC-SR04 Ultrasonic Sensor): This unit is responsible for acquiring raw
environmental data. It receives a trigger signal from the Control Unit and, in response, emits
an ultrasonic pulse and measures the echo return time.

3. Actuation Unit (Tower Pro SG90 Servo Motor): This unit provides physical motion. It
receives Pulse Width Modulation (PWM) signals from the Control Unit to precisely position
the Sensing Unit at different angles, enabling the scanning function.

4. Communication Interface (FT232RL USB to TTL Module): This unit acts as a bridge
between the microcontroller and the host computer. It converts the logic-level serial data
(UART) from the STM32 into a USB signal that the computer can understand, and vice versa.
This link is used for both programming the microcontroller and for transmitting real-time radar
data.

5. Visualization Unit (Host PC with Processing GUI): This unit is responsible for the
human-machine interface. A host computer runs a custom application that receives the
serialized angle and distance data, processes it, and renders it onto a graphical radar screen for
the user to interpret.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


11
3.2 Principle of Operation

The operational cycle of the ultrasonic radar system is a continuous, repetitive process that can
be broken down into the following sequential steps:

1. Initialization: Upon power-up or reset, the STM32 microcontroller executes the


setup() portion of its firmware. This involves initializing the serial communication port
at a baud rate of 115200 for data transmission, configuring the specific GPIO pins
connected to the sensor and servo as either inputs or outputs, and commanding the servo
motor to move to its initial starting position of 15 degrees.

2. Scanning Loop: The system enters its main loop(). The firmware commands the servo
motor to begin a sweep from its starting position (15°) towards its end position (165°).
This sweep is not continuous but occurs in discrete angular increments (e.g., 1 degree
per step).

3. Distance Measurement (Time-of-Flight): At each angular step of the servo, the


microcontroller performs a distance measurement. It sends a brief, high-logic-level
pulse of 10 microseconds (10μs) to the Trig pin of the HC-SR04 sensor. This action
triggers the sensor to emit an 8-cycle burst of 40 kHz ultrasonic sound. Immediately
after sending the trigger, the microcontroller begins to monitor the Echo pin. It uses the
pulseIn() function to measure the duration, in microseconds, for which the Echo pin
remains high. This duration corresponds to the round-trip time of the sound wave
traveling from the sensor to the object and back.

4. Distance Calculation: With the time-of-flight (Time) measured, the firmware


calculates the distance to the object. The calculation uses the standard formula for sonar
ranging:

Distance=(Time×SpeedOfSound)/2

The speed of sound is approximated as 0.034 centimeters per microsecond (cm/μs). The result
is divided by two because the measured time accounts for the sound wave's journey to the
object and back to the sensor; only half of this time represents the one-way distance.

5. Data Transmission: The calculated distance and the current angle of the servo motor
are formatted into a single, delimited string. The chosen format is "angle,distance.", for
example, "77,10.". This string is then transmitted from the STM32 to the host PC over
the serial connection established by the FT232RL module.

6. Data Reception and Visualization: On the host PC, the Processing application is
continuously listening for data on the designated serial (COM) port. When it receives a
complete data packet (terminated by the '.' character), an event is triggered. The

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


12
application parses the incoming string, using the comma as a delimiter to separate the
angle and distance values. These polar coordinates (angle, distance) are then
mathematically converted to Cartesian coordinates (x, y) suitable for plotting on the 2D
screen. The application updates the display, drawing a point or a line segment at the
calculated position on the radar grid, thus visually representing the detected object.

7. Return Sweep: Once the servo motor reaches the end of its scan at 165 degrees, the
firmware immediately begins a return sweep, moving from 165° back to 15°. The
process of measuring, calculating, and transmitting data (Steps 3-6) is repeated during
this return sweep, ensuring that the radar display is continuously updated without any
"blind" period during servo repositioning. This entire cycle repeats indefinitely,
providing a persistent, real-time scan of the environment.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


13
CHAPTER 4

HARDWARE TOOLS AND COMPONENT

4.1 Central Control Unit: STM32F103C8T6 "Blue Pill" Board :

The "Blue Pill" is a popular and inexpensive development board that features the
STM32F103C8T6 microcontroller from STMicroelectronics. It serves as the central processing
unit or "brain" of the project, responsible for executing the embedded firmware that controls
the servo motor, triggers the ultrasonic sensor, performs all necessary calculations, and
manages serial communication with the host PC.

Figure 4.1: STM32F103C8T6 "Blue Pill"

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


14
Key Specifications:

o Core: High-performance 32-bit ARM Cortex-M3 CPU.

o Maximum Frequency: 72 MHz, enabling rapid instruction execution.

o Flash Memory: 64 KB for storing the program code.

o SRAM: 20 KB for storing variables and managing program execution.

o Peripherals: Includes multiple General Purpose Input/Output (GPIO) pins,


timers with PWM generation capability (essential for servo control), and UART
interfaces for serial communication.

4.2 Ranging Sensor: HC-SR04 Ultrasonic Module :

The HC-SR04 is the primary sensing element of the system, used for non-contact distance
measurement. It operates based on the principles of sonar, emitting high-frequency sound
waves and measuring the time it takes for an echo to return.

• Key Specifications :

o Operating Voltage: 5V DC.

o Working Current: Approximately 15mA during operation.

o Operating Frequency: Emits sound pulses at 40 kHz.

o Theoretical Range: 2 cm to 400 cm.

o Measuring Angle: The sensor has a narrow detection cone of less than 15
degrees.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


15
o Pinout: The module has four essential pins: VCC (5V power), Trig (Trigger
input), Echo (Echo output), and GND (Ground).

4.3 Scanning Actuator: Tower Pro SG90 Micro Servo Motor :

The Tower Pro SG90 is a lightweight, widely used, and low-cost servo motor. In this project,
its function is to physically rotate the HC-SR04 sensor, allowing the system to scan a wide
angular area instead of just measuring distance in a single, fixed direction.

• Key Specifications :

o Operating Voltage: Typically 4.8V to 6V.

o Torque: 1.8 kg-cm at 4.8V, sufficient for rotating the lightweight sensor.

o Rotation Range: 0 to 180 degrees (though practically limited to 15-165 degrees


in this project's firmware).

o Control Signal: The servo's position is controlled by the duration of a high pulse
on its signal line, a technique known as Pulse Width Modulation (PWM). The
STM32's timer peripherals are used to generate this signal.

4.4 Communication Interface: FT232RL USB to TTL Serial Converter :

This module is a critical intermediary component that facilitates communication between the
STM32 microcontroller and the host PC. The STM32 communicates using logic-level UART
(Transistor-Transistor Logic levels), while the PC uses the USB protocol. The FT232RL chip
on this module handles the necessary protocol conversion and voltage level shifting to create a
virtual serial (COM) port on the PC. This interface serves a dual purpose: it is used to upload
the compiled firmware to the STM32 (in conjunction with a bootloader) and to transmit the
real-time angle and distance data from the operational radar to the GUI.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


16
4.5 Bill of Materials (BOM)

The following table provides an itemized list of all hardware components required for the
project, along with their approximate costs. This highlights the overall cost-effectiveness of
the system, a key advantage of this design approach.

Component Name Quantity Estimated Price (Taka)

STM32F103C8T6 ARM Development Module 1 240

Ultrasonic Sensor HC-SR04 1 70

FTDI USB to TTL Serial Converter FT232RL 1 300

Servo Motor SG90 1 160

Breadboard - 400 points 1 85

USB Cable 1 30

Jumper Wires Set (Included with kits)

Glue Gun & Glue Stick 1 350

Soldering Iron & Accessories 1 250

Total (Approximate) 1500

Table 4.1: Project Bill of Materials

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


17
CHAPTER 5

SOFTWARE TOOLS AND LANGUAGES

The development of the STM32-based ultrasonic radar system required a suite of software tools
to create the embedded firmware, the graphical user interface, and to manage the programming
of the microcontroller. This chapter details the software environments and programming
languages used in the project.

5.1 Development Environment: Arduino IDE :

The Arduino Integrated Development Environment (IDE) was selected as the primary tool for
writing, compiling, and uploading the firmware to the STM32 board. While typically
associated with Arduino-brand hardware, the IDE's open-source nature and extensible
architecture allow it to support a wide range of third-party boards, including the STM32 "Blue
Pill."

• STM32 Integration: To enable support for the STM32F103C8T6, the development


environment was configured by adding a specific board manager URL to the IDE's
preferences. This allowed for the installation of the "STM32F1xx/GD32F1xx" board
package. Once installed, the "Generic STM32F1 series" could be selected from the
board menu. This setup provides a simplified, high-level programming experience,
leveraging familiar Arduino functions and libraries (like Servo.h and Serial) while
targeting the more powerful STM32 hardware. The upload method was configured to
use the serial bootloader, which works in tandem with the FT232RL adapter.

5.2 Visualization Environment: Processing IDE :

Processing is an open-source graphical library and Integrated Development Environment (IDE)


built upon the Java programming language. It was chosen for developing the radar's Graphical
User Interface (GUI) due to its simplicity and powerful features for creating visual applications
and handling serial data communication. Its straightforward syntax makes it easy to draw
shapes, handle colors, and manage text, while its built-in serial library provides a robust
mechanism for reading the data stream sent by the STM32. This makes Processing an ideal
choice for rapid prototyping of data visualization applications like the one required for this
project.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


18
5.3 Firmware Flashing Utility: STM32CubeProgrammer :

STM32CubeProgrammer is an all-in-one, multi-OS software tool from STMicroelectronics for


programming STM32 products. While the Arduino IDE was used for application development,
STM32CubeProgrammer was essential for the initial, one-time setup of the "Blue Pill" board.
Its primary role in this project was to flash the serial bootloader firmware onto the
microcontroller's memory. This bootloader is a small program that resides in the STM32's
memory and allows the chip to be reprogrammed over its UART interface, a necessary
prerequisite for the convenient "upload" functionality of the Arduino IDE.

5.4 Programming Languages :

Two primary programming languages were utilized in this project, corresponding to the two
main software components:

• C/C++: The embedded firmware running on the STM32 microcontroller was written in
C++. The Arduino IDE uses a simplified C++ dialect and provides a framework of core
libraries that abstract away much of the low-level hardware configuration, allowing the
developer to focus on the application logic.

• Java: The GUI application was developed in the Processing IDE, which uses Java as its
underlying language. The code written in the Processing sketchbook is pre-processed
and converted into standard Java code before compilation and execution.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


19
CHAPTER 6

IMPLEMENTATION

6.1 Hardware Assembly and Wiring :

The hardware was assembled on a solderless breadboard for ease of prototyping and
modification. The connections were made using standard jumper wires. The process involved
two main stages of wiring: initial setup for bootloader flashing and the final configuration for
system operation.

Figure 6.1: Full System Wiring Diagram

• Control Unit Wiring (for Bootloader Flashing): To prepare the STM32 board for its
initial programming, the FT232RL USB-to-TTL converter was connected. The
connections were as follows: FT232RL VCC to STM32 3.3V, GND to GND, TX to
STM32 RX (pin PA10), and RX to STM32 TX (pin PA9). The BOOT0 jumper on the
STM32 board was set to the '1' position to enable programming mode. This setup is
illustrated in Figure 6.2.

• System Wiring (for Operation): After flashing the bootloader, the wiring was
reconfigured for the final application. The FT232RL connections remained the same
for data communication. The sensor and servo were then connected:

o HC-SR04 Sensor: VCC pin to STM32 5V, GND to GND, Trig pin to STM32
pin PA10, and Echo pin to STM32 pin PA9.

o SG90 Servo Motor: VCC (red wire) to STM32 5V, GND (brown wire) to
GND, and Signal (orange wire) to STM32 pin PA8, which is a PWM-capable
pin.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


20
6.2 Bootloader Installation and Firmware Flashing

The development workflow for the STM32 "Blue Pill" is more involved than that of a standard
Arduino, requiring an initial setup phase. This hidden complexity is a crucial practical aspect
of the project.

Figure 6.2: Bootloader Installation Wiring Diagram

1. Hardware Configuration: The BOOT0 jumper on the Blue Pill board was set to the
'1' position, and the BOOT1 jumper was set to '0'. This configures the microcontroller
to boot from its internal system memory, where the factory bootloader resides, allowing
it to accept programming commands over the UART interface.

2. Flashing the Bootloader: With the board connected to the PC via the FT232RL
adapter, the STM32CubeProgrammer software was launched. The software was
configured to connect to the correct COM port at a baud rate of 115200. The bootloader
binary file (a generic STM32 bootloader compatible with the Arduino IDE) was
selected, and the target memory address was set to 0x08000000. The programming
operation was then initiated, which erases the relevant flash sector and writes the new
bootloader code.

3. Final Configuration: After successfully flashing the bootloader, the BOOT0 jumper
was returned to the '0' position. This ensures that on subsequent power-ups, the
microcontroller executes the code from its main flash memory, where the user
application will be stored. From this point forward, all application firmware could be
uploaded directly from the Arduino IDE without needing STM32CubeProgrammer or
changing jumpers.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


21
6.3 Embedded Firmware Development (STM32 Code):

// Includes the Servo library

#include <Servo.h>.

// Defines Tirg and Echo pins of the Ultrasonic Sensor

const int trigPin = PA10;

const int echoPin = PA9;

// Variables for the duration and the distance

long duration;

int distance;

Servo myServo; // Creates a servo object for controlling the servo motor

void setup() {

pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output

pinMode(echoPin, INPUT); // Sets the echoPin as an Input

[Link](115200);

[Link](PA8); // Defines on which pin is the servo motor attached

void loop() {

// rotates the servo motor from 15 to 165 degrees

for(int i=15;i<=165;i++){

[Link](i);

delay(30);

distance = calculateDistance();// Calls a function for calculating the distance

measured by the Ultrasonic sensor for each degree

[Link](i); // Sends the current degree into the Serial Port

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


22
[Link](","); // Sends addition character right next to the previous value needed

later in the Processing IDE for indexing

[Link](distance); // Sends the distance value into the Serial Port

[Link]("."); // Sends addition character right next to the previous value needed

later in the Processing IDE for indexing

EEE 416 C 2020 – Final Project

EEE416(2021) Project Group C.P8

// Repeats the previous lines from 165 to 15 degrees

for(int i=165;i>15;i--){

[Link](i);

delay(30);

distance = calculateDistance();

[Link](i);

[Link](",");

[Link](distance);

[Link](".");

// Function for calculating the distance measured by the Ultrasonic sensor

int calculateDistance(){

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


23
digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound

wave travel time in microseconds

distance= duration*0.034/2;

return distance;

6.4 GUI Development (Processing Code):

The graphical user interface was created in the Processing IDE. The code is event-
driven and focused on visualization.

import [Link].*; // imports library for serial communication

import [Link]; // imports library for reading the data from the serial
port

import [Link];

Serial myPort; // defines Object Serial

// defubes variables

String angle="";

String distance="";

String data="";

String noObject;

float pixsDistance;

int iAngle, iDistance;

int index1=0;

int index2=0;

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


24
PFont orcFont;

void setup() {

size (1200, 720); // ***OUR SCREEN RESOLUTION***

smooth();

myPort = new Serial(this,"COM9", 9600); // starts the serial communication

[Link]('.'); // reads the data from the serial port up to the character '.'. So
actually it

reads this: angle,distance.

void draw() {

fill(98,245,31);

// simulating motion blur and slow fade of the moving line

noStroke();

fill(0,4);

rect(0, 0, width, height-height*0.065);

fill(98,245,31); // green color

// calls the functions for drawing the radar

drawRadar();

drawLine();

drawObject();

drawText();

EEE416(2021) Project Group C.P8

EEE 416 (2020) – Final Project Group [Link]

void serialEvent (Serial myPort) { // starts reading data from the Serial Port

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


25
// reads the data from the Serial Port up to the character '.' and puts it into the String

variable "data".

data = [Link]('.');

data = [Link](0,[Link]()-1);

index1 = [Link](","); // find the character ',' and puts it into the variable "index1"

angle= [Link](0, index1); // read the data from position "0" to position of the

variable index1 or thats the value of the angle the Arduino Board sent into the Serial
Port

distance= [Link](index1+1, [Link]()); // read the data from position


"index1"

to the end of the data pr thats the value of the distance

// converts the String variables into Integer

iAngle = int(angle);

iDistance = int(distance);

void drawRadar() {

pushMatrix();

translate(width/2,height-height*0.074); // moves the starting coordinats to new


location

noFill();

strokeWeight(2);

stroke(98,245,31);

// draws the arc lines

arc(0,0,(width-width*0.0625),(width-width*0.0625),PI,TWO_PI);

arc(0,0,(width-width*0.27),(width-width*0.27),PI,TWO_PI);

arc(0,0,(width-width*0.479),(width-width*0.479),PI,TWO_PI);

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


26
arc(0,0,(width-width*0.687),(width-width*0.687),PI,TWO_PI);

// draws the angle lines

line(-width/2,0,width/2,0);

line(0,0,(-width/2)*cos(radians(30)),(-width/2)*sin(radians(30)));

line(0,0,(-width/2)*cos(radians(60)),(-width/2)*sin(radians(60)));

line(0,0,(-width/2)*cos(radians(90)),(-width/2)*sin(radians(90)));

line(0,0,(-width/2)*cos(radians(120)),(-width/2)*sin(radians(120)));

line(0,0,(-width/2)*cos(radians(150)),(-width/2)*sin(radians(150)));

line((-width/2)*cos(radians(30)),0,width/2,0);

popMatrix();

void drawObject() {

pushMatrix();

translate(width/2,height-height*0.074); // moves the starting coordinats to new


location

strokeWeight(9);

stroke(255,10,10); // red color

pixsDistance = iDistance*((height-height*0.1666)*0.025); // covers the distance from


the sensor from

cm to pixels

// limiting the range to 40 cms

if(iDistance<40){

// draws the object according to the angle and the distance

line(pixsDistance*cos(radians(iAngle)),-pixsDistance*sin(radians(iAngle)),(width

width*0.505)*cos(radians(iAngle)),-(width-width*0.505)*sin(radians(iAngle)));

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


27
}

popMatrix();

void drawLine() {

pushMatrix();

strokeWeight(9);

stroke(30,250,60);

translate(width/2,height-height*0.074); // moves the starting coordinats to new


location

line(0,0,(height-height*0.12)*cos(radians(iAngle)),-(height-
height*0.12)*sin(radians(iAngle))); //

draws the line according to the angle

popMatrix();

void drawText() { // draws the texts on the screen

pushMatrix();

if(iDistance>40) {

noObject = "Out of Range";

else {

noObject = "In Range";

fill(0,0,0);

noStroke();

rect(0, height-height*0.0648, width, height);

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


28
fill(98,245,31);

textSize(25);

EEE416(2021) Project Group C.P8

text("10cm",width-width*0.3854,height-height*0.0833);

text("20cm",width-width*0.281,height-height*0.0833);

text("30cm",width-width*0.177,height-height*0.0833);

text("40cm",width-width*0.0729,height-height*0.0833);

textSize(25);

text("EEE 416-Lab Project", width-width*0.875, height-height*0.0277);

text("Angle: " + iAngle +" °", width-width*0.48, height-height*0.0277);

text("Distance: ", width-width*0.26, height-height*0.0277);

if(iDistance<40) {

text("

"

+ iDistance +" cm", width-width*0.225, height-height*0.0277);

textSize(25);

fill(98,245,60);

translate((width-width*0.4994)+width/2*cos(radians(30)),(height-height*0.0907)

width/2*sin(radians(30)));

rotate(-radians(-60));

text("30°",0,0);

resetMatrix();

translate((width-width*0.503)+width/2*cos(radians(60)),(height-height*0.0888)

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


29
width/2*sin(radians(60)));

rotate(-radians(-30));

text("60°",0,0);

resetMatrix();

translate((width-width*0.507)+width/2*cos(radians(90)),(height-height*0.0833)

width/2*sin(radians(90)));

rotate(radians(0));

text("90°",0,0);

resetMatrix();

translate(width-width*0.513+width/2*cos(radians(120)),(height-height*0.07129)

width/2*sin(radians(120)));

rotate(radians(-30));

text("120°",0,0);

resetMatrix();

translate((width-width*0.5104)+width/2*cos(radians(150)),(height-height*0.0574)

width/2*sin(radians(150)));

rotate(radians(-60));

text("150°",0,0);

popMatrix();

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


30
6.5 System Flowchart :

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


31
CHAPTER 7
RESULTS AND DISCUSSIONS
7.1 System Demonstration

The system was successfully assembled and tested, demonstrating its ability to detect objects
and visualize their location in real-time. The graphical user interface, rendered by the
Processing application, provides a clear and intuitive representation of the scanned
environment. The following figures, captured during operation, showcase the system's output
when detecting objects at different positions.

Figure 7.1: Radar GUI Displaying Object at 77° and 10cm

Figure 7.2: Radar GUI Displaying Object at 121° and 22cm

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


32
As shown in the figures, the GUI correctly plots the detected objects. The green sweeping line
indicates the current direction of the sensor, while the red line segment marks the position of
the obstacle at the measured angle and distance. The text display at the bottom provides precise
numerical readouts. These results confirm that all subsystems—sensing, actuation, control,
communication, and visualization—are integrated and functioning correctly.

7.2 Performance Analysis

• Range and Accuracy: The system was tested and found to be effective within the 40
cm range limit defined by the GUI's visual scale. While the HC-SR04 sensor has a
theoretical maximum range of 400 cm, this is rarely practical for small targets in open
air. The effective range is limited by several factors, including the attenuation of the
sound wave as it travels, the size and acoustic reflectivity of the target object, and the
sensitivity of the receiver. For this project's purpose of short-range scanning, the 40 cm
range is sufficient. The accuracy, observed qualitatively, appears high for solid objects
placed perpendicular to the sensor's path. However, precise quantitative accuracy would
require calibration against a known standard and implementation of environmental
compensation.

• Angular Resolution: The angular resolution of the system is primarily determined by


the step size defined in the firmware's for loop, which is 1 degree. This means the
system takes one distance measurement for every degree of servo rotation. The practical
angular accuracy is also dependent on the mechanical precision and step consistency of
the SG90 servo motor.

• Real-time Performance: The system exhibits good real-time responsiveness. The


choice of the 72 MHz STM32 microcontroller ensures that the distance calculation and
serial transmission at each step are completed almost instantaneously. The primary
sources of latency in the system are the physical speed of the servo motor and the
delay(30) command in the firmware loop, which was added to allow the servo time to
settle at each new position before a measurement is taken. This delay dictates the overall
scan speed of the radar.

7.3 Analysis of Implementation Challenges

The development process was not without its challenges. Overcoming these issues provided
valuable practical experience in embedded systems troubleshooting. The two main problems
encountered are detailed below, formalizing the notes from the project's documentation.

• Challenge 1: COM Port Detection Failure: During the initial setup, the Windows 10
operating system failed to automatically recognize the FT232RL USB-to-TTL adapter

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


33
and assign it a COM port. This prevented any communication with the STM32 board.
The problem was traced to a missing device driver.

o Troubleshooting and Solution: The Device Manager was used to identify the
unrecognized "USB Serial Port." The correct drivers for the FT232RL chip were
then manually downloaded and installed. After installation, the device was
properly recognized, and a COM port was assigned, enabling both the
STM32CubeProgrammer and the Arduino IDE to communicate with the board.
This experience underscores the critical importance of proper driver
management, a common hurdle in embedded development when interfacing
with various hardware modules.

• Challenge 2: Incorrect Pin Naming Convention: When first writing the firmware,
the STM32 pins were referred to using the labels printed on the Blue Pill board's silk
screen (e.g., "A10", "A9"). This resulted in compiler errors, as the Arduino core for
STM32 did not recognize these aliases.

o Troubleshooting and Solution: The problem was solved through a


combination of deductive reasoning and consulting official documentation. By
observing that the onboard LED was controlled via pin "PC13," it was inferred
that the correct naming convention likely required a port prefix (e.g., 'P' for
Port). This hypothesis was confirmed by cross-referencing the official
STM32F103C8T6 pinout diagram, which showed the pins labeled as PA9,
PA10, etc. Changing the code to use the PAx format (e.g., const int trigPin =
PA10;) resolved the compiler errors. This challenge highlights a potential pitfall
of using abstraction layers like the Arduino core; while they simplify
development, they can sometimes obscure hardware-specific details, making it
essential to consult primary datasheets when issues arise.

7.4 System Limitations

While the project was successful, it is important to acknowledge its inherent limitations, which
stem from the chosen components and design.

• Sensor Limitations: The HC-SR04 sensor is the primary source of limitations. It


cannot reliably detect materials that absorb sound, such as foam, soft fabrics, or some
plastics. It can also be "fooled" by objects with surfaces that are sharply angled relative
to the sensor, as the sound wave may be reflected away from the receiver instead of
back to it, resulting in a missed detection.

• Single-Target Detection: The firmware's reliance on the pulseIn() function means it


can only measure the distance to the first object that returns an echo along a given line

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


34
of sight. It is incapable of distinguishing between multiple objects at different distances
but at the same angle.

• Environmental Factors: The accuracy of the distance measurement is dependent on


the speed of sound, which varies with environmental conditions like temperature,
humidity, and air pressure. The current system does not include any sensors to measure
these conditions, and therefore cannot compensate for variations in sound speed,
introducing a potential source of error.

• 2D Scanning Only: The system scans in a single horizontal plane and cannot provide
any information about the height or vertical position of detected objects.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


35
CHAPTER 8
CONCLUSION AND FUTURE SCOPE

8.1 Conclusion :

This project successfully achieved its objective of designing, building, and testing an STM32-
based ultrasonic radar system. A functional, low-cost prototype was created that accurately
detects objects within a 150-degree field of view and displays their location on a real-time
graphical interface. The project effectively demonstrates the successful integration of multiple
engineering domains: embedded systems programming, hardware interfacing, sensor data
acquisition, mechanical actuation, and software development for data visualization.

The selection of the STM32F103C8T6 microcontroller proved to be a key advantage, providing


significant performance headroom over more common 8-bit platforms. This choice establishes
the project not only as a successful proof-of-concept but also as a robust and highly extensible
platform for future development. The challenges encountered and overcome during
implementation provided critical hands-on experience in practical embedded systems
engineering. In conclusion, the system serves as an excellent educational tool and a solid
foundation for more advanced applications in robotics, security, and automated environmental
sensing.

8.2 Future Scope :

The current prototype offers numerous avenues for future enhancement and expansion. The
robust STM32 platform provides the necessary resources to implement more advanced
features. The STM32-based ultrasonic radar was successfully designed and implemented. The
system demonstrated real-time object detection and graphical display, showing the potential of
low-cost radars for robotics, automation, and security applications.

• Increased Range and Angular Coverage:

To achieve a full 360-degree scan, the SG90 servo motor could be replaced with a continuous
rotation servo or a stepper motor coupled with a slip ring to manage wiring.

• Enhanced Signal Processing and Accuracy:

The firmware could be enhanced to improve measurement accuracy. Instead of relying on a


single pulseIn() reading, the STM32 could take multiple samples at each angular step and
average them to reduce noise

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


36
• Multi-Sensor Fusion:

The system's reliability and detection capabilities could be dramatically improved by adding a
sensor of a different type and fusing the data.

• On-Device Intelligence (Edge AI):

A significant leap in functionality would be to incorporate on-device Artificial Intelligence. By


upgrading to a more powerful microcontroller from the STM32 family (e.g., an STM32H7
series) and utilizing the STMicroelectronics AI ecosystem ([Link]), a machine
learning model could be deployed directly on the device.

• IoT Integration and Remote Access:

To make the system accessible from anywhere, it could be connected to the Internet of Things
(IoT). An ESP8266 or ESP32 Wi-Fi module could be interfaced with the STM32 via a UART
serial connection.

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


37
REFERENCES

Datasheets:

• STMicroelectronics. (Date). STM32F103C8T6 Datasheet.

• (Manufacturer). (Date). HC-SR04 Ultrasonic Sensor Datasheet.

• Tower Pro. (Date). SG90 Micro Servo Datasheet.

• FTDI. (Date). FT232RL Datasheet.

Software and Online Resources:

• Arduino IDE. [Link]

• Processing IDE. [Link]

• STMicroelectronics. STM32CubeProgrammer. [Link]


tools/[Link]

NIELIT Chennai - STM32 MICROCONTROLLER BASED ULTRASONIC RADAR


38

You might also like