Compare Digital Temperature Sensor DHT11 & DS18B20

major hardware.PNG

A month ago I purchased 2 Arduino Nano and a DHT11 temperature sensor along with some other components, last week I felt I should learn how to use them since I already bought them, I figured I should record my room’s daily temperature changes and plot a nice chart with it, so I hooked everything up, collected a few days data and I got this↓↓↓

dht11 reading.PNG


I was very disappointed, the sensitivity of DHT11 is only 1ºC, I didn’t check its specs when I buy it. I’ve learned my lesson, always read the specs carefully.

But I still want to plot a nice graph with accurate readings, then I remembered I have a Dallas DS18B20 temperature sensor with me, and its accuracy is ±0.5°C (-10°C to +85°C), slightly better than DHT11. Another good thing about this sensor is that it uses 1-Wire® communication interface, many DS18B20 can be connected to the same 1-Wire bus with one micro-controller board. (Actually both sensors use 1-Wire interface) I decided to compare these 2 sensors’ reading in the same environment, so I connected them to the same Arduino Nano, collect and save their readings about every 4 seconds. The graph is below↓↓↓

Blue: readings from DHT11

Orange: readings from DS18B20

both sensor graph.PNG


both sensor graph(zoomed2).PNG

As you can see, the DS18B20 is much more accurate than DHT11, other than that it’s cheaper, and allows simple 2 wire connection (powered by data line).

Actual Setup

Both temperature sensors are connected to the same Arduino Nano, the Arduino Nano is connected to my Raspberry Pi 3 via USB port, I prepared a python program to receive temperature data from Arduino and save data to a file. Another python program was prepared to read all data from the file and plot temperature graph. Matplotlib was used to generate the chart.

actual setup.PNG

led panel display temperature.PNG

Update 2017/11/26

I’ve added a I2C display panel to display the reading of these 2 sensors, but it’s still not very convenient to use, the display is small and I couldn’t get the reading remotely. So I decided to make a webpage to show my room temperature.

System Design

display temperature on webpage 1.PNG

There are 5 steps:

  1. Design a webpage. I modified a w3schools template for my webpage.
  2. Create a Simple HTTP Server to host my webpage. The server is running on my Raspberry Pi 3B.
  3. Connect the arduino nano (with 2 temperature sensors) to Raspberry Pi via USB port (to supply power & transfer data), temperature data will be transferred via the serial port. Prepare the arduino program and data collection program (python 2.7) for the Raspberry Pi.
  4. Make a websocket server (python, tornado) to send the data to my webpage in step 1, prepare the websocket client javascript code for the webpage.
  5. Run the websocket server & Simple HTTP Server program, open the webpage from my computer or hand phone and it works.

照片 26-11-17 下午11 12 41

Thanks for reading 🙂

One thought on “Compare Digital Temperature Sensor DHT11 & DS18B20

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s