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
Carbon Monoxide (CO) – MQ-7 Sensor #
- Detection range: 0–500 ppm
- Uses temperature cycling for sensing
Hydrogen Sulfide (H₂S) – MQ-136 Sensor #
- Detection range: 1–200 ppm
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.