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↓↓↓
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
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).
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.
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.
There are 5 steps:
- Design a webpage. I modified a w3schools template for my webpage.
- Create a Simple HTTP Server to host my webpage. The server is running on my Raspberry Pi 3B.
- 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.
- Run the websocket server & Simple HTTP Server program, open the webpage from my computer or hand phone and it works.
Thanks for reading 🙂