6.2 - Temperature - Humidity

Humidity and temperature are closely related from the physical quantity itself to the actual people’s life. The temperature and humidity of human environment will directly affect the thermoregulatory function and heat transfer effect of human body. It will further affect the thinking activity and mental state, thus affecting the efficiency of our study and work.

Temperature is one of the seven basic physical quantities in the International System of Units, which is used to measure the degree of hot and cold of an object. Celsius is one of the more widely used temperature scales in the world, expressed by the symbol “℃”.

Humidity is the concentration of water vapor present in the air. The relative humidity of air is commonly used in life and is expressed in %RH. Relative humidity is closely related to temperature. For a certain volume of sealed gas, the higher the temperature, the lower the relative humidity, and the lower the temperature, the higher the relative humidity.


A basic digital temperature and humidity sensor, the DHT11, is provided in this kit. It uses a capacitive humidity sensor and thermistor to measure the surrounding air and outputs a digital signal on the data pins (no analog input pins are required).







  • You can open the file 6.2_dht11.ino under the path of euler-kit/arduino/6.2_dht11.

  • Or copy this code into Arduino IDE.

  • For detailed tutorials, please refer to Open & Run Code Directly.

Don’t forget to select the Raspberry Pi Pico board and the correct port before clicking the Upload button.

After the code is run, you will see the Serial Monitor continuously print out the temperature and humidity, and as the program runs steadily, these two values will become more and more accurate.

How it works?

Initialize the DHT11 object. This device requires only a digital input to be used.

int pinDHT11 = 16;
SimpleDHT11 dht11(pinDHT11);

Reads the current temperature and humidity, which are stored in the variables temperature and humidity. err is used to determine the validity of the data.

byte temperature = 0;
byte humidity = 0;
int err = dht11.read(&temperature, &humidity, NULL);

Filter invalid data.

if (err != SimpleDHTErrSuccess) {
    Serial.print("Read DHT11 failed, err=");

Print temperature and humidity.

Serial.print(" *C, ");
Serial.println(" H");

Finally, the DHT11 sampling rate is 1HZ, a delay(1500) is needed in the loop.