Article directory
- 0 Preface
- 1 overall design
- 2 hardware circuit
- 3 Software Design
- 4 Fall Detection Algorithm
- 5 key codes
- 6 last
0 Preface
🔥
In the past two years, the requirements and difficulty of graduation design and graduation defense have been continuously increasing. The traditional graduation project lacks innovation and highlights, and often fails to meet the requirements of graduation defense. In the past two years, students have been telling seniors about their own projects. The system does not meet the teacher's requirements.
In order for everyone to pass the graduation project smoothly and with the least amount of energy, the seniors share high-quality graduation design projects. What I want to share today is
🚩 stm32 elderly fall detection and prevention system
🥇 Seniors here give a comprehensive score for a topic (full score for each item is 5 points)
- Difficulty factor: 3 points
- Workload: 4 points
- Innovation point: 4 points


🧿 Project sharing:
https://gitee.com/sinonfin/sharing
1 overall design
The senior uses STM32F103C8T6 as the central processing unit, the GPS module is used to obtain the current location of the elderly, the current human health information is collected through the DS18B20 and the heart rate sensor, and the ADXL345 is used to judge whether the elderly has fallen. The latitude and longitude information of the current location. Displayed by OLED liquid crystal, the data can also be sent to the set mobile phone number through the SIM800 module, and the detected latitude and longitude, heart rate and body temperature will be displayed on the text message.
1. Circuit power supply part: The basic working voltage of the entire circuit is 5V, and the programming program of the single-chip microcomputer can be downloaded through the STINK V2 downloader.
2. Human-computer interaction. Through the SIM800 module, the single-chip microcomputer communicates with the mobile phone through SMS, and the collected heart rate and body temperature, whether it has fallen, and the latitude and longitude information can be displayed on the mobile phone.
3. Signal processing. The STM32F103C8T6 single-chip microcomputer is used as the CPU to perform data sampling and analysis operations.
4. Data collection. Use the heart rate blood oxygen sensor to collect heart rate, collect body temperature through DS18B20, ADXL345 to judge whether the elderly has fallen, and GPS to locate. After collecting the corresponding detected satellite signals through the GPS receiving module, data such as satellite orbit parameters can be calculated, and finally The microprocessor in the receiver can perform positioning calculation according to the positioning calculation algorithm to obtain the longitude and latitude of the machine's location, and finally send the current data to the user design terminal through the GSM SMS module for display reminders.
5. Data display. After calculation, the latitude and longitude of the current test site and the physiological condition of the elderly can be obtained through the OLED liquid crystal display on the device. as shown in the picture
2 hardware circuit
The MCU in the figure is STM32 MCU, including the entire minimum system, the display is an OLED liquid crystal display, and the power supply of the entire circuit connected to the MCU through a pull-up resistor is powered by a 5V power supply. The switch and power supply are designed as one. It is controlled by ordinary toggle switch. The GPS module is used to detect latitude and longitude and time information. The SIM800 module is used for SMS sending, and also contains buttons for setting. Including heart rate blood oxygen body temperature sensor and ADXL345 fall detection, its hardware circuit schematic diagram is shown in the figure
Core master control stm32
stm32 minimum system
3 Software Design
According to the requirements of the entire system design, the software functions this time are mainly to first configure the pins we need to use on STM32, and then initialize each module, GPS acquisition and processing, OLED display and SMS sending. In order to facilitate the writing and running effects, we consider the aesthetics when writing the program, which is convenient for observation. We encapsulate each related function. When the program needs to call that function, we can call it directly. No need Write the program in the main function. The main part of the software is composed of main function, button subroutine, GPS acquisition program, SIM800 SMS module subroutine, heart rate and blood oxygen acquisition AD conversion, fall detection ADXL345, etc. The entire main program flow chart is shown in the figure
4 Fall Detection Algorithm
The fall detection technology based on wearable sensors can be divided into acceleration sensor detection method and pressure sensor detection method according to the type and position of the wearable sensor. The detection method of the pressure sensor
The formula mainly utilizes the pressure sensor placed on the sole of the foot. Utilizing the plantar pressure sensor working in tandem with other sensors, it is possible to distinguish human falls from normal behavior. The detection method based on the acceleration sensor is mainly
Real-time monitoring of the acceleration parameters of the human body movement, when the acceleration parameters of the human body movement change, it is judged whether a fall occurs through the operation of the algorithm. The detection technology based on the acceleration sensor can be subdivided into threshold
detection and pattern recognition
Fall judgment is to distinguish and mark human fall behavior from daily activities. without classifying all human activities: on the other hand,
In practical applications, equipment resources are very precious, and many limitations of real-time systems are that algorithms with high complexity cannot be realized. Even if realized, it will lead to high cost, high energy consumption, high complexity,
A series of problems, such as low real-time performance, run counter to the original design intention of this system. Therefore, it is the guiding ideology of algorithm design to try to be as "simple" as possible under the premise of "effectiveness".
At the same time, it needs to be emphasized that, especially for the physiologically fragile safety monitoring system such as the elderly, the basic principle to be followed is "no mistakes, no mistakes".
The situation that is not a fall is judged as a fall, which can be ruled out by the user; but no false report is allowed, that is, the real fall of the user is missed, but there is no alarm. Once such a situation occurs, the consequences will be huge.
At the same time, it does not mean that we should set the alarm threshold too low
The senior uses MPU6050 to record data at a sampling frequency of 5hz, that is, collect data every 0.2s. According to research, the height h of adults generally ranges from 1.5 m to 1.9 m
Between, h= 1.7 m is selected here for estimation. Studies have found that the human navel is the golden section point from the top of the human head to the sole of the foot [10], that is, the length from the navel to the sole of the foot is 0.618 of the height of the human body
times, and the navel is just at the waist of the human body, and at the same time, it is considered that the initial longitudinal velocity of the human body is zero when the human body falls, and the acceleration a is taken as the threshold value 1g, g=9.8 m/s^2, according to the formula of gravitational acceleration:
It is obtained that in the limit state, the time for the human body to fall to the ground is about 0.21 s. That is to say, it takes 0.21s for the human body to do a free fall parallel to the ground at a position of about 1.05m from the waist
To fall to the ground. According to experiments, in the actual situation, the time required for the falling process is much longer than 0.21s, generally 1.6s to 2.0s, so the sampling frequency of 5hz is completely sufficient
The detailed process will be placed in the supporting materials, and the space is limited so I won’t repeat it here
🧿 Project sharing:
https://gitee.com/sinonfin/sharing
5 key codes
int main() { uint8_t dirswitchtemp,spswitchtemp; SmartCar_Init(); while(1) { VisualScope_Out(); while(DMA_IsMajorLoopComplete(HW_DMA_CH2)); if(StandUp_Flag==1&&IS_RUNNING==0) { dirswitchtemp=DirectionControlSwitch;//Save previous switch spswitchtemp =SpeedControlSwitch; DirectionControlSwitch=0; SpeedControlSwitch=0; ZL.P*=1.5f; ZL.D*=1.5f; DelayMs(500); Motor_Enable(); IS_RUNNING=1;//Set the trolley running flag DelayMs(500); StandUp_Flag=0; DelayMs(1000); ZL.P/=1.5f; ZL.D/=1.5f; SpeedControlSwitch=dirswitchtemp; DirectionControlSwitch=dirswitchtemp; } } } void PIT0_ISR() { static uint16_t FindZeroIndex=0; systime_speed++;//Speed ​​control beat +1 systime_direction++;//Direction Control Tempo +1 ADC_GetDataAndFilter(); Angle_Calculate(); //Yaw_Calculate(); if(systime_direction==5) { //HMC_angle=Get_Angle(); systime_direction=0; Dr_Smooth=0.2; Direction_Calculate(t2-t2_mid); } if(systime_speed==20) { systime_speed=0 ; GPIO_ToggleBit(HW_GPIOE,26);//flashing Sp_Smooth=0.05;//reset smoothing factor Get_Speed(); Speed_Calculate(); } if(FindZeroFlag) { FindZeroIndex++; if(FindZeroIndex>=400)//To put it bluntly, the data is recorded two seconds after the button is pressed { GYROY_SUM+=T_Y; GYROX_SUM+=T_X; if(FindZeroIndex>=499) { FindZeroFlag=0;//The number of times is enough, clear the flag FindZeroIndex=0; TY_OFFSET=GYROY_SUM*0.01f; TX_OFFSET=GYROX_SUM*0.01f; GYROX_SUM=0; GYROY_SUM=0; } } } Motor_Output(); } void SmartCar_Init() { DelayInit(); /******Debug_initialization******/ /*******Mainly because DMP uses printf*********/ UART_QuickInit(UART3_RX_PE05_TX_PE04,115200); UART_SelectDebugInstance(HW_UART3); //**********LED initialization, used as system operation indication************// GPIO_QuickInit(HW_GPIOE,26,kGPIO_Mode_OPP); GPIO_SetBit(HW_GPIOE,26); /********OLED initialization**************/ OLED_Init(); //***************Analog Accelerometer Gyroscope Initialization******************/ GPIO_QuickInit(MMA7361_EN,kGPIO_Mode_OPP); GPIO_SetBit(MMA7361_EN); //Enable MMA7361 ADC_QuickInit(ADC_ACCEL_Z,kADC_SingleDiff10or11);//Single-ended 12-bit input //***************IIC and L3G4200D\HMC5883 initialization******************// I2C_QuickInit(I2C0_SCL_PD08_SDA_PD09,I2C_SPEED); L3G4200D_Init(); CT_IIC_Init(); while(mpu_dmp_init()) { OLED_P8x16Str(0,0,"DMP Error"); OLED_P8x16Num(0,0,mpu_dmp_init()); DelayMs(200); } OLED_P8x16Str(0,0,"DMP OK!"); /****DMP Data output interrupt*/ GPIO_QuickInit(HW_GPIOE,4,kGPIO_Mode_IFT); //DMP output output interrupt GPIO_CallbackInstall(HW_GPIOE,GPIOE_ISR); GPIO_ITDMAConfig(HW_GPIOE,4,kGPIO_IT_FallingEdge,true); /****************PWM initialization*****************/ FTM_PWM_QuickInit(FTM0_CH0_PC01,kPWM_EdgeAligned,10000); FTM_PWM_QuickInit(FTM0_CH1_PC02,kPWM_EdgeAligned,10000); FTM_PWM_QuickInit(FTM0_CH2_PC03,kPWM_EdgeAligned,10000); FTM_PWM_QuickInit(FTM0_CH3_PC04,kPWM_EdgeAligned,10000); FTM_PWM_ChangeDuty(FTM_PWM_LEFT,0); FTM_PWM_ChangeDuty(FTM_PWM_LEFT_,0); FTM_PWM_ChangeDuty(FTM_PWM_RIGHT,0); FTM_PWM_ChangeDuty(FTM_PWM_RIGHT_,0); /**************FTM Orthogonal decoding initialization **************/ /***********Initialization bit Pulse-direction encoder**********/ FTM_QD_QuickInit(FTM1_QD_PHA_PB00_PHB_PB01,kFTM_QD_NormalPolarity,kQD_CountDirectionEncoding); FTM_QD_QuickInit(FTM2_QD_PHA_PB18_PHB_PB19,kFTM_QD_NormalPolarity,kQD_CountDirectionEncoding); GPIO_QuickInit(DIR_LEFT,kGPIO_Mode_IFT);//The direction angle of the left encoder is set as a floating input GPIO_QuickInit(DIR_RIGHT,kGPIO_Mode_IFT);//The direction angle of the right encoder is set as a floating input //*********************Serial Port Initialization********/ UART_QuickInit(UART4_RX_PE25_TX_PE24,115200); UART_ITDMAConfig(HW_UART4,kUART_DMA_Tx,true); UART_DMASendConfig(HW_UART4,HW_DMA_CH2); //****************************************************************************************/ GPIO_QuickInit(KEY_GPIO,KEY_OK,kGPIO_Mode_IPU); GPIO_QuickInit(KEY_GPIO,KEY_UP,kGPIO_Mode_IPU); GPIO_QuickInit(KEY_GPIO,KEY_DOWN,kGPIO_Mode_IPU); GPIO_QuickInit(KEY_GPIO,KEY_LEFT,kGPIO_Mode_IPU); GPIO_QuickInit(KEY_GPIO,KEY_RIGHT,kGPIO_Mode_IPU); GPIO_CallbackInstall(KEY_GPIO,GPIOA_ISR);//Key interrupt callback function GPIO_ITDMAConfig(KEY_GPIO,KEY_OK,kGPIO_IT_FallingEdge,true); GPIO_ITDMAConfig(KEY_GPIO,KEY_UP,kGPIO_IT_FallingEdge,true); GPIO_ITDMAConfig(KEY_GPIO,KEY_DOWN,kGPIO_IT_FallingEdge,true); GPIO_ITDMAConfig(KEY_GPIO,KEY_LEFT,kGPIO_IT_RisingEdge,true); GPIO_ITDMAConfig(KEY_GPIO,KEY_RIGHT,kGPIO_IT_FallingEdge,true); //*************Decoding Channel Configuration****************/ GPIO_QuickInit(HW_GPIOD,12,kGPIO_Mode_IFT); GPIO_QuickInit(HW_GPIOD,13,kGPIO_Mode_IFT); GPIO_QuickInit(HW_GPIOD,14,kGPIO_Mode_IFT); GPIO_CallbackInstall(HW_GPIOD,GPIOD_ISR); GPIO_ITDMAConfig(HW_GPIOD,12,kGPIO_IT_RisingFallingEdge,true); GPIO_ITDMAConfig(HW_GPIOD,13,kGPIO_IT_RisingFallingEdge,true); GPIO_ITDMAConfig(HW_GPIOD,14,kGPIO_IT_RisingFallingEdge,true); //*****************PIT timing interrupt initialization******************/ PIT_QuickInit(HW_PIT_CH0,3000); PIT_ITDMAConfig(HW_PIT_CH0,kPIT_IT_TOF,true); PIT_CallbackInstall(HW_PIT_CH0,PIT0_ISR); /*******************NVIC Configuration ****************/ NVIC_SetPriorityGrouping(NVIC_PriorityGroup_2); //Interrupt priorities are divided into 2 groups NVIC_SetPriority(PORTD_IRQn, NVIC_EncodePriority(NVIC_PriorityGroup_2, 0, 0));//remote control NVIC_SetPriority(PIT0_IRQn, NVIC_EncodePriority(NVIC_PriorityGroup_2, 1, 0));//Periodic Interrupt Priority NVIC_SetPriority(PORTE_IRQn, NVIC_EncodePriority(NVIC_PriorityGroup_2, 2, 0));//DMP NVIC_SetPriority(PORTA_IRQn, NVIC_EncodePriority(NVIC_PriorityGroup_2, 3, 0));//key interrupt OLED_P8x16Str(0,2,"Hello World!"); }
6 last
🧿 Project sharing: