Indoor Air Quality with a Pi Zero

I know, I’ve been absent so long that you’ve probably given up on me!  However, I have been doing some Python coding with my lovely little air quality set-up which measures the VOCs (Volatile Organic Compounds) in the air in my study room.

 

Breakout_Garden_pHAT_1_of_5_400x400Pimoroni_Shopping cart

I bought the sensor from: Pimoroni BME 680 air quality and decided to get a Pimoroni small form factor Breakout Garden* and an LED matrix, with 11 x 7 white LEDs,  to show the results in an graphic way.  I had a Pi Zero WH (Wi fi enabled and with male Header) already, to attach the Breakout Garden to, which I’d taken from a previous project so all I needed then was a micro SD card from my local supermarket.

*I used the Breakout Garden because, with no soldering needed, it was easy to get up and running quickly. It also looks beautiful which I appreciate!

The python program indoor-air-quality.py  was in the linked Python Library from:

Pimoroni BME 680 Air Quality and was just what I needed so I was able to get started.

Costs were roughly:                                                     £

Pi Zero WH                                                             13.00

Micro SD card                                                          9.00

BME680                                                                  18.50

Breakout Garden                                                    9.50

11 x 7 LED Matrix                                                  9.00

Booster header*                                                       2.00

61.00

You may also need a £5 set of Pi Zero adapters, which can be used again and again, and a USB hub so that you can connect a wired keyboard and mouse.

After an initial trial to check the BME680 was working OK, I realised there was a lot to know and found this: Forum post on air quality in which Sandy J Macdonald explains in detail how to use the BME680.

Next my task was to get the result from the BME680 and show it on the LED matrix. Again there’s a link to the Python Library for the LED matrix from: 11×7 LED matrix and I cobbled together bits of code to get a circle which I could put a smiley mouth in when the air quality was good.

AQ1_IMG_1092_crop

AQ2_IMG_1095

Air Quality good

I decided to just stick with a blank face when the air quality was bad. (My Python’s not great yet so I don’t want to run before I can walk!)

AQ3_IMG_1097

Air Quality bad

So I defined a function called face which could be used within the code to do the graphics.

Here’s my code. It’s not great, but remember I’m a newbie to python!

import time
import math

from matrix11x7 import Matrix11x7
matrix11x7 = Matrix11x7()

def face(air_quality):
  # Avoid retina-searage!
  matrix11x7.set_brightness(0.5)

  n = 400
  pi_over180 = 3.14159265/180.0
  radius = 2
  angle = 1
  i = 0

  for i in range(n):
    timestep = 360/n

    localx = (math.cos(angle*pi_over180)*radius*2)
    localy = (math.sin(angle*pi_over180)*radius*2)
    localx = int(localx)+ 5
    localy = int(localy)+ 3

    matrix11x7.set_pixel(localx, localy, 0.5)
    angle = angle + timestep

    time.sleep(0.0005)
    matrix11x7.show()

  # If air quality good, light up smile!

  if air_quality > 89.9:
    matrix11x7.set_pixel(4, 3, 0.5)
    matrix11x7.set_pixel(5, 4, 0.5)
    matrix11x7.set_pixel(6, 3, 0.5)
    time.sleep(0.0005)
    matrix11x7.show()
    time.sleep(1)

  else:
    matrix11x7.set_pixel(4, 3, 0)
    matrix11x7.set_pixel(5, 4, 0)
    matrix11x7.set_pixel(6, 3, 0)
    time.sleep(0.0005)
    matrix11x7.show()
    time.sleep(1)

  time.sleep(1)

Also, all the indentations went when I pasted it into here – so if they’re wrong I hold my hands up!

Then I added, at the end of the BME680 part, the statement:

face(air_quality_score)

into indoorairquality.py  and placed the function, face , in near the top and it worked!

Anyway, I can see me spending happy hours investigating the air quality in my study and messing about with VOCs, such as nail varnish remover, to really understand the topic of air quality.

If you’re doing a similar air quality project please get in touch.

*I’ve added a booster header so the BME680 air quality sensor isn’t so affected by the heating of the Pi Zero.

Happy tinkering!

 

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s