Interfacing DHT11 Temperature & Humidity Sensor with STM32 Blue Pill

This post shows how to interface STMicroelectronics ARM Cortex-M3 microcontroller based STM32F103C8T6 Blue Pill development board with DHT11 digital temperature & humidity sensor where Arduino IDE software is used to write the interfacing program. We will also see the simulation of the STM32F103C8T6 Blue Pill board with the DHT11 sensor using Proteus simulation software.
The STM32 Blue Pill board MCU reads temperature (in °C) & humidity (in rH%) values from the DHT11 sensor and print their values on 16×2 LCD display. To see how to interface STM32 Blue Pill board with 16×2 LCD go to the the following post:
Interfacing STM32 Blue Pill with 1602 LCD

About DHT11 sensor:
The DHT11 is a device used to measure temperature and relative humidity. This sensor uses a resistive-type humidity measurement component and an NTC temperature measurement component which are connected to an integrated 8-bit microcontroller.
The DHT11 sensor uses only one data pin for the communication with the microcontroller which makes the connection circuit very simple. The DHT11 sensor can work with 3.3V and 5V microcontrollers with no problem.
There are two types of the DHT11 sensor: old type (AOSONG) and new type (ASAIR). The differences between the 2 types are summarized below:

DHT11 ASAIR VS AOSONG
DHT11 ASAIR VS AOSONG

Interfacing DHT11 Temperature & Humidity Sensor with STM32 Blue Pill circuit:
The image below shows project circuit diagram.

STM32F103C8 Blue Pill board with DHT11 humidity and temperature sensor circuit

Hardware required:
This is a summary of circuit required parts.

  • STM32 Blue Pill board   —> STM32F103C8T6 32-bit Arm Cortex-M3 MCU
  • 1602 LCD screen   —> HD44780 datasheet
  • DHT11 (RHT01) humidity and temperature sensor   —->  datasheet
  • 5.1k ohm resistor (R1)
  • 10k ohm variable resistor (R2)
  • Breadboard & jumper wires…
  • FTDI FT232RL USB-to-UART converter (for burning program file to the MCU)

Circuit description:
The DHT11 sensor has 4 pins (from left to right):
Pin 1 is power supply pin, connected to STM32 Blue Pill board 3V3 pin,
Pin 2: data pin, connected to STM32 Blue Pill board A6 pin (PA6),
Pin 3: not connected pin,
Pin 4: GND (ground), connected to STM32 Blue Pill board GND pin.
A pull-up resistor of 5.1k ohm is required because the DHT11 sensor output is open drain type.

There are some DHT11 breakout modules that comes with built-in pull up resistor as the one shown below. Using a module can make the circuit more cleaner and easier.

DHT11 Breakout board module

The main power source of the circuit comes from the micro USB port of the STM32 Blue Pill board with voltage of 5V. The board contains a voltage regulator that feeds the STM32F103C8T6 microcontroller with 3.3V. The 16×2 LCD module is powered with 5V from the STM32 Blue Pill board where its ‘VDD’ pin is connected to ‘5V’ pin of the board.

Other 1602 LCD pins are connected to the STM32 Blue Pill board as follows:
RS —> pin PA0
E   —> pin PA1
D4 —> pin PA2
D5 —> pin PA3
D6 —> pin PA4
D7 —> pin PA5
VSS, RW, D0, D1, D2, D3 and K are connected to circuit ground
VEE to the variable resistor (or potentiometer) output
VDD and A to +5V (from the board).
VEE pin is used to control the contrast of the LCD. A (anode) and K (cathode) are the back light LED pins.

Interfacing STM32F103C8T6 Blue Pill with DHT11 sensor Arduino code:
Arduino IDE is used to write project code, the STM32 Blue Pill board has to be added to the IDE before compilation.
The STM32 Blue Pill board can be installed using Arduino IDE Boards Manager.

The FT232RL USB to serial UART converter is used to program the STM32F103C8T6 microcontroller, the ST-LINK V2 programmer also can be used and it is supported by the Arduino IDE.

To make the Arduino code simple and easy to understood I used a library for the DHT11 sensor form Adafruit Industries. Installing the library is so easy, just go to Sketch —> Include Library —> Manage Libraries …, in the search box write “dht” and install the one from Adafruit (during installation of the library Arduino IDE may ask for installing Adafruit Unified Sensor library).
The library also can be installed manually (offline installation), first download it from the following GitHub link:
Adafruit DHT library             —->   direct link

You may need to install Adafruit Unified Sensor library if it’s not already installed, download link is below:
Adafruit Unified Sensor library   —->    direct link

After the download, go to Arduino IDE —> Sketch —> Include Library —> Add .ZIP Library … and browse for the .zip file (previously downloaded).

Hints:
The interfacing Arduino code uses two libraries, the first one is built-in library (comes with STM32 Blue Pill board installation) and the 2nd library is for the DHT11 sensor. The 2 libraries are included in the Arduino code as shown below:

The connection between the STM32 Blue Pill board and the 16×2 LCD is as shown in the above circuit schematic, it is defined in the Arduino code as shown below:

The Adafruit DHT library requires some definitions such as sensor type and data pin:

Rest of code is described through comments.

The following video shows my simple DIY circuit:

Proteus Simulation:
The interfacing of ST32F103C8T6 Blue Pill with DHT11 sensor project can be simulated using Proteus simulation software as shown in the video below:

Proteus simulation file download:
Interfacing STM32F103C8T6 Blue Pill with DHT11 sensor and 16×2 LCD Proteus simulation file download link is below, use Proteus version 8.15 or higher to open it.
Download

And the link below is Proteus library for the STM32F103C8T6 Blue Pill board. After the download put the file in Proteus library folder, for example in my case Proteus library folder path is: C:\ProgramData\Labcenter Electronics\Proteus 8 Professional\Library
Proteus library for the STM32F103C8T6 Blue Pill board

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top