DESIGNED V1d FOR RASPBERRY PI 400. COMPATIBLE WITH RASPBERRY PI 2, 3 AND 4.
INTRODUCTION The MonkMakes Air Quality Kit for Raspberry Pi is based around the MonkMakes Air Quality Sensor board. This add-on for the Raspberry Pi measures the quality of the air in a room (how stale the air is) as well as the temperature. The board has a display of six LEDs (green, orange and red) that display the air quality and a buzzer. Temperature and air quality readings can be read by your Raspberry Pi, and the buzzer and LED display can also be controlled from your Raspberry Pi.
PARTS Please note that a Raspberry Pi is NOT included in this kit. Before you do anything else, check that your kit includes the items below. Air Quality Sensor Board for Raspberry Pi. Female to male jumper wires.
AIR QUALITY AND ECO2 The Air Quality Sensor board uses a sensor with a part number of CCS811. This small chip does not actually measure the level of CO2 (carbon dioxide) but instead the level of a group of gasses called volatile organic compounds (VOCs). When indoors, the level of these gasses rises at a fairly similar rate to that of CO2, and can therefore be used to estimate the level of CO2 (called the equivalent CO2 or eCO2).
SETTING UP Whether you are using a Raspberry Pi 400 or a Raspberry Pi 2, 3 or 4, make sure that the Raspberry Pi is shutdown and powered off before you connect the Air Quality Sensor. The Air Quality Sensor will display the eCO2 readings as soon as it gets power from your Raspberry Pi. So, once you have connected it, the display should indicate the eCO2 level. You will then learn how to interact with the board, receiving readings and controlling the LEDs and buzzer from a Python program.
Connecting the Air Quality Sensor (Raspberry Pi 2/3/4) If you have a Raspberry Pi 2, 3, 4, then you will need the Raspberry Leaf and some female to male jumper wires to connect the Air Quality Sensor board to your Raspberry Pi. WARNING: Reversing the power leads or connecting the Air Quality Sensor to 5V rather than the 3V pin of the Raspberry Pi is likely to break the sensor and may damage your Raspberry Pi. So, please check the wiring carefully before powering on your Raspberry Pi.
Once it's all connected, it should look like this: Check your wiring carefully and then power up your Raspberry Pi -- both the power LED (in the MonkMakes logo) and one of the LEDs should also light. Unplugging the Air Quality Board Before removing the board from a Raspberry Pi 400. 1. Shutdown the Raspberry Pi. 2. Gently ease the board off the back of the Pi 400, edging it a little from each side in turn, so as not to bend the pins.
Enabling the Serial Interface Even though the board will show the eCO2 level without any programming, that means we are just using the Raspberry Pi as a power source. To be able to interact with the board from a Python program, on our Raspberry Pi, there are a few more steps that we need to take. Downloading the Example Programs The example programs for this kit are available for download from GitHub. To fetch them, start a browser window on your Raspberry Pi and go to this address: https://github.
Download a zip archive of the project by clicking on the Code button and then the Download ZIP option. Once the download is finished, extract the files from the ZIP archive by finding the ZIP file in your Downloads folder and then then right-clicking on it and selecting the option Extract To.. Select a suitable directory (I would recommend your home directory – /home/pi) and extract the files. This will create a folder called pi_aq-main. Rename this to just pi_aq.
Thonny Having downloaded the programs, you could just run them from the command line. However, it's good to take a look at the files, and the Thonny editor will allow us to edit the files and to run them. The Thonny Python editor is pre-installed in Raspberry Pi OS. You will find it in the Programming section of the main menu. If for any reason it's not installed on your Raspberry Pi, then you can install it using the Add / Remove Software menu option on the Preferences Menu item.
GETTING STARTED Before we start the Python programming, let's take a look at the Air Quality Board. The power indicator LED in the top left, provides a quick check that the board is receiving power. Below this is a temperature sensor chip, and next to this is the eCO2 sensor chip itself. If you look closely at it, you will see that it has tiny holes for the air to get in and out. Directly beneath the eCO2 sensor is a buzzer, that you can turn on and off from your programs.
console, by typing the following commands: $ cd /home/pi/pi_aq $ python3 Open the local aq module by typing the command: >>> from aq import AQ >>> Then create an instance of the AQ class by typing: >>> aq = AQ() >>> We can now read the CO2 level by typing the command: >>> aq.get_eco2() 434.0 >>> So in this case, the eCO2 level is a nice fresh 434 ppm. Lets get the temperature now (in degrees Celcius). >>> aq.get_temp() 20.
PROGRAM 1. ECO2 METER When you run this program the window similar to the one shown below will open, showing you the temperature and eCO2 level. Try putting your finger on the temperature sensor and the temperature readings should rise. You can also breathe gently on the eCO2 sensor and the readings should increase. To run the program, Load the file 01_aq_meter.py in Thonny and then click on the Run button.
Here's the code for the project. The code makes use of the GUI Zero library which you can read more about in Appendix B. import threading import time from guizero import App, Text from aq import AQ aq = AQ() app = App(title="Air Quality", width=550, height=300, layout="grid") def update_readings(): # update fields with new # temp and eCO2 readings while True: temp_c_field.value = str(aq.get_temp()) eco2_field.value = str(aq.get_eco2()) time.sleep(0.5) t1 = threading.Thread(target=update_readings) t1.
PROGRAM 2. ECO2 METER WITH ALARM This program extends Program one, by making use of the buzzer and some fancy user interface features, to make an alarm sound and the window turn red if a set level of eCO2 is exceeded. The slider at the bottom of the window sets the eCO2 level at which the buzzer should sound and the window turn red. Try setting the Alarm level a little higher than the current eCO2 level and then breathe on the sensor.
Here is the code for Program 2, much of it is very similar to Program 1. Areas of interest have been highlighted in bold. import threading import time from guizero import App, Text, Slider from aq import AQ aq = AQ() app = App(title="Air Quality", width=550, height=400, layout="grid") def update_readings(): while True: temp_c_field.value = str(aq.get_temp()) eco2 = aq.get_eco2() eco2_field.value = str(eco2) if eco2 > slider.value: app.bg = "red" app.text_color = "white" aq.buzzer_on() else: app.
PROGRAM 3. DATA LOGGER This program (03_data_logger.py) doesn't have a graphical interface. It just prompts you to enter an interval in seconds between readings, followed by the name of a file in which to save the readings. In the example above, sampling is set to 5 seconds and the file is called readings.txt. When you have finished logging data, CTRL-c will end logging and close the file. The data are saved in the same format as they are shown in the screen capture above.
Click OK to import the data, and then select the column for the eCO2 readings. You can then plot a graph of these readings by selecting Chart from the Insert menu, and then choosing a Chart type of Line, followed by Line Only. This gives you the graph shown on the next page.
As an experiment, try leaving the logger program running for a 24 hour period to see how the eCO2 level changes throughout the day.
APPENDIX A. API DOCUMENTATION For the serious programmers – here is the technical documentation. The file monkmakes_aq.py is not installed as a full Python library, but should just be copied into the same folder as any other code that needs to use it. aq.py The monkmakes_aq.py module is a class that wraps the serial communication between your Raspberry Pi and the Air Quality board. Creating an instance of AQ: aq = AQ() Reading the eCO2 reading aq.
APPENDIX B. GUI ZERO Laura Sach and Martin O’Hanlon at The Raspberry Pi Foundation have created a Python library (GUI Zero) that makes it super easy to design GUIs. This kit uses that library. Before you can use the library, you need to import the bits of it that you want to use in your program.
TROUBLESHOOTING Problem: The board is plugged into my Pi 400 but the power LED is not lit. Solution: Check that the GPIO pins are lined up correctly with the socket. See page 4. Problem: The board is plugged into my Pi 400 but the power LED is flashing rapidly. Solution: This indicates a problem with the sensor. Sometimes, all it needs is for the power to be reset by turning your Raspberry Pi off and on again.
LEARNING Programming & Electronics If you want to learn more about programming the Raspberry Pi and Electronics, then the designer of this kit (Simon Monk) has written a number of books that you might enjoy. You can find out more about books by Simon Monk at: http://simonmonk.
MONKMAKES For more information on this kit, the product's home page is here: https://monkmakes.com/pi_aq As well as this kit, MonkMakes makes all sorts of kits and gadgets to help with your maker projects. Find out more, as well as where to buy at: https://www.monkmakes.com/products You can also follow MonkMakes on Twitter @monkmakes.