Hello! Welcome to Embedic!
This website uses cookies. By using this site, you consent to the use of cookies. For more information, please take a look at our Privacy Policy.
Home > Embedded Events > Interfacing STM32 Blue Pill Board based on STM32F103C8T6 MCUs

Interfacing STM32 Blue Pill Board based on STM32F103C8T6 MCUs

Date: 07-11-2023 ClickCount: 971

In this tutorial I will describe how to interface the DHT11 humidity and temperature sensors with the STM32 Blue Pill Board based on the STM32F103C8T6 MCU. The values of the DHT11 sensors are read by the STM32 and displayed on the I2C LCD display.



Sensors are very small devices that bridge the gap between the raw analog world and the digital world of the MCU. Sensors can be very simple, such as the very famous LM35 temperature sensor, or they can be some complex mathematical unit, such as the MPU6050 gyroscope and accelerometer combination sensor.


Simple or complex, sensors are a key part of many consumer, automotive, robotics and industrial applications and some applications cannot be accomplished without integrating the proper sensors.


Let's expand from industrial applications to everyday projects and hobbyists. Weather stations are a very common and popular project for both IoT applications and regular character LCD applications.


The key component of such weather station projects is the ability to detect weather related parameters (such as temperature, humidity, etc.) The DHT11 humidity and temperature sensor is the device for these types of projects.


I have used the DHT11 sensor in an Arduino project called " DHT11 Humidity Sensor on Arduino" (first tweet). In that project, I have interfaced the DHT11 sensor with the Arduino, calculated the temperature and humidity values and displayed them on a 16×2 LCD display. I will do the same thing here, but this time I will interface the DHT11 humidity and temperature sensors to the STM32F103C8T6 MCU.


STM32F103C8T6 MCUs

STM32F103C8T6 Descriptions

The STM32F103C8T6 is a 32-bit ARM Cortex-M3 based microcontroller with 64 KB of Flash memory, 20 KB of SRAM, a range of built-in peripherals, and support for various communication interfaces, making it a versatile choice for embedded applications.


STM32F103C8T6 Features

  • Mounting Style: Surface Mount Device/Surface Mount Technology (SMD/SMT)
  • Package/Case: Low-profile Quad Flat Package with 48 pins (LQFP-48)
  • Core: ARM Cortex-M3
  • Program Memory Size: 64 kB of Flash memory
  • Data Bus Width: 32 bits
  • ADC Resolution: 12 bits
  • Maximum Clock Frequency: 72 MHz
  • Number of I/Os: 37 I/O (Input/Output) pins
  • Data RAM Size: 20 kB of SRAM (Static Random-Access Memory)
  • Supply Voltage - Min: 2 V
  • Supply Voltage - Max: 3.6 V
  • Minimum Operating Temperature: -40°C
  • Maximum Operating Temperature: +85°C
  • Packaging: Tray
  • Brand: STMicroelectronics
  • Data RAM Type: SRAM
  • Height: 1.4 mm
  • Interface Type: CAN, I2C, SPI, USART, USB
  • Length: 7 mm
  • Moisture Sensitive: Yes
  • Number of ADC Channels: 10 Channels
  • Number of Timers/Counters: 3 Timers/Counters
  • Processor Series: ARM Cortex-M
  • Product: Microcontrollers (MCUs)
  • Product Type: ARM Microcontrollers - MCU
  • Program Memory Type: Flash
  • Subcategory: Microcontrollers - MCU
  • Tradename: STM32
  • Width: 7 mm
  • Unit Weight: 0.006349 oz

STM32F103C8T6 Applications

  • Industrial Automation
  • Consumer Electronics
  • Internet of Things (IoT) Devices
  • Robotics
  • Home Automation
  • Motor Control
  • Audio and Musical Instrument Controllers
  • Power Supplies and Inverters
  • Medical Devices
  • Automotive Systems


DHT11 Temperature and Humidity Sensor

The DHT11 and its brother, the DHT22, are inexpensive but highly reliable humidity and temperature sensors.The DHT22's range and accuracy are slightly better than the DHT11's, but this extended range and tighter accuracy comes at a price. On top of that, both sensors look similar and have the same pins and connectivity. Therefore, from now on, we will focus on the sensor for this project, the DHT11.

DHT11 Temperature and Humidity Sensor

It is an ultra-low-cost sensor with a resistive humidity measurement component, an NTC-type temperature measurement component and an 8-bit microcontroller that converts the data from the two measurement components into digital values.


In the Arduino - DHT11 tutorial, I talked about how the sensor works and how to interpret the data from the serial. I recommend that you refer to that project for more information about this sensor.


Also, in that project I didn't use any dedicated libraries for the DHT11 humidity and temperature sensors, but tried my own code. For changes only, I will use the DHT library developed by Adafruit.


Connecting the DHT11 Humidity and Temperature Sensor to the STM32F103C8T6


Before proceeding, I must remind you of something in the DHT11 sensor datasheet. It says that the single data line between the DHT11 sensor and the microcontroller (STM32 in this case) must be pulled up with the help of a 5KΩ resistor.

