This project demonstrates how to interface a DHT11 temperature and humidity sensor with an STM32 microcontroller using the GPIO bit-banging protocol. The project also includes real-time data display via UART and full Proteus simulation support.
The DHT11 is a low-cost digital sensor that measures both temperature and humidity. It communicates using a single-wire protocol, making it simple to interface with microcontrollers. Although it has limited precision compared to advanced sensors, its affordability and ease of use make it a popular choice for learning and basic IoT applications.
STM32CubeMX Setup- MCU Selection: STM32F103C6 (16 MHz clock)
- GPIO Configuration:
-
PA0 as Open-Drain Output (DATA line)
- TIM1 Configuration:
-
Prescaler = 15,
-
Counter Period = 65535 (for µs delays)
- UART1 Configuration:
-
115200 baud
-
8-bit data
-
no parity
- Generate initialization code and open the project in STM32CubeIDE.
Key Functions:
void DHT11_Init();
→ Configures GPIO and timervoid DHT11_Read(float *temp, float *humidity);
→ Reads sensor valuesprintf("Temp: %.1f°C, Humidity: %.1f%%\r\n", temp, humidity);
→ UART output
Components:
- STM32F103C6
- DHT11 Sensor
- Virtual Terminal
Connections:
- DATA pin → PA0
- UART1-TX → Virtual Terminal
Simulation:
- Load the generated.hex file
- Observe temperature and humidity values in the terminal
If you have any questions or suggestions don't hesitate to leave a comment below
Comments