Nate HardyHenry BartholomewGrayson Roberts
Published

Indoor Atmospheric Monitoring System (I.A.M.S.)

A desktop device to monitor the indoor air quality for a house, room, or apartment.

BeginnerFull instructions provided34
Indoor Atmospheric Monitoring System (I.A.M.S.)

Things used in this project

Hardware components

Argon
Particle Argon
×1
Temperature Sensor
Temperature Sensor
×1
Grove - Gas Sensor(MQ2)
Seeed Grove - Gas Sensor(MQ2)
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
RGB LED
×1

Software apps and online services

ThingSpeak API
ThingSpeak API
Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Circuit Diagram for the Sensor Board

Layout for the Sensor Board

Code

Code for the Sensor Borad

C/C++
This code is used for the sensor board and to transmit the data to the receiver code and board
//IOT Project I.A.M.S Indoor Air Quality Monitor
//Nate Hardy - 2021 

#include <Adafruit_DHT.h>   //Include the Afafruit DHT library

#define DHTPIN 5            //pin for DHT11 sensor
#define DHTTYPE DHT11	    //setting the correct DHT sensor type

DHT dht(DHTPIN, DHTTYPE);   //inilize the DHT sensor with the DHT pin and type specified

const int TMP36Pin = A1;    //TMP-36 temp sensor pin
const int MQ2 = A5;          //MQ-2 CO2 sensor pin

double voltage, TMP36F, TMP36C, h, t, f, MQ2value;
int reading = 0;

void setup() {
    //Start serial and print a message!
	Serial.begin(9600); 
	Serial.println("IOT PROJECT IAMS Serial Test OKAY");
	
	pinMode(TMP36Pin, INPUT);   //Start the pin for the TMP36 in input mode
	pinMode(MQ2, INPUT);        //Start the pin for the MQ-2 in input mode 
    
	dht.begin(); //Initilize the DHT sensor
	
	//Start the Paricle.io variables
	
	Particle.variable("DHT-11 in degF", f);
	Particle.variable("DHT-11 in degC", t);
	Particle.variable("DHT-11 in %h", h);
	
	Particle.variable("TMP36 in degF", TMP36F);
	Particle.variable("TMP36 in degC", TMP36C);
	Particle.variable("TMP36 volts", voltage);
	
	Particle.variable("MQ-2 Data", reading);
}

void loop() {
	delay(2000); // Wait a few seconds between measurements.
	
    MQ2value = analogRead(MQ2);         //Reading the data from the MQ-2 sensor
    reading = analogRead(TMP36Pin);  //Reading the data from the TMP36

//Convert data from the TMP36
    voltage = (reading * 3.3) / 4095.0;     //Convert data into 10mv/deg
    TMP36C = (voltage - 0.5) * 100.0;       //Calculate degC value
    TMP36F = (TMP36C * (9/5) ) + 32.0;      //Calculate degF from the degC value

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
	h = dht.getHumidity();      // Read humidity
	t = dht.getTempCelcius();   // Read temperature as Celsius
	f = dht.getTempFarenheit(); // Read temperature as Farenheit

// Check if any reads failed and exit early (to try again).
	if (isnan(h) || isnan(t) || isnan(f)) {
		Serial.println("Failed to read from DHT sensor!");
		//return;
	}
	
/*  ==============================================
                SENDING CLOUD DATA
    ============================================== */
	Particle.publish("DHT-11 in degF", String(f));
	Particle.publish("DHT-11 in %h", String(h));
	
	Particle.publish("TMP36 in degF", String(TMP36F));
   
    Particle.publish("MQ-2 Data", String(MQ2value));
    
/*  ==============================================
                SENDING SERIAL DATA
    ============================================== */
//MQ-2 Sensor Data
    Serial.println("MQ-2 DATA");
    Serial.println(MQ2value);
    Serial.println("");
    
//TMP-36 Sensor Data
    Serial.println("TMP-36 DATA");
    Serial.print("Voltage: ");
    Serial.println(voltage);
    
    Serial.print("degC");
    Serial.println(TMP36C);
    
    Serial.print("degF");
    Serial.print(TMP36F);

//DHT11 Sensor Data
    
	Serial.println("Humid: "); 
	Serial.print(h);
	Serial.print("% - ");
	Serial.print("Temp: "); 
	Serial.print(t);
	Serial.print("*C ");
	Serial.print(f);
	Serial.print("*F ");
	
// Compute heat index
// Must send in temp in Fahrenheit!
/*	float hi = dht.getHeatIndex();
	float dp = dht.getDewPoint();
	float k = dht.getTempKelvin(); */

	
/*	Serial.print(k);
	Serial.print("*K - ");
	Serial.print("DewP: ");
	Serial.print(dp);
	Serial.print("*C - ");
	Serial.print("HeatI: ");
	Serial.print(hi);
	Serial.println("*C");
	Serial.println(Time.timeStr()); */
}

