STM32F401CCU6 blackbox project with serial logging using HAL API.
This is a project to create a portable, multi-sensor data logger (a "black box") using an STM32F401CCU6 "Black Pill" board. It reads data from various analog and digital sensors and outputs the processed information via UART for real-time monitoring.
- Reads LPG concentration in PPM from an MQ-2 gas sensor.
- Reads Carbon Monoxide (CO) concentration in PPM from an MQ-7 gas sensor.
- Reads water level as a percentage from a resistive water level sensor.
- Reads 6-axis motion data (3-axis accelerometer and 3-axis gyroscope) from an MPU-6050 IMU.
- Processes all raw data into human-readable units (
PPM,%,g,°/s). - Transmits all sensor data in a formatted string over UART.
- STM32F401CCU6 "Black Pill" Development Board
- ST-Link V2 Programmer
- MQ-2 Gas Sensor Module
- MQ-7 Gas Sensor Module
- Water Level Sensor Module
- MPU-6050 Gyroscope/Accelerometer Module
- Jumper Wires & Breadboard
- STM32CubeIDE
- STM32 HAL (Hardware Abstraction Layer) Libraries
- A serial terminal program (like PuTTY, Tera Term, or the Arduino IDE's Serial Monitor)
- Clone this repository to your local machine.
- Connect all the hardware as shown in the wiring table below.
- Open the project in STM32CubeIDE.
- Build the project and flash the firmware to the STM32 board using an ST-Link.
- Power the board (e.g., via its USB port).
- Connect a USB-to-TTL serial adapter to
PA9(TX) andPA10(RX) or use your preferred method to read the UART output. - Open a serial terminal at 9600 baud to view the sensor data stream.
| Sensor / Module | STM32F401 Pin |
|---|---|
| MQ-2 (Analog Out) | PA0 (ADC1_IN0) |
| MQ-7 (Analog Out) | PA1 (ADC1_IN1) |
| Water Lvl (Analog Out) | PA2 (ADC1_IN2) |
MPU-6050 SCL |
PB6 (I2C1_SCL) |
MPU-6050 SDA |
PB7 (I2C1_SDA) |
UART TX for Output |
PA9 |
Currently in development. The next planned feature is to integrate an SD card module via SPI to log all data to a .csv file for persistent storage.
