Hackster will be offline on Monday, June 15 from 5pm to 7pm PDT to perform some scheduled maintenance.
Elias Manolakos
Published

Indoor Air Quality Monitor

This uses a combination of devices to monitor the gas levels, temp and humidity, and an rtc module to determine overall air quality.

IntermediateShowcase (no instructions)5 hours34
Indoor Air Quality Monitor

Things used in this project

Hardware components

Arduino Nano
×1
MQ135
×1
Gravity: DHT11 Temperature Humidity Sensor For Arduino
DFRobot Gravity: DHT11 Temperature Humidity Sensor For Arduino
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
Pushbutton Switch, Momentary Spring Return
Pushbutton Switch, Momentary Spring Return
×2
High Accuracy Pi RTC (DS3231)
Seeed Studio High Accuracy Pi RTC (DS3231)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Air Quality Monitor layout

Schematics

Breadboard layout

Code

Untitled file

C/C++
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
#include <dht.h>


#define MQ2pin A0
#define DHTpin 8
#define button1Pin 2
#define button2Pin 3


dht DHT;
RTC_DS3231 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);


volatile bool showTempHum = false;
volatile bool showGas = false;


char daysOfTheWeek[7][4] = {
  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};


void handleButton1() {
  showTempHum = true;
}


void handleButton2() {
  showGas = true;
}


void setup() {
  Wire.begin();
  rtc.begin();


  lcd.init();
  lcd.backlight();


  pinMode(button1Pin, INPUT_PULLUP);
  pinMode(button2Pin, INPUT_PULLUP);


  attachInterrupt(digitalPinToInterrupt(button1Pin), handleButton1, FALLING);
  attachInterrupt(digitalPinToInterrupt(button2Pin), handleButton2, FALLING);


  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}


void loop() {


 
  DHT.read11(DHTpin);


 
  float t = (DHT.temperature * 9.0 / 5.0) + 32.0;


  float h = DHT.humidity;
  int gasValue = analogRead(MQ2pin);


 
  if (showTempHum) {
    showTempHum = false;


    lcd.clear();


    lcd.setCursor(0, 0);
    lcd.print("Temp: ");
    lcd.print(t);
    lcd.print((char)223);
    lcd.print("F");


    lcd.setCursor(0, 1);
    lcd.print("Humi: ");
    lcd.print(h);
    lcd.print("%");


    delay(4000);
  }


 
  if (showGas) {
    showGas = false;


    lcd.clear();


    lcd.setCursor(0, 0);
    lcd.print("Gas Level:");


    lcd.setCursor(0, 1);
    lcd.print(gasValue);


    delay(4000);
  }


 
  DateTime now = rtc.now();


  lcd.clear();


  lcd.setCursor(0, 0);
  lcd.print(now.year());
  lcd.print('/');
  lcd.print(now.month());
  lcd.print('/');
  lcd.print(now.day());


  lcd.setCursor(0, 1);
  lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
  lcd.print(" ");


  lcd.print(now.hour());
  lcd.print(':');


  if (now.minute() < 10) {
    lcd.print('0');
  }
  lcd.print(now.minute());


  delay(1000);
}

Credits

Elias Manolakos
1 project • 0 followers

Comments