2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
The intelligent access control system combines various sensors, actuators and communication modules through the STM32 embedded system to achieve real-time monitoring, automatic control and data transmission of access control. This article will introduce in detail how to implement an intelligent access control system in the STM32 system, including environment preparation, system architecture, code implementation, application scenarios, problem solutions and optimization methods.
The intelligent access control system consists of the following parts:
Access card, fingerprint and motion data are collected through various sensors and displayed in real time on the OLED display. The system realizes monitoring and automatic control of access control through data processing and network communication. Users can set it by buttons or knobs, and check the current status through the display.
Use STM32CubeMX to configure the UART interface:
Code:
- #include "stm32f4xx_hal.h"
-
- UART_HandleTypeDef huart1;
-
- void UART1_Init(void) {
- huart1.Instance = USART1;
- huart1.Init.BaudRate = 9600;
- huart1.Init.WordLength = UART_WORDLENGTH_8B;
- huart1.Init.StopBits = UART_STOPBITS_1;
- huart1.Init.Parity = UART_PARITY_NONE;
- huart1.Init.Mode = UART_MODE_TX_RX;
- huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart1.Init.OverSampling = UART_OVERSAMPLING_16;
- HAL_UART_Init(&huart1);
- }
-
- uint8_t Read_RFID_Card(uint8_t* buffer, uint16_t size) {
- return HAL_UART_Receive(&huart1, buffer, size, HAL_MAX_DELAY);
- }
-
- int main(void) {
- HAL_Init();
- SystemClock_Config();
- UART1_Init();
-
- uint8_t rfid_buffer[16];
-
- while (1) {
- if (Read_RFID_Card(rfid_buffer, 16) == HAL_OK) {
- // 处理RFID数据
- }
- HAL_Delay(1000);
- }
- }
Use STM32CubeMX to configure the UART interface:
Code:
- #include "stm32f4xx_hal.h"
-
- UART_HandleTypeDef huart2;
-
- void UART2_Init(void) {
- huart2.Instance = USART2;
- huart2.Init.BaudRate = 57600;
- huart2.Init.WordLength = UART_WORDLENGTH_8B;
- huart2.Init.StopBits = UART_STOPBITS_1;
- huart2.Init.Parity = UART_PARITY_NONE;
- huart2.Init.Mode = UART_MODE_TX_RX;
- huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart2.Init.OverSampling = UART_OVERSAMPLING_16;
- HAL_UART_Init(&huart2);
- }
-
- uint8_t Read_Fingerprint(uint8_t* buffer, uint16_t size) {
- return HAL_UART_Receive(&huart2, buffer, size, HAL_MAX_DELAY);
- }
-
- int main(void) {
- HAL_Init();
- SystemClock_Config();
- UART2_Init();
-
- uint8_t fingerprint_buffer[32];
-
- while (1) {
- if (Read_Fingerprint(fingerprint_buffer, 32) == HAL_OK) {
- // 处理指纹数据
- }
- HAL_Delay(1000);
- }
- }
The data processing module converts the sensor data into data that can be used in the control system and performs necessary calculations and analysis.
Implement a simple access control algorithm to control the switch of the electromagnetic lock based on the access card and fingerprint data:
- #define AUTHORIZED_CARD_ID "1234567890"
- #define AUTHORIZED_FINGERPRINT_ID "A1B2C3D4E5"
-
- void Control_Door(uint8_t* rfid_data, uint8_t* fingerprint_data) {
- if (strcmp((char*)rfid_data, AUTHORIZED_CARD_ID) == 0 ||
- strcmp((char*)fingerprint_data, AUTHORIZED_FINGERPRINT_ID) == 0) {
- // 打开门锁
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
- } else {
- // 关闭门锁
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
- }
- }
-
- int main(void) {
- HAL_Init();
- SystemClock_Config();
- UART1_Init();
- UART2_Init();
- GPIO_Init();
-
- uint8_t rfid_buffer[16];
- uint8_t fingerprint_buffer[32];
-
- while (1) {
- if (Read_RFID_Card(rfid_buffer, 16) == HAL_OK &&
- Read_Fingerprint(fingerprint_buffer, 32) == HAL_OK) {
- Control_Door(rfid_buffer, fingerprint_buffer);
- }
- HAL_Delay(1000);
- }
- }
Use STM32CubeMX to configure the UART interface:
Code:
- #include "stm32f4xx_hal.h"
- #include "usart.h"
- #include "wifi_module.h"
-
- UART_HandleTypeDef huart3;
-
- void UART3_Init(void) {
- huart3.Instance = USART3;
- huart3.Init.BaudRate = 115200;
- huart3.Init.WordLength = UART_WORDLENGTH_8B;
- huart3.Init.StopBits = UART_STOPBITS_1;
- huart3.Init.Parity = UART_PARITY_NONE;
- huart3.Init.Mode = UART_MODE_TX_RX;
- huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart3.Init.OverSampling = UART_OVERSAMPLING_16;
- HAL_UART_Init(&huart3);
- }
-
- void Send_Data_To_Server(uint8_t* rfid_data, uint8_t* fingerprint_data) {
- char buffer[128];
- sprintf(buffer, "RFID: %s, Fingerprint: %s", rfid_data, fingerprint_data);
- HAL_UART_Transmit(&huart3, (uint8_t*)buffer, strlen(buffer), HAL_MAX_DELAY);
- }
-
- int main(void) {
- HAL_Init();
- SystemClock_Config();
- UART3_Init();
- UART1_Init();
- UART2_Init();
-
- uint8_t rfid_buffer[16];
- uint8_t fingerprint_buffer[32];
-
- while (1) {
- if (Read_RFID_Card(rfid_buffer, 16) == HAL_OK &&
- Read_Fingerprint(fingerprint_buffer, 32) == HAL_OK) {
- Send_Data_To_Server(rfid_buffer, fingerprint_buffer);
- }
- HAL_Delay(1000);
- }
- }
Use STM32CubeMX to configure the I2C interface:
Code:
First, initialize the OLED display:
- #include "stm32f4xx_hal.h"
- #include "i2c.h"
- #include "oled.h"
-
- void Display_Init(void) {
- OLED_Init();
- }
Then implement the data display function to display the access control status and data on the OLED screen:
- void Display_Data(uint8_t* rfid_data, uint8_t* fingerprint_data) {
- char buffer[32];
- sprintf(buffer, "RFID: %s", rfid_data);
- OLED_ShowString(0, 0, buffer);
- sprintf(buffer, "Fingerprint: %s", fingerprint_data);
- OLED_ShowString(0, 1, buffer);
- }
-
- int main(void) {
- HAL_Init();
- SystemClock_Config();
- I2C1_Init();
- Display_Init();
- UART1_Init();
- UART2_Init();
-
- uint8_t rfid_buffer[16];
- uint8_t fingerprint_buffer[32];
-
- while (1) {
- if (Read_RFID_Card(rfid_buffer, 16) == HAL_OK &&
- Read_Fingerprint(fingerprint_buffer, 32) == HAL_OK) {
- // 显示门禁数据
- Display_Data(rfid_buffer, fingerprint_buffer);
- }
- HAL_Delay(1000);
- }
- }
The intelligent access control system can be used for access control management of office buildings. By real-time monitoring of access control data, automatic control can be achieved to improve the security and management efficiency of office buildings.
In the community, the smart access control system can realize automated management of residents and visitors, improving the safety and convenience of the community.
The smart access control system can be used for home access control, and through automated control and data analysis, it can achieve smarter home access control management.
Intelligent access control system can be used for intelligent building research, and provide scientific basis for building access control management and optimization through data collection and analysis.
⬇Help everyone organize the information of single chip microcomputer
Including stm32 project collection [source code + development documentation]
Click the blue words below to receive it, thank you for your support! ⬇
Click here to get more embedded details
For discussion and information on stm32, please send me a private message!
Ensure that the connection between the sensor and STM32 is stable and calibrate the sensor regularly to obtain accurate data.
Solution: Check whether the connection between the sensor and STM32 is firm, and re-solder or replace the connection wire if necessary. At the same time, calibrate the sensor regularly to ensure accurate data.
Optimize control algorithms and hardware configurations to reduce access control instability and improve system response speed.
Solution: Optimize control algorithms, adjust parameters, reduce oscillation and overshoot. Use high-precision sensors to improve the accuracy and stability of data acquisition. Choose more efficient actuators to improve the response speed of access control.
Ensure the stable connection between the Wi-Fi module and STM32, optimize the communication protocol, and improve the reliability of data transmission.
Solution: Check whether the connection between the Wi-Fi module and STM32 is firm, and re-solder or replace the connection wire if necessary. Optimize the communication protocol to reduce data transmission delay and packet loss rate. Choose a more stable communication module to improve the reliability of data transmission.
Check the I2C communication line to ensure that the communication between the display and the MCU is normal to avoid display abnormalities caused by line problems.
Solution: Check whether the I2C pins are connected correctly and ensure that the power supply is stable. Use an oscilloscope to detect the I2C bus signal to confirm whether the communication is normal. If necessary, replace the display or MCU.
Integrate more types of sensor data and use data analysis technology to predict and optimize environmental conditions.
Suggestion: Add more monitoring sensors, such as door magnetic sensors, temperature and humidity sensors, etc. Use cloud platforms for data analysis and storage to provide more comprehensive environmental monitoring and management services.
Improve user interface design to provide more intuitive data display and simpler operation interface to enhance user experience.
Recommendation: Use a high-resolution color display to provide a richer visual experience. Design a simple and easy-to-understand user interface to make it easier for users to operate. Provide graphical data display, such as real-time environmental parameter charts, historical records, etc.
Add an intelligent decision support system to automatically adjust the control strategy based on historical data and real-time data to achieve more efficient environmental control and management.
Recommendation: Use data analysis technology to analyze environmental data and provide personalized environmental management suggestions. Combine historical data to predict possible problems and needs and optimize control strategies in advance.
This tutorial details how to implement an intelligent access control system in an STM32 embedded system, from hardware selection, software implementation to system configuration and application scenarios.