Measuring and recording the room temperature with a Raspberry Pi
The Raspberry Pi is a small embedded computing device that you can use for many different software and hardware projects. One of the first projects I did with the Pi was turning it into a device that would measure, record and display the room temperature.
To make the project, you will of course need a Raspberry Pi. I use my old Raspberry Pi model B, any newer one would also work. You also need a DS18B20 temperature sensor and a RRU 4K7 resistor. You can buy the separately, or you can buy the Raspberry Pi YouTube Workshop Kit that also contains both parts.
To connect the temperature sensor to the Pi, I suggest you follow the YouTube tutorial for the kit. You can also solder the temperature sensor and the resistor into one piece and connect it to the Pi using this schema, so the result then looks like this
The advantage of using the DS18B20 temperature sensor is that Raspbian and all the other Raspbian based Linux distors for the Pi contain drivers for it. There are two drivers that you need to load to make it work, the w1-gpio and the w1-therm. You can load them using
sudo modprobe w1-gpio sudo modprobe w1-therm
or just add them to /etc/modules so they autoload with each boot of the Pi.
When the temperature sensor is connected and both drivers are loaded, a new device will appear in /sys/bus/w1/devices/. On my Pi, it is 28-000004e23e98, execute
to find the id on yours.
I am a .NET developer but running Mono on the Pi just seems strange to me, so I decided to use Node.js to create the UI. You can find the whole project on Github. It is a simple Node.js server that gets the temperature and shows it.
Getting the temperature is a matter of a simple cat command to the right place
and parsing the result.
I decided to use SQLite for storing the data and create a simple endpoint that gets the current temperature and stores it in the database. I recommend using cron to call the endpoint with the periodicity you want.
You can then use the /history endpoint to get the temperature stats.
You can get, download, fork the whole project from https://github.com/igorkulman/rpi-thermometer.