Measuring air quality with the Raspberry Pi

Lead Image © Oleksiy Tsupe,

Fresh Air

Monitor your environment with a Raspberry Pi and an air quality sensor.

As you know from prior columns and articles, the folks at SwitchDoc Labs have always had a passion for building weather instruments and sensors. Recently, we had a successful Kickstarter project for a product called "OurWeather." Basically, it's a complete weather station kit using Grove connectors to minimize soldering and make the electronics more accessible to people that aren't crazy about soldering in general.

The kit is based on an ESP8266 WiFi computer and can be programmed with the Arduino IDE. The product is doing quite well, and people are starting to ask for extender kits to sense more environmental variables. The first sensor I want to build is an air quality sensor (AQS) based on the TP-401A indoor air quality gas sensor (Figure 1). The components you will need for this project are shown in the "Parts List" box.

Figure 1: Block diagram of AQS and DataLogger.

The TP-401A connects to the Raspberry Pi (Rasp Pi) using a Grove 4-channel, 16-bit, analog-to-digital converter (one of the missing boards for the Rasp Pi!). The Rasp Pi logs data and graphs the results with the new Raspberry data logging and graphing software. MatPlotLib produces the graphs on the Rasp Pi.

TP-401A Air Quality Sensor Theory

The TP-401A sensor is very sensitive to a number of air-contaminating substances at low concentrations, including second-hand smoke, carbon monoxide (CO), alcohol, volatiles of cosmetics (especially hair spray, as you will see later), acetone, thinner, insecticides, benzene, formaldehyde, and others. Because it is sensitive to alcohol and formaldehyde, perhaps one should refrain from drinking cocktails with maraschino cherries around the sensor.

The sensor is composed of SnO2 materials doped with a catalyst, making it a metal oxide semiconductor type of gas sensor. The resistance of the sensor decreases when contaminating gases are present and increases when the gases are removed from the environment. To operate, the device needs to be heated to about 200-400°C, which is what causes a current of about 50mA. A typical response of the sensor to 20ppm (parts per million) CO is an increase in voltage up to about 0.25~0.60V (Figure 2).

Figure 2: The TP-401A sensor. VH is voltage to the heater (5V), which takes 3-5 minutes to warm up; Vc is voltage to the circuit (also 5V). When exposed to a contaminant, the load resistor (RL) connected to the circuit decreases resistance, and the measured voltage (VL) increases.


As you can see in Figure 3, the parts go together easily with the Grove cables. To measure the current going to the AQS, you need to make a special Grove cable (with the power line cut) to put the INA3221 in line with the Grove connector. For more information, take a look at the tutorial on measuring current with the Grove INA3221 [5] for details.

Figure 3: The assembled AQS DataLogger.

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content