Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BrakeLight

Overview

Brake Light is a project inspired by the common issue of weak or unreliable bike lights that often run out of battery suddenly and without warning. As a daily bike commuter, I know from experience that visibility in traffic is critical for safety, and that is something that can be greatly improved with adaptive, attention grabbing lighting system. The goal was to design a smart brake light prototype that activates only when the rider is decelerating, using an onboard IMU sensor (BMI088) rather than a mechanical trigger.

This allows fine-tuning so the light activates only when deceleration passes a defined threshold, improving both safety and battery life.

3D Print Assembly 1 3D Print Assembly 2

Key Features:

  • Powered by a single-cell LiPo battery or a standard 2.54mm pin header
  • Reverse voltage protection
  • SWD programming interface for the STM32G030F6P6 microcontroller
  • Onboard BMI088 IMU for acceleration and motion monitoring
  • One button user interface
  • Four LEDs for visibility
  • Compact PCB and 3D printable enclosure design

Project Structure

Folder Description
CAD_files Contains .stl and .3mf files for 3D printed parts
ECAD_files Contains PCB manufacturing files
Images ...
Source_Code Firmware developed for this project

Example Firmware Snippet

switch (mode)
	  {
			case 0: // DECELERATION DETECTION
			{
				float currentAccX, currentAccY, currentAccZ;
				const float XaxisThresholdP = 1.0f;	//orientation threshold
				const float XaxisThresholdN = -1.0f; //orientation threshold
				const float YaxisThreshold = 6.0f; //orientation threshold
				const float decelThreshold = 0.3f; // only trigger if Z decreases by 0.3 m/s²
				static uint32_t lastSample = 0;
				const uint32_t sampleInterval = 10; // sample every 10ms for stability
				static uint32_t ledOnTime = 0;
				const uint32_t ledDuration = 800; // when triggered stays on for 800ms
				static uint8_t ledActive = 0; // 0 = OFF, 1 = ON
				//FILTERRING
				static float prevAccZ = 0.0f;      // previous filtered Z acceleration
				static float filteredAccZ = 0.0f;  // current filtered Z value
				const float alpha = 0.8f;          // smoothing factor

				// sample at fixed rate
				if (HAL_GetTick() - lastSample >= sampleInterval){
					lastSample = HAL_GetTick();

					BMI088_ReadAcc(&imu);
					currentAccX = imu.acc[1];
					currentAccY = imu.acc[0];
					currentAccZ = imu.acc[2]; //raw X,Y,Z values, x,y re-mapped with negative sign

					// low-pass filter
					filteredAccZ = alpha * currentAccZ + (1.0f - alpha) * filteredAccZ;

					//check orientation
					if (currentAccX <= XaxisThresholdP && currentAccX >= XaxisThresholdN && currentAccY >= YaxisThreshold){ 
						//detect decelaration
						if ((prevAccZ - filteredAccZ) > decelThreshold && prevAccZ > 1 && !ledActive){ 
							HAL_GPIO_WritePin(GPIOA, LED_PAIR1_Pin | LED_PAIR2_Pin, GPIO_PIN_SET);
							ledActive = 1;
							ledOnTime = HAL_GetTick();
						}
					}

					prevAccZ = filteredAccZ; // update previous value for next loop
				}

				//turn leds off if they were turned on
				if (ledActive && (HAL_GetTick() - ledOnTime >= ledDuration)){
					HAL_GPIO_WritePin(GPIOA, LED_PAIR1_Pin | LED_PAIR2_Pin, GPIO_PIN_RESET);
					ledActive = 0;
				}
				break;

(See full firmware in the Source_Code folder for complete implementation.)


Power Consumption

Measured using the Nordic Power Profiler Kit II (PPK2).

Power Profiler Results

Mode Description Current (mA)
0 IMU active — brake detection mode 15mA avrg - 77mA max
1 Always ON 70mA avrg - 77mA max
2 Blink 28mA avrg - 77mA max
3 Always OFF 6.5mA avrg - 7mA max

3D Printed Enclosure

All parts were designed for 3D printing.
Universal Magnetic snap-fit mount makes it easy to attach and remove the light from so far any bike seat post.

3D Print Assembly 1 3D Print Assembly 2


Final Results

The final prototype fits various bike seat posts and attaches securely with a magnetic snap-on mount, making installation and removal effortless.

3D Print Assembly 1 3D Print Assembly 2


Future Work

In the next revision of the Brake Light project, the following improvements are planned:

  • Power Efficiency: Optimize both firmware and hardware to reduce overall power consumption.
  • USB-C Charging: Integrate a USB-C port and charging circuit for the 1S LiPo battery.
  • Firmware Enhancements: Improve raw IMU data processing for more accurate and responsive deceleration detection.
  • ESD Protection: Add electrostatic discharge protection to safeguard the electronics.

Sponsor Acknowledgment

I extend my heartfelt gratitude to PCBWay for their generous support and contribution to this project.
Their commitment to fostering innovation and learning in PCB design has been instrumental in making this project possible.
I am very pleased with the customer support throughout the process and even more with the quality of the delivered printed circuit boards.

Sponsor Logo

Contact Information
For inquiries or to learn more about PCBWay, please visit www.pcbway.com
or contact them directly at 📧 service@pcbway.com


Author

Developed by cubeli27
For questions or collaboration, feel free to reach out through GitHub.

About

brake light for bicycles featuring an STM32G030 MCU and BMI088 IMU

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages