Design of Intelligent Bicycle Status Indication Apparatus Based on STM32 Microcontroller

As the improvement of people’s living standards, more and more motor vehicles are emerging on the roads, which pose a great threat to the bicycle riders on the same routes. Among all the road accidents, more than half are caused by the inadequacy of bicycle signals. To guarantee the safety of these bicycle riders, it is important to show the real-time status of bicycles. Basically, the research method of this paper is design, simulation, and virtual verification. Based on STM32 microcontroller, the overall design scheme of an intelligent bicycle status indication apparatus was proposed, and the hardware and software design was specified. After scheme design, simulation was carried out and showed that with high-performance STM32 microcontroller, the apparatus can promptly show the status of bicycles, and the alarm will ring when other vehicles are in the dangerous range. Theoretical analysis which includes graphical analysis and calculation was successfully conducted, which proved that this design can effectively serve as a status indication apparatus and protect the bicycle riders from collisions.


INTRODUCTION
Bicycle is a common means of transport in commutes. It is popular for its lightweight and environmentally friendly characteristics. Bicycles have become more widely used in recent years with the rise of a shared economy. However, there are often many large motor vehicles on the road. Compared with these large motor vehicles, bicycles lack pre-turn signals and rangefinders, which makes motor vehicle drivers difficult to identify the status of bicycles and brings great safety risks to bicycle riders. In recent years, there were a number of traffic accidents caused by this defect. According to a study by an institution in the United States, more than 50% of bicycles collisions incidents in the United States are caused by ambiguous or invisible signals from bicycles. In addition, from an electrical perspective, many previous designs of bicycle status indication devices use the analog circuit, which is not very precise and is unable to make extra extensions. Moreover, most of the existing bicycle status indication devices are wired, making it hard to plan how the wire should be placed without disturbing the bicycle riders.
In order to solve this problem, this paper proposed an intelligent bicycle status indication apparatus based on STM32 and uses wireless modules to simplify its layout. To avoid collisions, the device uses an ultrasonic range finder module, so when there is a vehicle approaching behind the bicycle, the buzzer will ring to remind the bicycle riders.
The main purpose of the research in this paper is to put forward a feasible security solution for the bicycle riders and create a safer and more comfortable cycling environment for them, and prevent them from being hit by motor vehicles.

Overall scheme design
The objective of this design is to provide a feasible status indication solution for bicycles. The main functions of this design are as follows: 1. A real-time bicycle status signal can be released. 2.A rangefinder module is applied and configured in this design and will trigger the alarm when other vehicles on the roads get too close to the bicycles.
The microcontroller of this device is STM32F103 designed by ST microelectronics. There are mainly 2 boards in this design. The transmitter board is attached to the handlebar on the front of the bicycle, with several control buttons on it. The mainboard is attached to the back of the bicycle and will receive the control signal sent by the transmitter board via antennas. Figure 1. Block Diagram of the Mainboard.   There are 8 LED lights in total. When LED2, LED3, LED4, LED6, and LED8 blink at the same time, it represents the left turn. When LED1, LED3, LED5, LED6, and LED7 blink at the same time, it represents the right turn. When 8 LED lights flash simultaneously, it means an emergency stop.

Hardware design
The STM32F103 series is designed by STmicroelectronics and uses a high-performance Arm Cortex-M, 32-bit core operating at 72MHz, with built-in high-speed memory (up to 128K bytes of flash and 20K bytes of SRAM), rich enhanced IO ports and peripherals connected to two APB buses. All models include two 12-bit ADCs, three generalpurpose 16-bit timers, and a PWM timer. They also include standard and advanced communication interfaces, up to two I2C and SPIs, three USART, one USB, and one CAN (Baron, et al., 2011).
PT2262/2272 is a pair of infrared remote control transmitting/receiving chips with address and data coding functions. The transmitting chip PT2262-IR integrates the carrier oscillator, encoder, and transmitting unit, making the transmitting circuit very simple (Drechsler & Drechsler, 2003). The data output bit of receiving chip PT2272 is different according to its suffix, and the data output has two ways of "temporary storage" and "latching", which is convenient for users to use. The suffix "M" is "temporary storage type", and the suffix "L" is "latching type". Its data output is divided into 0, 2, 4 and 6 different outputs. For example, PT2272-M4 represents a temporary storage infrared remote control receiving chip with data output of 4 bits (Norris, 2008). Figure 6. Schematic Diagram of Transmitter Module HC-SR04 ultrasonic rangefinder module can provide 2cm-400cm non-contact distance sensing function, and ranging accuracy is up to 3mm (Bia & Gao, 2014); The module includes an ultrasonic generator, receiver, and control circuit. There are 4 pins on this module: VCC、TRIG、ECHO and GND. The IO port of STM32 gives a very short time (at least 1us) high-level signal to the TRIG pin of ultrasonic ranging module HC-SR04, The module automatically sends 8 square waves at 40kHz and automatically detects whether there is a signal returned (Zhi et al., 2018). If there is a return signal, the ECHO pin outputs a high level. STM32 detects the duration that ECHO pin outputs high level through the IO port connected to ECHO, and then deduces the distance through the sound speed.

