Humidity & Temperature Monitoring with DHT11 & STM32 Microcontroller
This tutorial is all about Humidity & Temperature Monitoring with DHT11 & STM32 Microcontroller. DHT11 is a Humidity & Temperature sensor that is used to measure the atmospheric temperature and humidity in a particular environment or in a confined closed space. The sensor could measure the temperature from 0°C to 50°C with an accuracy of 1°C. It can measure humidity from 20% to 90% with an accuracy of 1%.
We will interface DHT11 Humidity & Temperature sensor with STM32f103c8t6 microcontroller and display the temperature and humidity data on 16×2 LCD Display.
But before starting you can go through your previous post to learn more about STM32 as well as its programming:
1. Getting Started with STM32 Microcontroller: Blinking of LED
2. STM32 Bootloader: Programming STM32F103C8 Board using USB Port
3. Interfacing 16X2 LCD Display with STM32 Bluepill Microcontroller
Bill of Materials
The following are the hardware components required for making this project.
| S.N. | Components Name | Quantity | Purchase Links |
|---|---|---|---|
| 1 | STM32F103C Board | 1 | Amazon | AliExpress |
| 2 | 16X2 LCD Display | 1 | Amazon | AliExpress |
| 3 | DHT11 Sensor | 1 | Amazon | AliExpress |
| 4 | Potentiometer 10K | 1 | Amazon | AliExpress |
| 5 | Connecting Wires | 1 | Amazon | AliExpress |
| 6 | Breadboard | 1 | Amazon | AliExpress |
DHT11 Humidity & Temperature Sensor
The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins needed).
Its fairly simple to use, but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using the library, sensor readings can be up to 2 seconds old.
Circuit Diagram & Connections
Below is the circuit diagram for interfacing STM32 Microcontroller with DHT11 Humidity & Temperature Sensor.
Supply 5V to LCD pins 2,15 from the 5V pin of STM32
Connect pin 1,5,16 of LCD to GND of STM32
Connect pin 3 of LCD to 10K Pot as shown in the above circuit.
Connect pin 4 (RS) of LCD to PB11 of STM32
Connect pin 6 (EN) of LCD to PB10 of STM32
Connect pin 11 (DB4) of LCD to PA4 of STM32
Connect pin 12 (DB5) of LCD to PA3 of STM32
Connect pin 13 (DB6) of LCD to PA2 of STM32
Connect pin 14 (DB7) of LCD to PA1 of STM32
Similarly, supply 5V to VCC Pin of DHT11 & Connect GND to GND. Connect its output Analog/Digital Pin to PA0 of STM32.
Source Code/Program
Below is the source code for interfacing DHT11 Humidity and Temperature Sensor with STM32f103c8t6.
But before that, you should have installed STM32 Board in the Arduino IDE.
There are 6 methods by which you can program STM32 Microcontroller. The methods are:
|
1 2 3 4 5 6 |
1. STM32duino Bootloader Method 2. Serial Method 3. By using ST-Link Debugger 4. By BMP (Black Magic Pro) 5. Jlink Method 6. By HID bootloader 2.0 |
I have used the first method i.e STM32duino bootloader method. By this method, you can directly upload code to STM32 via USB port. But before that, you need to install the bootloader in STM32. To learn more about this method check here: STM32 Bootloader: Programming STM32F103C8 Board using USB Port
Add DHT11 Library before compiling this code. The download link is below:
Download DHT11 Library
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include<LiquidCrystal.h> // include the LCD library const int rs = PB11, en = PB10, d4 = PA4, d5 = PA3, d6 = PA2, d7 = PA1; //STM32 Pins to which LCD is connected LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //Initialize the LCD #include<DHT.h> //Library for using DHT sensor #define DHTPIN PA0 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); //initilize object dht for class DHT with DHT pin with STM32 and DHT type as DHT11 void setup() { // initialize the LCD lcd.begin(16,2); dht.begin(); lcd.print("DHT11 with STM32"); delay(3000); lcd.clear(); } void loop() { float h = dht.readHumidity(); //Gets Humidity value float t = dht.readTemperature(); //Gets Temperature value lcd.setCursor(0,0); lcd.print("Temp: "); lcd.print(t); lcd.print(" C"); lcd.setCursor(0,1); lcd.print("Humid: "); lcd.print(h); lcd.print(" %"); } |
Video Tutorial & Demonstration
In the same way you can also interface DS81B20 with STM32 Microcontrollers.









5 Comments
Thank you for your Tutorial. Can I get your linkedin/mail/Facebook ID?????
I get deta from dht only with debugging , not without debug
i want to use 2 temp sensors, how can i change the code to do so?
hi, I want to use the blue pill and HX711 to measure pression on a cell, how can I do that???
please anyone have connection configuration