Coding to get data from the sensor module
This section describes how to code a program for both the Blue Pill and the Curiosity Nano boards so that they can read values from the DHT11. You will also learn how to program the LM35 temperature sensor with the Blue Pill. Let's start by programming the DHT11 sensor for the Blue Pill board.
Programming the DHT11 sensor for the Blue Pill board
In this section, you will review the code that gets data from the DHT11 sensor using a special library. The code will also show you how to display the temperature and humidity data on the serial port, and thus on the Arduino IDE's serial monitor. The following code reads both the temperature and humidity from a DHT11 sensor module, which is connected to digital input port B12
of the Blue Pill:
#include <DHT.h> #define DHT11_data_pin PB12 DHT dht(DHT11_data_pin, DHT11); void setup() { Â Â Â Â Serial.begin(9600); Â Â Â Â while (!Serial); Â ...