FreeRTOS Multi-Gas Detector Design Using STM32 and WiFi
Modern mining environments demand accurate, real-time detection of hazardous gases to ensure worker safety and operational reliability. This article presents a wireless portable multi-gas detector built on FreeRTOS, combining embedded processing, sensor fusion, and IoT connectivity.
The system detects methane (CHβ), carbon monoxide (CO), and hydrogen sulfide (HβS) with high accuracy while enabling remote monitoring via WiFi and cloud platforms.
π§ Introduction #
Toxic gases in underground mining pose serious risks. Traditional detectors often suffer from:
- Slow response times
- Limited storage capacity
- Poor wireless communication
- Bulky and inefficient designs
To address these challenges, this design integrates:
- STM32 microcontroller for processing
- FreeRTOS for multitasking
- WiFi (ESP8266) for cloud connectivity
- Kalman filtering for noise reduction
ποΈ System Architecture #
The system is divided into three functional layers:
| Layer | Description |
|---|---|
| Data Acquisition | Sensors collect gas concentration data |
| Data Processing | STM32 processes and filters data |
| Monitoring | Cloud platform visualizes and stores data |
Data Flow #
$$ Sensors β STM32 (ADC + Processing) β WiFi Module β Cloud Platform $$
This architecture enables real-time monitoring and remote analytics.
π§ Hardware Design #
The system uses a modular hardware approach.
Key Modules #
- STM32 microcontroller
- Gas sensors (MQ-4, MQ-7, MQ-136)
- ESP8266 WiFi module
- SD card storage
- TFT LCD display
- Alarm module (buzzer/LED)
- RTC clock and input keys
Gas Detection Modules #
Methane (CHβ) β MQ-4 Sensor #
- Detection range: 0.03%β1.00%
- Outputs analog and digital signals
$$ C = ((ADC_val Γ V / n) - b) / a Γ c $$
Carbon Monoxide (CO) β MQ-7 Sensor #
- Detection range: 0β500 ppm
- Uses temperature cycling for sensing
$$ C = 98.322 Γ (Rs / R0)^(-1.458) $$
Hydrogen Sulfide (HβS) β MQ-136 Sensor #
- Detection range: 1β200 ppm
$$ RFL / RL = (VC - VFL) / R0 C = (0.9754 Β± 574.889 Γ VFL) / (33 Γ 5 - 33 Γ VFL) $$
Storage Module #
- SD card (SPI/SDIO interface)
- Provides non-volatile, high-capacity logging
- Ensures data persistence after power loss
Wireless Communication Module #
- ESP8266-01 WiFi module
- Uses MQTT protocol
Data Transmission Flow #
$$ Read SD β Format JSON β Send via MQTT β Cloud Storage $$
Human-Machine Interface #
- 2.0-inch TFT LCD
- Multiple control keys
Supports:
- Data viewing
- Parameter configuration
- Network synchronization
π§ Software Design #
FreeRTOS Integration #
FreeRTOS enables concurrent task execution with:
- Task scheduling
- Priority management
- Efficient CPU utilization
Task Distribution #
| Task | Function |
|---|---|
| Data Acquisition | Sensor sampling |
| Data Processing | Filtering and calculation |
| Storage | Save to SD card |
| Communication | WiFi transmission |
| UI Task | Display and input handling |
Main Program Flow #
$$ Hardware Init β FreeRTOS Init β Task Creation β Scheduler Execution $$
π Kalman Filtering for Noise Reduction #
ADC readings often contain noise. The Kalman filter improves accuracy by:
- Estimating true signal values
- Reducing random noise
- Preserving signal trends
Benefits #
- Higher measurement precision
- Stable readings in noisy environments
π‘ Wireless Communication Performance #
Packet Loss Test Results #
| Distance (m) | Packets Sent | Packets Received | Loss Rate (%) |
|---|---|---|---|
| 20β80 | 100 | 100 | 0 |
| 100 | 100 | 99 | 1 |
| 120 | 100 | 95 | 5 |
| 140 | 100 | 94 | 6 |
| 160 | 100 | 90 | 10 |
| 200 | 100 | 85 | 15 |
Insight: Reliable communication is maintained within 100 meters.
π§ͺ Experimental Validation #
Standard Gas Testing #
| Gas | Standard Value | Measured Results |
|---|---|---|
| CO | 1.00 ppm | 1.00β1.02 |
| CHβ | 150 ppm | 149β152 |
| HβS | 10 ppm | 10.0β10.3 |
- Average error < 2%
- Higher accuracy than traditional detectors
π Key Advantages #
-
High Accuracy
- Kalman filtering reduces noise
-
Real-Time Monitoring
- WiFi + MQTT cloud integration
-
Reliability
- FreeRTOS multitasking reduces data loss
-
Portability
- Compact embedded design
-
Scalability
- Modular hardware and software
π Best Practices #
- Calibrate sensors regularly
- Use watchdog timers for system stability
- Optimize FreeRTOS task priorities
- Secure MQTT communication (TLS if possible)
- Validate sensor data with reference instruments
β Conclusion #
The FreeRTOS-based wireless multi-gas detector provides a robust, accurate, and scalable solution for hazardous gas monitoring in mining environments.
By integrating:
- STM32 embedded processing
- FreeRTOS multitasking
- Kalman filtering algorithms
- WiFi cloud connectivity
the system achieves:
- Reliable real-time detection
- Low data loss
- High measurement accuracy
This design represents a significant advancement in industrial safety monitoring, with strong potential for broader IoT and environmental applications.