MQ135 and DHT22- Datalogging- Sensor Workshop

For the datalogging assignment Hanny and I decided to test the MQ-135 Air Quality Control Sensor along with a DHT22 Humidity & Temperature Sensor.

The MQ-135  detects a wide range of gases including NH3, NOx, alcohol, benzene, smoke and CO2. The gas sensing layer reacts to changes in SnO2, Tin Dioxide, which has a lower conductivity in clean air. When the target combustible gas exists, the sensors conductivity gets  higher as the gas concentration rises.

We decided to read the air pollution in three different places in  the ITP shop. As students, we spend so much time there, knowing the air quality could explain random moments of genius or the opposite in our work….We know the temperature and humidity of an environment can affect the gas sensor’s readings. We had the Arduino log the data onto a text file on an SD card. We then imported the readings into excel, compiled, and charted.

We took each reading for 30 minutes.

Location 1: the blue bins at the back of the shop

Location 2: hazardous, flammable substances cabinet

Location 3: wood shop

First, we tested each sensor separately to make sure it worked and how long it took to read properly. The sensors can take a little time so we decided to do a 30 minutes reading knowing that the last 10 minutes of the readings would be the most accurate.

We also formatted the SD card using Disk Utility on the Mac and using the SD Card Test sktech from the Arduino examples.

Once everything was working, calibrated, and set up, we proceeded to start.

Bellow, the circuit board set up.

This is the code we wrote after combining code from various sources. We combined code from Adafruit, Tom Igoe’s, and Instructables.

#include <SD.h>

#include “DHT.h”
#define DHTPIN 2 // what pin we’re connected to
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

const int chipSelect = 10;
void setup()
{
Serial.begin(9600);

// Serial.println(“DHTxx test!”);
dht.begin();

// Serial.print(“Initializing SD card…”);
pinMode(10, OUTPUT);

if (!SD.begin(chipSelect)) {
//Serial.println(“Card failed, or not present”);
}
// Serial.println(“card initialized.”);
}

void loop()
{

// make a string for assembling the data to log:
String dataString = “”;

//Sensor code starts

int sensor1 = 0;
int sensor2 = 1;

// TEMP- HUMIDITY CODE
int h = (int)dht.readHumidity();
int t = (int)dht.readTemperature();

// (not a number) then something went wrong!
// if (isnan(t) || isnan(h)) {
// Serial.println(“Failed to read from DHT”);
// } else {
// Serial.print(“Humidity, “);
Serial.println(h);
//Serial.print(” ,t”);
// Serial.print(“,Temperature, “);
Serial.println(t);
// Serial.println(” ,”);
// }

// GAS CODE
int g = analogRead(0); // read analog input pin 0
Serial.println(g);

delay(1000);
//END OF SENSOR CODE

//START OF STRING CODE

dataString = String(t) + “, ” + String(h) + “, ” + String(g);

// open the file. note that only one file can be open at a time,
File dataFile = SD.open(“datalog.txt”, FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn’t open, pop up an error:
else {
Serial.println(“error opening datalog.txt”);
}
}

The value we  are measuring is a function of Vrl- the voltage.

Vrl = sensorValue * 5.0 / 1024.0. Vc is 5.0 volts when connected to the regulated power source on the Arduino.

See below  for excel graph with values for the three locations.

 

Then we separate graphs for each kind of reading, one for the temperature, one for the humidity, and one for the gas.

Temperature Graph:

Humidity Reading:

Gas Reading:

What we are looking for are differences  in the overall gas readings. We can see that the gas reading is very different, much lower bet 2.5-3 in the wood shop where the humidity is at its highest and the temperature is at its lowest. The next step would be use different gas sensors in the shop and see what the MQ135 is reacting too. This way we would find out if the lower reading means a dirtier or cleaner air and what gases the MQ 135 is reacting to.

The other interesting thing to notice about the graphs.  For the readings by the blue bins, we notice that the humidity is more or less constant. However as the temperature drops so does the gas value, so there may be a relationship between a lower temperature and a lower MQ 135 reading. This is also something we should test again.

Sources:

www.adafruit.com

http://hwsensor.en.alibaba.com

http://wiring.org

wwww.instructables.com

www.arduino.cc

ww.pololu.com