Code for the Receiver Board

C/C++
This is the code for the receiver board which adjusts the LED corresponding to the data that is sent from the sensor board and program
//IOT Project IAMS Reciver code
//Nate Hardy - 2021

const int redP = 2;          //Pin for the Red of the RGB LED
const int greenP = 3;       //Pin for the Green of the RGB LED
const int blueP = 4;        //Pin for the blue of the RGB LED

const int baseTemp = 70;    //Base temperture to compare measured temp to
const int baseHumid = 30;   //Base humidity to compare measured values to
const int goodCO2 = 1350;   //CO2 level considered 'safe'

double temp;                                            //calculated temperture value
int DHT11TempVar, DHT11HumidVar, TMP36temp, MQ2Var;     //Varables for the sensor values from the other Argon
int red, green, blue;                                   //Values for red, green, and blue to be sent to the LED

void DHT11temp(const char *event, const char *data) {
    DHT11TempVar = atof(data);  //Reading the cloud data from the DHT-11 temperture
}

void DHT11humid(const char *event, const char *data) {
    DHT11HumidVar = atof(data); //Reading the cloud data from the DHT-11 humdity
}

void TMP36(const char *event, const char *data) {
    TMP36temp = atof(data);     //Reading the cloud data from the TMP-36 
}

void MQ2(const char *event, const char *data) {
    MQ2Var = atof(data);        //Reading the cloud data from the MQ-2 sensor
}

void RGBWrite(int redV, int greenV, int blueV) {
    analogWrite(redP, redV);                            //function to write data to the RGB LED
    analogWrite(greenP, greenV);
    analogWrite(blueP, blueV);
}

void setup() {
    Serial.begin(9600);                                 //Serial setup and self-test
    Serial.println("Serial Test OK");
    
    pinMode(redP, OUTPUT);                              //Setup pin mode for the RGB LED 
    pinMode(greenP, OUTPUT);
    pinMode(blueP, OUTPUT);
    
    red = 100;                                          //Initilize the values for the different colors
    green = 100;
    blue = 100;
    
    Particle.subscribe("DHT-11 in degF", DHT11temp);    //Subscribe to the data outputed from the other Argon
	Particle.subscribe("DHT-11 in %h", DHT11humid);
	
	Particle.subscribe("TMP36 in degF", TMP36);
   
    Particle.subscribe("MQ-2 Data", MQ2);
    
}

void loop() {
    delay(2000);
    
    Serial.println(DHT11TempVar);                       //print the serial data recived
    Serial.println(DHT11HumidVar);
    Serial.println(TMP36temp);
    Serial.println(MQ2Var);
    
    temp = (DHT11TempVar + TMP36temp)/2;                //Temperture average between the 2 sensors
    RGBWrite(0,0,0);
    
    if (MQ2Var >= goodCO2) {
        RGBWrite(255,0,0);                           
    } else if (temp >= baseTemp + 5) {
        RGBWrite(0,0,255);
    } else if (temp <= baseTemp - 5 ) {                        
        RGBWrite(0,0,255);   
    } else if (DHT11HumidVar <= baseHumid - 10) {
        RGBWrite(255,255,0);
    } else if (DHT11HumidVar >= baseHumid + 10) {
        RGBWrite(0,255,255);
    } else {
        RGBWrite(0,0,0);
    }
    
}

Credits

Nate Hardy

Nate Hardy

1 project • 0 followers
Henry Bartholomew

Henry Bartholomew

0 projects • 0 followers
Grayson Roberts

Grayson Roberts

0 projects • 0 followers

Comments

Add projectSign up / Login