Raspberry Pi Projects

Raspberry Pi With Humidity Sensor Tutorial


A Raspberry Pi With Humidity Sensor is a great way to keep track of the moisture in your home. By reading the humidity level, you can adjust the amount of time you spend watering your plants or adjust the temperature in your home to ensure that your family is comfortable. By using a humidity sensor, you can also monitor the amount of moisture in the air. We will also show you how to write a Python script to read data from the sensor and print it to the terminal.

What is a Raspberry Pi?

Raspberry Pi With Humidity Sensor

A Raspberry Pi is a credit card-sized computer that was created with the intention of teaching people about computer programming. It has since been used for a variety of projects, from creating a homemade security system to building a robot.

What is a humidity sensor?DHT22 Sensor

A humidity sensor is a device that measures the amount of water vapor in the air. There are many different types of humidity sensors but most work by measuring the amount of water vapor in the air using a hygrometer. Humidity sensors are used in many different applications, such as weather stations, greenhouses, and incubators. If you need to measure humidity in the range of 20% – 90% (at 25 ° C) close humidity – DHT11 is good.


  • Dimensions 13 x 29 x 8 mm
  • 3 – 5.5V power supply
  • Average power consumption 0.2 mA
  • Communication: 1-Wire (OneWire)
  • Temperature measurement:   * Temperature measurement range 0 – 50 ° C    * 8-bit resolution (1 ° C)    * Accuracy 1 ° C    * Response time 6 – 15 s (typically 10 s)
  • Moisture measurement    * Humidity measurement range 20% – 90% RH (at 25 ° C) – in the full temperature range – 30% -80%    * 8-bit resolution (± 1% RH *)    * Accuracy ± 4 RH * (at 25 ° C)    * Measuring range 6 – 30 s    * Stability ± 1% RH / year

How to set up a Raspberry Pi With Humidity Sensor

A Raspberry Pi humidity sensor is a great way to measure the humidity in your environment. There are many different types of humidity sensors, but the most popular type is the DHT11. This sensor is relatively easy to set up, and it is very accurate. Here are the steps to setting up your own Raspberry Pi humidity sensor:

Connect the Raspberry Pi With Humidity Sensor.

connect the sensor to your Raspberry Pi. The sensor has three pins: power, ground, and data. Connect the power and ground pins to the corresponding pins on your Raspberry Pi, and connect the data pin to a GPIO pin.

Raspberry Pi With Humidity Sensor Tutorial e1654417357813

DHT Pin Signal Pi Pin
1  Data/Out 23 (GPIO22)
2 3.3v 1
3 GND 6 or 9

Python Library

The DHT11 needs a specific protocol to be used for the data pin. In order to save time trying to implement this yourself, it’s far easier to use the Adafruit DHT library. This library will allow you to read data from the sensor

Software Setup

To start with update your package lists and install a few Python libraries :

Then clone the Adafruit library from their repository :

Then install the library for Python 2 and Python 3 :

Hopefully, at this topic, the library is installed and watchful to be used within a Python script.

Adafruit Example Raspberry Pi With Humidity Sensor Python Script

Adafruit provides an example script that you can use to check whether your sensor is working correctly or not.

Then :

The example script takes two parameters. The first is the sensor type so is set to “11” to represent the DHT11.

The second is the GPIO number so for my example I am using “16” for GPIO16. You can change this if you are using a different GPIO pin for your data/out wire.

You should see an output similar to this :

Using the Library In Other Python Scripts

Once the Adafruit library is installed and you’ve got the example script to work you can use the sensor in your own scripts. Simply import the module, set up a few variables, and call the “read_retry” function :

This script can be downloaded directly to your Pi using :

and run using :


DHT11 Sensor with the Raspberry pi to find humidity and temperature

Read Similar Articles:

Related Articles

Leave a Reply

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

Back to top button

Adblock Detected

Please consider supporting us by disabling your ad blocker