Return to site

build an air quality tester with arduino

This will help you build a standalone air quality tester that can detect carbon monoxide, acetone, thinners, formaldehyde, alcohol, sneaky crop dusting, and other toxic gases.  Example video below.
You can pick up the components from Seeedstudio (who are my go to for pretty much everything maker-ish now).  You'll need:
1
broken image
Slide the Grove unit on top of your Arduino.  It's easy to orient as the pins only match up one way.
2
broken image
Find the buzzer, air quality sensor and 2 x LED sockets.  Add a red and green LED to the sockets.  Be sure to insert the LED pins the correct way around.  The negative terminal will be the shorter of the two.  
3
broken image
Connect the four components to your Grove with the following layout.
  • A0 - Air quality sensor
  • D2 - Green LED
  • D3 - Red LED
  • D4 - Buzzer
4
Download the Air Quality Sensor library and place it in your Arduino Library folder.  On a Mac the path should look like this > Documents/Arduino/Libraries/AirQuality.  This folder will contain 'AirQuality.cpp', 'AirQuality.h' and a folder called 'Examples'.
5
Connect your Arduino to your Mac/PC via USB and create a new blank sketch with the Arduino software.
6
Copy everything between the separators below and paste it into your sketch.  This is a variant of this code base which I've altered to include LED and sound alerts.
#include"AirQuality.h"
#include"Arduino.h"
AirQuality airqualitysensor;
int current_quality =-1;
#define GREEN 2 //assigns the green LED to D2
#define RED 3 //assigns the red LED to D3
#define SOUND 4 //assigns the buzzer to D4
void setup()
{
Serial.begin(9600);
airqualitysensor.init(A0);
pinMode(GREEN, OUTPUT);
pinMode(RED, OUTPUT);
pinMode(SOUND, OUTPUT);
}
void loop()
{
current_quality=airqualitysensor.slope();
if (current_quality >= 0)
{
if (current_quality==0) {
digitalWrite(RED, HIGH);
delay(50);
digitalWrite(RED, LOW);
delay(10);
digitalWrite(SOUND, HIGH);
delay(analogRead(0));
digitalWrite(SOUND, LOW);
delay(analogRead(0));
delay(100);}
else if (current_quality==1) {
digitalWrite(RED, HIGH);
delay(300);
digitalWrite(RED, LOW);
delay(100);
digitalWrite(SOUND, HIGH);
delay(analogRead(0));
digitalWrite(SOUND, LOW);
delay(analogRead(0));
delay(300)
;}
else if (current_quality==2) {
digitalWrite(RED, HIGH);
delay(500);
digitalWrite(RED, LOW);
digitalWrite(SOUND, HIGH);
delay(analogRead(0));
digitalWrite(SOUND, LOW);
delay(analogRead(0));
delay(500); }
else if (current_quality ==3) {
digitalWrite(GREEN, HIGH);
delay(500);
digitalWrite(GREEN, LOW);
delay(500);}
}
}
ISR(TIMER2_OVF_vect)
{
if(airqualitysensor.counter==122)
{
airqualitysensor.last_vol=airqualitysensor.first_vol;
airqualitysensor.first_vol=analogRead(A0);
airqualitysensor.counter=0;
airqualitysensor.timer_index=1;
PORTB=PORTB^0x20;
}
else
{
airqualitysensor.counter++;
}
}
7
Click the 'Verify' button to check your code is ok then hit 'Upload'.  The Arduino will then take about 20 seconds to start up. The Green LED should then start flashing indicating the code is running.  If it fails to respond you can:
  • Remove the LEDs from their sockets and turning them around.  The terminals may be matched up incorrectly.
  • In the Ardunio software, go to the 'Tools' menu and choose 'Serial Monitor'.  This lets you monitor output from the Arduino while it's connected.
8
broken image
Now you can remove the USB, add your 9V battery and take the sensor anywhere!  Have access to a 3D printer?  You can print a case like the one above to protect the Arduino while it's on the move.
There are a bunch of mods that could be done to add new features or make the code more efficient.  Enjoy.