Noel Padgaonkar
Published

Portable Room Monitor

A simple low cost room monitor which measures temperature, humidity, carbon dioxide level and VOC. This data is accessible via the internet.

IntermediateWork in progress8 hours456
Portable Room Monitor

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
SparkFun Air Quality Breakout - CCS811
SparkFun Air Quality Breakout - CCS811
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Nextion NX4832T035 - 3.5" HMI TFT LCD Touch Display Module
Itead Nextion NX4832T035 - 3.5" HMI TFT LCD Touch Display Module
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Plastic Enclosure, Project Box
Plastic Enclosure, Project Box
×1

Software apps and online services

Arduino IDE
Arduino IDE
Itead Nextion HMI Interface Editor

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Connections

Code

Code for the ESP8266 NodeMCU

Arduino
Use the module NodeMCU 1.0 from your list of devices from Arduino IDE and upload the code
#include <Adafruit_CCS811.h>
#include <Nextion.h>
#include <DHT.h>
#include <WiFiManager.h>
#include <DNSServer.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <RTClib.h>
#include <Wire.h>
#include <SPI.h>
#include <SoftwareSerial.h>

/* Basic Initializations */

SoftwareSerial nex(D5,D6);

/* Nextion Display */
NexText t0 = NexText(0, 1, "t0");
NexText t1 = NexText(0, 2, "t1");
NexText t2 = NexText(0, 3, "t2");
NexText t3 = NexText(0, 4, "t3");
NexTouch *nex_listen_list[] = {
  NULL
};
/* CCS811 */
Adafruit_CCS811 ccs;
/* DHT22 */
#define DHTPIN D4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float t,h;
int co2,voc;
/* NodeMCU WiFi Credentials */
const char *host = "**YOUR HOSTING NAME (IP OR DOMAIN NAME)***";   //IP address of server
WiFiManager wifiManager;
/* Setup Function that runs only once in the program */

void setup()
{
  /* Setting baud rate as 9600 */
  Serial.begin(9600);
  /* Initialise Nextion */
  nexInit();
  nex.begin(9600);
  /* Initialise DHT22 */
  dht.begin();
  /* Initialise CCS811 */
  if (!ccs.begin()) {
    Serial.println("Failed to start sensor! Please check your wiring.");
    while (1);
  }
  /* Initialise WiFI */
  //wifiManager.resetSettings();
}

/* Loop Function that runs always on loop in the program */

void loop()
{
  if (ccs.available()) {
    h = (dht.readHumidity()+0.00);
    t = (dht.readTemperature()+0.00);
    co2 = ccs.geteCO2();
    voc = ccs.getTVOC();
    if (!ccs.readData()) {
      /* Display on Nextion */
      if(co2==0 && voc==0)
      {
        //This helps to avoid sending 0 values of CCS811 sensor while intialising
        Serial.println("I am here");
        return;
      }
      else
      {
      nex.write(0xff);
      nex.write(0xff);
      nex.write(0xff);
      nex.print("t0.txt=");
      nex.print("\"" + String(t) + "\"");
      nex.write(0xff);
      nex.write(0xff);
      nex.write(0xff);
      nex.print("t1.txt=");
      nex.print("\"" + String(h) + "\"");
      nex.write(0xff);
      nex.write(0xff);
      nex.write(0xff);
      nex.print("t2.txt=");
      nex.print("\"" + String(co2) + "\"");
      nex.write(0xff);
      nex.write(0xff);
      nex.write(0xff);
      nex.print("t3.txt=");
      nex.print("\"" + String(voc) + "\"");
      nex.write(0xff);
      nex.write(0xff);
      nex.write(0xff);
      Serial.println(String(t)+","+String(h)+","+String(co2)+","+String(voc));
      /* Sending Data over WiFi */
      WifiData();
      }
      delay(180000);
    }
  }
}
void WifiData()
{
  wifiManager.autoConnect("***ANY NAME YOU WOULD LIKE TO NAME YOUR DEVICE HOTSPOT***");
  // if you get here you have connected to the WiFi
  Serial.println("Connected.");
  Serial.print("Connecting to ");
  Serial.println(host);
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort))
  {
    Serial.println("Connection Failed");
    return;
  }
  String url1 = "/room.php?Temperature=" + String(t) + "&Humidity=" + String(h) + "&CO2=" + String(co2) + "&VOC=" + String(voc);
  Serial.print("Requesting URL: ");
  Serial.println(url1);
  client.print(String ("GET ") + url1 + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
  delay(500);
  while (client.available())
  {
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  Serial.println();
  Serial.println("Closing Connection");
}

Credits

Noel Padgaonkar

Noel Padgaonkar

1 project • 2 followers

Comments