Intelligent Laboratory Security System Based on STM32 and ZigBee: Multi-Node Networking and Intrusion Detection Practice

With the popularization of Internet of Things (IoT) technology, laboratory security systems are evolving from traditional single-function systems to intelligent and networked solutions. This article proposes a laboratory security system based on the STM32 microcontroller and ZigBee wireless communication, achieving functions such as intrusion detection via door/window magnetic sensors and smoke/infrared alarms through multi-node networking, providing an efficient and low-power intelligent monitoring solution for laboratories. The system uses the CC2530 as the ZigBee coordinator, combined with the high-performance processing capability of the STM32, to realize distributed data collection and alarm linkage.

System Architecture Design 1. System Composition The system consists of the following four parts: • Perception Layer: Sensor nodes deployed at key locations in the laboratory (door/window magnetic sensors, smoke sensors, infrared sensors). • Control Layer: The main control module centered around the STM32F103C8T6, responsible for data processing and logical judgment. • Transmission Layer: A wireless communication network based on the ZigBee protocol (CC2530 coordinator + terminal nodes). • Application Layer: Alarm information is uploaded to monitoring terminals (such as PCs or mobile devices) via serial or WiFi. 2. Multi-Node Networking Topology The system adopts a star network architecture, with the coordinator (CC2530) as the central node, and multiple terminal nodes (sensor nodes) communicating with the coordinator via the ZigBee protocol. Each terminal node is responsible for independently collecting environmental data and transmitting it to the coordinator for centralized processing via the wireless network.

Hardware Design 1. Core Hardware Selection • STM32F103C8T6: Main control chip responsible for data collection, logical judgment, and communication control. • CC2530: ZigBee wireless communication module, supporting IEEE 802.15.4 protocol, enabling multi-node networking. • Sensor Modules: • Door/window magnetic sensor (reed switch + magnet): Detects unauthorized opening of doors and windows. • MQ-2 smoke sensor: Detects gas concentration in the laboratory. • Infrared sensor (HC-SR501): Detects human movement. 2. Hardware Connection Schematic

// SPI communication configuration between STM32 and ZigBee module void SPI_Init()

{ GPIO_InitTypeDef GPIO_InitStruct; SPI_InitTypeDef SPI_InitStruct; // Configure SPI pins (SCK, MISO, MOSI) RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStruct.GPIO_Mode= GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStruct); // Initialize SPI SPI_InitStruct.SPI_Direction= SPI_Direction_2Lines_FullDuplex; SPI_InitStruct.SPI_Mode= SPI_Mode_Master; SPI_InitStruct.SPI_BaudRatePrescaler= SPI_BaudRatePrescaler_256; SPI_Init(SPI1, &SPI_InitStruct); SPI_Cmd(SPI1, ENABLE);}

Software Design 1. System Process 1. Initialization Phase: STM32 configures GPIO, SPI, and timers; ZigBee module establishes the network. 2. Data Collection Phase: Sensors periodically collect data and send it to the coordinator via ZigBee. 3. Alarm Judgment Phase: The coordinator analyzes data (e.g., door/window magnetic sensor status, smoke concentration threshold) and triggers alarms. 4. Alarm Linkage Phase: Triggers sound and light alarms, and sends alarm information to the monitoring terminal via serial. 2. Core Code Implementation (1) Sensor Data Collection

// Read door/window magnetic sensor status uint8_t Read_MagnetSensor()

{ return; GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0); // Low level indicates door/window is open }

// Read smoke sensor analog value uint16_t Read_SmokeSensor()

{ ADC_RegularChannelConfig(ADC1, ADC_Channel_0,1,ADC_SampleTime_55Cycles5); return ADC_GetConversionValue(ADC1);}

(2) ZigBee Data Transmission

// Send data to coordinator void ZigBee_SendData(uint8_t *data, uint8_t len)

{ uint8_t buffer[128]; memcpy(buffer, data, len); HAL_SPI_Transmit(&hspi1,buffer,len, HAL_MAX_DELAY);}

// Receive commands from coordinator void ZigBee_ReceiveData()

{ uint8_t rx_buffer[128]; if (HAL_SPI_Receive(&hspi1, rx_buffer, 128, 100) == HAL_OK)

{ if (rx_buffer[0] == CMD_ALARM)

{ Trigger_Alarm(); // Trigger buzzer alarm } }}

(3) Alarm Logic Processing

void Check_Alarm()

{ if (Read_MagnetSensor() == 0) { // Door/window illegally opened ZigBee_SendData(“ALERT:Door/Window Open!”, 23); } if(Read_SmokeSensor() > SMOKE_THRESHOLD)

{ // Smoke concentration exceeds threshold ZigBee_SendData(“ALERT:Smoke Detected!”, 21); }}

Testing and Performance Analysis 1. Testing Scenarios • Scenario 1: Normal state (doors and windows closed, no smoke). • Scenario 2: Doors and windows illegally opened. • Scenario 3: Smoke concentration exceeds threshold.

This design of the laboratory security system based on STM32 and ZigBee achieves door/window intrusion detection and multi-source environmental monitoring through multi-node networking. The system features low power consumption, high reliability, and good scalability, making it suitable for high-security scenarios such as laboratories and warehouses. In the future, AI algorithms can be integrated to further enhance the ability to identify false alarms.

Intelligent Laboratory Security System Based on STM32 and ZigBee: Multi-Node Networking and Intrusion Detection Practice

Design is not easy, remember to support: Like!, Save!, Follow!

Leave a Comment