Software design
The software design is crucial for the apparatus to realize its functions. After turning on the apparatus, the microcontroller starts the initialization process, and the parameters of the system will be initialized. Next, the watchdog and timers of stm32 will be initialized. Then the program will calculate the time of high-level output by ECHO pin of HC-SR04 ultrasonic ranging module. If the corresponding distance calculated from this time is less than the set distance, the buzzer alarm will be triggered.
After all the process above is over, the program begins to judge which key is pressed. If the left turn button is pressed, the program will call the HAL_GPIO_WritePin function, and the IO ports connected to LED2, LED3, LED4, LED6, and LED8 will alternate between high and low levels and drive the corresponding LED lights to blink; If the right turn button is pressed, the program will call the HAL_GPIO_WritePin function and the IO ports connected to LED1, LED3, LED5, LED6 and LED7 will alternate between high and low levels and drive the corresponding LED lights to blink; If the emergency stop button is pressed, all the STM32 IO ports that are connected to LED lights will alternate between high and low levels, and all the LED lights will blink. If the reset button is clicked, all the blinking LED lights will stop blinking.   Figure 10. Configuration of IO Ports

Theoretical Analysis
Assuming that when the motor vehicle driver see a sudden turn or pre-turn signal of bicycle, it is in uniformly decelerated motion when we see it from the vertical direction (alongside the road), and the bicycle is in uniform motion when we see it from the vertical direction, then safe condition, when there is no bicycle turning signal, can be expressed as follows: In the inequation, m v is the initial speed of motor vehicle, respond t is the duration that motor vehicle driver responds to a sudden turn of the bicycle, _ light on t is the duration that the pre-turn lights blink (Under this situation no pre-turn light is used, this variable is used for comparison with the second situation), 1 a is the decelerated speed of the motor vehicle, is the dangerous distance that will trigger the alarm.
The safe condition when there is a pre-turn signal from the bicycle can be expressed as follows: In the inequation, m v is the initial speed of motor vehicle, respond t is the duration that motor vehicle driver responds to the pre-turn signal of the bicycle, 2 a is the decelerated speed of the motor vehicle, Comparing the two situations, we will find that in the situation that the bicycle abruptly turns with out pre-turn signal, it is harder to avoid a collision because based on the same initial distance, higher decelerated speed and longer deceleration duration is needed. Figure 11. The v-t Diagram

RESULTS AND DISCUSSION
After theoretical analysis, simulation was carried out in Proteus. Due to the lack of a wireless module in the Proteus component library, the buttons are directly connected to the IO ports of STM32 instead. To fully realize the functions, we also designed software based on Keil program and C programming language and downloaded the hexformat file into STM32 microcontroller. The simulation in Proteus was successful and proved that this design can realize the expected functions. Restricted by the danger of field tests, we only analyzed the value of this design theoretically, based on the inequations listed in the previous section. To simplify the calculation process, we designed WINFORM program which can judge whether the bicycle is safe based on the given parameters. We typed in different groups of parameters that is commonly seen on the road. Take the traffic regulation in mainland China, for example, the speed of motor vehicles in an urban area can be in a range of 0-30km/h, or up to 50km/h, and on the roads of rural areas, the figure can be up to 70km/h.

CONCLUSION
The design uses the fast, high precision, accurate STM32 core, which can indicate the status of bicycles, range the distance from motor vehicles to bicycles, and send an audio alarm when the distance is within dangerous range. Simulation in Proteus and theoretical analysis proved the feasibility and effectiveness of this design as it can considerably improve the safety condition of bicycle riders and avoid collisions with motor vehicles. The flexibility of STM32 microcontroller, along with its abundant and multifunctional IO ports makes further extensions on this design possible, so other functions that can make bicycle riders safer and more convenient can be added to this design in the future.