Therefore, when purchasing a DHT11 sensor, try to buy a module that includes the said pull-up resistor (or even some energized LEDs). This makes connecting the DHT11 humidity and temperature sensors to the STM32F103C8T6 much easier as it does not require any other components.


Another thing to keep in mind is that I used an I2C LCD, i.e. an I2C GPIO expander module based on the PCF8574 module with a good old 16×2 LCD display. I have already implemented the same functionality in the dedicated project "Interfacing I2C LCD with STM32F103C8T6". Please refer to that project for more information.


Required Components

  • STM32 Blue Pill Board based on STM32F103C8T6 MCUs
  • DHT11 temperature and humidity sensor
  • 16×2 LCD display
  • PCF8574 I2C LCD module
  • 5KΩ resistor (optional, not required if resistor is on DHT11 module)
  • Connection cable
  • USB to UART converter (required only if programming via UART)
  • Circuit Diagram


Connection Instructions


First, connect the VCC and GND pins of the DHT11 Sensor to + 5V and GND respectively. then connect the data pin of the sensor to pin PA1 of the STM32 board.


When you come to the LCD, insert the PCF8574 I2C LCD module into the back of the LCD and connect the SDA and SCL pins of the PCF8574 module to pins PB7 and PB6 of the STM32 board, respectively. Similarly, connect the VCC and GND pins of the I2C LCD module to + 5V and GND.

Programming the STM32 to connect the DHT11


Before proceeding, make sure you have identified the slave address of the PCF8574 module mentioned in the I2C LCD tutorial. You can use the following code for the same.


void setup()




while (!Serial); }


void loop()

} void loop(); } void loop(); } void loop()

byte error, address; int I2CDevices.

int I2CDevices.

Serial.println("Scanning for I2C Devices...");

I2CDevices = 0; for (address = 1; address < 127; address < 0)

for (address = 1; address < 127; address++ )


Wire.beginTransmission(address); error = Wire.endTransmission(address); }

error = Wire.endTransmission(); if (error == 0); I2CDevices = 0; for I2C Devices.

if (error == 0)

error = Wire.endTransmission(); if (error == 0) {

Serial.print("I2C device found at address 0x"); if (address < 16)

if (address < 16)

Serial.print("0″); if (address < 16)

Serial.print(address, HEX); Serial.println("!

Serial.println(" !"); if (address < 16) Serial.print(address, HEX); Serial.println(" !") ;



else if (error == 4)

} else if (error == 4)

Serial.print("Unknown error at address 0x"); if (address < 16); } else

Serial.print("Unknown error at address 0x"); if (address < 16)

Serial.print("0"); Serial.println(address, HEX); if (address < 16)

Serial.println(address, HEX);



Serial.println(address, HEX); } } if (I2CDevices == 0)

Serial.println("No I2C devices found "); } if (I2CDevices == 0)

Serial.println("No I2C devices found "); }

Serial.println("**** ");

Serial.println(" "); delay(5000);



Now for the actual program ahead, start by downloading the DHT library from this link. Unzip the zip file and copy its contents to the library folder of your local Arduino installation. The path is usually " C: Program Files (x86) Arduino libraries".


Then, in the program, define the data pin of the DHT as PA1 and the type of the DHT sensor as DHT11 or DHT22. Declare the I2C LCD with the LiquidCrystal_I2C library functionality by mentioning the slave address, the number of columns and the number of rows. Now you can initialize the LCD and the DHT11 sensor using the respective "Start" function.


Now, get the two floating point values and get the humidity and temperature readings from the sensors. Finally, print these values on the LCD.


Source Code



#define DHTPIN PA1
#define DHTTYPE DHT11

LiquidCrystal_I2C lcd(0x27, 16, 2);
byte degree_symbol[8] =

void setup()

lcd.print(“Electronics Hub”);
lcd.print(“DHT11 with STM32”);
lcd.print(“Temp = “);
lcd.print(“Humid = “);
lcd.createChar(0, degree_symbol);

void loop()
float hum = dht.readHumidity();
float tem = dht.readTemperature();


A simple project has been implemented here to demonstrate the interface of the DHT11 humidity and temperature sensors with the STM32 Blue Pill Board based on the STM32F103C8T6 MCU.

  • Programming the STM32 Blue Pill with the Arduino IDE
  • VLSI VS Embedded Systems: What are Differences


Kristina Moyes is an experienced writer who has been working in the electronics industry for the past five years. With a deep passion for electronics and the industry as a whole, she has written numerous articles on a wide range of topics related to electronic products and their development. Kristina's knowledge and expertise in the field have earned her a reputation as a trusted and reliable source of information for readers interested in the latest advancements in electronics.

Hot Products

  • TMS320C6657SCZH

    Manufacturer: Texas Instruments


    Product Categories: DSP



  • TMS320DM647CUT9

    Manufacturer: Texas Instruments


    Product Categories: DSP



  • TMS320DM648CUTA6

    Manufacturer: Texas Instruments


    Product Categories: DSP



  • TMS320DM648CUTD9

    Manufacturer: Texas Instruments


    Product Categories: DSP



Customer Comments

  • Looking forward to your comment

  • Comment

    Verification Code * 

Compare products

Compare Empty