Raspberry Pi and Dht11 humidity Sensor

DailyPriyab
DYI Electronics & Tech Reviews
4 min readApr 9, 2017
Raspberry Pi 3 with DHT11

This was a small weekend experiment which I wanted to try for a long time. I have tried DHT11 sensor with Arduino and it worked great but with Raspberry Pi I don’t know how well it would work.

Much of what I learnt and did in this tutorial is taken from the below link.

Another link which is a good read can be found here.

Now coming back to the sensors:

DHT11 Sensor

The diagram is given below, and I used the 4 pin version. The good thing about DHT11 is that it gives you both humidity and temperature both.

Factsheet for DHT11

  • Ultra low cost
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 20–80% humidity readings with 5% accuracy
  • Good for 0–50°C temperature readings ±2°C accuracy
  • No more than 1 Hz sampling rate (once every second)
  • Body size 15.5mm x 12mm x 5.5mm
  • 4 pins with 0.1" spacing

The circuit that I setup is based the below diagram

Circuit Diagram for Raspberry Pi

The final setup looked like below:

Basically if you see the circuit diagram you would find following connection.

VCC of DHT11 -> 5v Pin of Raspberry Pi 3

GND of DHT11 -> GND Pin of Raspberry Pi 3

Signal pin of DHT11 -> GPIO 4 Pin of Raspberry Pi3

Thing to remeber is to use a 10K ohm pullup resistor between VCC and signal pins of DHT11 4 pin version or the sensor data will not be fetched. I faced the same issue and even using 1 Ohm did not work.

For the code I used the below Adafruit library for DHT11 sensor which

The code is given below:

In this code we are reading the humidity and temperature information and uploading it to a HTTP endpoint http://192.168.0.8:1880 as json.

To make it more like an IOT experiment I also created a Node-red flow. Now Node red is a great IOT workflow manager where you design the flow by dragging and dropping connectors and it starts working. I used a very simple flow where I read data from an HTTP connection running at http://192.168.0.8:1880 and wrote to a file. The actual sensor data was fetched from a python program and fed to the HTTP connector of Node-red.

The screenshots of the Node-red flow is given below:

The flow digram in Node-red
Endpoint for receiving http data /payload
Write the data to a file called stream

Finally when running the example it captured the humidity and temperature data.

The temperature and humidity data as json

Given that this was my one of the first experiments with GPIO pins in Raspberry Pi, I was very happy and plan to do many more such experiments.

--

--

DailyPriyab
DYI Electronics & Tech Reviews

Data Engineering | Data Governance | Azure | Spark | Python | Manager