Smart and Private Open Source Sensor Station

The internet is full of tutorials on how to read digital and analog sensors, now it is time to do something useful with this data.

Story
While working very concentrated on projects (like this one) it happens quite often to me that I forget about my environment. Suddenly sitting in the dark or not recognizing that fresh air is needed is not uncommon. Previously, I purchased a well known branded fancy Smart Sensing Weather Station, and I really loved how packed it was with sensors. I loved how much data they provided. But tinkering with it, I realized, I didn’t have local access to my personal data on a bloody device that is literally sitting next to me. The device only works with an internet connection, and all of my data is stored on their servers.

Having a sensor/device connected to the internet does not make it smart!
As a tinkerer I thought I can do that as well and maybe even better, get the same sensor data, add notifications and statistics to it all, but with the slight difference that my data and logic will be stored and processed locally.

So here’s what I did: I took my Raspberry Pi and attached sensors to it for temperature, humidity, air quality, ambient light and a barometric pressure. I decided to use nymea, my favorite IoT middle-ware, and wrote plug-ins for the sensors. Nymea provides a bunch of stuff out of the box, such as logging, statistics, notifications and rules, so that would easily allow me to add some actual smart behavior in my environment.

Components
I used several I²C sensors, which I got from Amazon. I was looking for a I²C air quality sensors, but I wasn’t able to find any for a reasonable price, so I hooked a cheap analog air quality sensor to an Analog to Digital Converter (ADC for short). I used a Raspberry Pi 3B+, but a similar hardware platform, that supports the I²C interface would do just fine.

The temperature and humidity sensor: I found the SHT30 sensor would be most suitable for my use case. It was cheap, and took care for the physical influence between humidity and temperature. Reading the values using the data sheet was straight forward.
The pressure sensor: very popular pressure sensor is the BMP180. Using this sensor, I could also get the temperature and humidity, since those values are needed for a correct measurement. The sensor was calibrated in the factory, and the calibration data was stored in the chip, which I found very neat. The data sheet provided me with all the necessary steps on how to get the pressure. You could also calculate the altitude if you want to, but I didn’t really need that for my use case
The light intensity sensor: There are a lot of sensors out there for this purpose. I was looking specifically for one, that is suited for measuring the visible light, since I wanted to use this sensor for my living room. I chose the TSL2561, which gives me the full spectrum of light intensity measurement, and additionally, gave me the infrared light intensity spectrum separately. That was really handy, because it allowed me to subtract the infrared spectrum measurement, from the full spectrum, and that results in a light measurement suitable for humans.
The air quality sensor. Finding a suitable air quality sensor without spending a bunch of money proved to be a bit challenging. I ended up with an analog MQ-135 air quality sensor. It measures different gases in the air like NH3, NOx, alcohol, benzene, smoke and CO2. Digging on more information for this sensor has shown that it’s not the easiest thing to single out a certain gas from the sensor. The calibration had to be done for each individual sensor (finding R0) and the sensor needed a “burn in” phase of at least 24 hours before giving any useful data. A detailed description and an in-depth research on the sensor can be found here. The code of the mathematical model behind it can be found here. I implemented the model and the result was more informative than accurate in my case, but more on that later.
Wiring the sensors
Since I²C is a parallel bus and each I²C device has a different default register address, there was no need to change the address and all devices can be connected directly. The air quality sensor has an analog output, therefore an ADC was needed. For this I used the ADS1115 ADC, also connected to the I²C bus allowing me to read the analog value as digital representation. There are still three free inputs, I’ll probably extend the station with additional sensors in the future. I placed the temperature sensor as far away from the air quality sensor as possible, since the air quality sensor contains a heating element which gets hot.”

Link

Related Content