STM32 Projects

STM32 Projects from Basic to Advanced


6 minute read

When I first started working with STM32 microcontrollers, I had no idea how much I would learn along the way. From my first simple experiments to designing full-fledged control systems, each project has been a step forward in my journey as an embedded systems developer. In this article, I’ve gathered all the STM32 projects I’ve worked on so far—complete with links and videos—so you can explore them, learn from them, and maybe even find inspiration for your own work. Whether you’re just starting with STM32 or looking for advanced implementations, I hope this collection helps you on your journey.

Let’s dive in!

STM32 Projects: Control LED Brightness using a potentiometer

Peripherals involved: GPIO, Timer Peripheral, PWM, ADC, External Interrupts

Source Code: STM32 Tutorial Source Code

Level: Beginner

It is a classical project found in many different embedded platforms. The idea is to control the LED's brightness using a potentiometer or a button. This project could be an excellent start for anyone wanting to learn about the STM32 MCUs. It involves learning an essential peripheral: GPIO Input/Output mode. You would understand fundamental concepts such as GPIO Ports, connecting Pull-up/Pull-down Resistors, and registers. Moreover, one can use external interrupts to capture the button release/press events.

Another project variation is integrating a potentiometer rather than a button to control the LED's brightness. In that case, you must learn a Timer Peripheral to generate a PWM signal. In addition, an analog-to-digital converter (ADC) is required to read the potentiometer output.

All these projects can be accomplished by following the STM32 Intro Course on my website:

STM32 Programming Course

You will learn microcontroller architecture, interrupts, timing, and bare-metal programming, along with the mentioned topics. 

STM32 Projects: DC Motor Control using PID

Peripherals involved: Timer Peripheral, PWM, GPIO, and Timer Update Interrupt, Timer Encoder Mode

Source Code: 

Level: Intermidiate

Hardware:

This project is a great starting point for learning robotics in an embedded systems context. The objective is to implement a Proportional-Integral-Derivative (PID) Controller to control the DC Motor speed. To implement this widely used controller, it is vital to use a Timer Update Interrupt to execute a piece of code periodically. Another critical component is the interface with a Rotary encoder using the Timer Encoder mode. Finally, a PWM signal is necessary to generate signals for an H-bridge. 

The complexity of the problem lies not in the peripherals involved but in seamlessly integrating all the parts for a single complete system. If one part does not work well, the motor control will fail. You must be rigorous and debug the issues well to successfully implement the PID Controller. Another important thing is to consider edge cases. If you forget to limit the PID Controller output, you can quickly burn the motor or damage the hardware. 

Using embedded C concepts such as structs and macros is another key to success in this project. There will be too many variables to handle with, so structs are essential to keeping everything tidy and organized. Otherwise, it will be hard to debug and make changes.

The videos below will guide you in implementing the PID Controller in C to control the motor speed: PID Implementation in C, PWM, Timer Update Interrupts, and other details. 

STM32 Projects: Inverted Pendulum Control

Peripherals involved: DMA, SPI, Timer, Timer Encoder Mode 

Source Code: My Patreon Page

Level: Advanced

This project is a slightly complex variation of the previous one. You still need to implement a feedback control algorithm called Linear Quadratic Regulator, which is more complicated than the PID. This feedback controller allows the control of multiple variables simultaneously as part of the State-Space design approach. 

Another difference is that a stepper motor is used rather than a DC motor. A stepper motor is a unique motor that achieves precise angular position without using an encoder. To drive the stepper, I used a well-known driver, L6470. It requires the SPI interface to configure the driver and PWM signal to adjust the motor speed. 

Another project feature is the system's capacity to reach an upward position. I designed a finite state machine to consider different scenarios for implementing this feature. Designing the state machine is another crucial skill in developing complex systems, including robots. Considering the depth and span of the skills required, this project is an excellent way of learning robotics and embedded systems.

STM32 Projects: USB Audio Speaker 

Peripherals involved: USB, DMA, I2S, SPI, GPIO

Source Code: My Patreon Page

Level: Advanced

Hardware: STM32F407G-DISC1

It is far more advanced than the previous project. The main aim is to develop a USB audio speaker device based on the STM32F4 MCU board. Specifically, you stream audio data from the USB buffer to the onboard Digital-to-Analog Converter (DAC) chip, which eventually drives a headphone connected to the audio jack. 

This project requires knowledge of the peripherals involved and debugging skills. The original source contains a bug, and you must find out the problem. In addition, it is vital to implement a double buffer system to stream audio data in real time without glitches. Using Direct Memory Access (DMA) is essential to accomplish that.  

The video tutorials below guide you through all the steps: onboard DAC Configuration, audio data streaming, and USB configuration. 


STM32 Projects: Self-Balancing Robot

Peripherals involved: USB, DMA, I2S, SPI, GPIO

Source Code: https://github.com/Steppeschool/Self-balancing-robot-course

Level: Advanced

Hardware: https://oshwlab.com/contact63/stm32-balancing-robot

This project is far more advanced than the mentioned robotics projects since it incorporates multiple parts: an IMU sensor for estimating the tilt angle, a DC Motor with an encoder for speed/position control, RC Joystick integration to receive commands from a user, and, of course, a control algorithm implemented in the STM32 MCU to keep the robot upright.

The robot uses the IMU sensor and a unique data fusion algorithm to measure the tilt angle. Then, it sends commands to the motor in such a way that it will minimize the tilt angle. Another important thing is to adapt the control commands to consider the user input. Again, we used LQR as a control algorithm to implement the control loop.


If you need more detailed information, check out my course, which provides a complete guide to building a self-balancing robot, including the hardware, embedded programming, data fusion, and control algorithm. 

Self-balancing Robot



« Back to Blog