For that reason, he decided to take a break from a project he was working on – a device which monitors currency prices using Raspberry Pi Zero W – to create an air quality reporting system. Having found a battery-operated toy traffic light, he came up with a plan that was both practical and fun.
“If the wind blows in the direction of the city, you can smell the smoke, which some say resembles whiskey, and it means you don’t want to have the windows open for too long,” Dmytro says. “So, I came up with the idea of having the red light of a traffic light illuminate if this was to happen.”
Capturing air quality
Dmytro chose a traffic light made by German toy manufacturer Dickie. “It’s compact, has a button on top, and two additional LEDs accompanying the standard three,” he explains. But before he could connect it to a Raspberry Pi 3B+ computer, he needed to open the toy.
“I had to get rid of the traffic light’s internal components without damaging the LEDs or the internal structure of the toy,” he continues. “I also had to change the resistors so that it would work with Raspberry Pi’s GPIO pins, which produce 3.3 V.”
From there, it was a matter of working out the best way of capturing air quality, starting by experimenting with the MQ-135 gas sensor which monitors benzene, alcohol, and smoke. “I got it working after a few hours by connecting an additional analogue-to-digital chip to the serial port of Raspberry Pi,” he says. “But the measurements were not that precise and I had to write quite a bit of code to account for inaccuracies which varied drastically based on the environment temperature.”
Good to go
Instead, he turned to an MH-Z19B carbon dioxide sensor. “It was way more accurate and it worked, but only temporarily, as the elements in my area can be on the extreme side,” Dmytro says.
The solution, therefore, was to write a short program using the open-source programming language Go. It fetches Air Quality Index data from the website IQAir, which uses information from consumer devices located across Kyiv. It also grabs current data from OpenWeather in parallel.
By storing the data on Raspberry Pi, Dmytro’s script – written in Python – can determine which light to illuminate, controlling the LEDs using the Python library GPIO Zero. Red obviously shows that the air quality is poor, prompting Dmytro to close the windows and take precautions when venturing outside.
Even so, there is room for improvement. “The aggregated data is quite accurate but it covers the entire city,” he laments. “Sometimes it would make more sense for measurements to be more local. Collecting data myself and combining it with the information I get from the API should be the next step.”