ncassadaJohn RavaioliGautam Kumar
Published © GPL3+

IOT Team 27 Home Climate Analyzer

The climate analyzer will read outdoor, bathroom, and indoor (reference) humidity.

IntermediateShowcase (no instructions)20 hours105
IOT Team 27 Home Climate Analyzer

Things used in this project

Hardware components

Argon
Particle Argon
Particle Argon
×3
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Multi-Turn Precision Potentiometer- 10k ohms (25 Turn)
Multi-Turn Precision Potentiometer- 10k ohms (25 Turn)
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×3

Software apps and online services

ThingSpeak API
ThingSpeak API
MATLAB
MATLAB

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Schematics

Main Temperature Sensor Diagram

This is the main temperature sensor....

Temperature Sensor (outside and inside)

This is the temperature sensor schematic for the Argon's placed in the bathroom and outdoors (there will be two setups)

Code

Outside Temperature Sensor

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>

#define DHTPIN D2
#define DHTTYPE DHT11

TCPClient client;
unsigned long myChannelNumber = 913676;
const char * myWriteAPIKey = "RU3LJ5FSFWP2XCTS";

int GK_tempF;
int GK_humidity;
int pinDHT11 = 6;
DHT dht(DHTPIN, DHTTYPE);

int lasttempF = 0; 
int tempFdelta;
int lasthumidity = 0;
int humiditydelta;

unsigned long lastSensorRead = 0;
unsigned long sensorInterval = 1000;

char *message = "GKs_Argon";
char msg[128];

void setup()
{ 
  ThingSpeak.begin(client);
  Particle.variable("tempF", GK_tempF);
  Particle.variable("humidity", GK_humidity);

  dht.begin(); 

  Serial.begin(9600);
}


void loop()
{



  if (millis() - lastSensorRead > sensorInterval)
  {
    GK_humidity = dht.getHumidity();
    GK_tempF = dht.getTempFarenheit();
    tempFdelta = GK_tempF - lasttempF;
    tempFdelta = abs(tempFdelta);
    humiditydelta = GK_humidity - lasthumidity;
    humiditydelta = abs(humiditydelta);

    if (tempFdelta < 2 && humiditydelta < 2) //if temp difference is more than 1 degree F in 5 seconds it's probably a spike in the data
    {
        snprintf(msg, sizeof(msg), "TempF\:\%d\,\Humidity\:\%d", GK_tempF, GK_humidity);
        Serial.println(msg);//for debugging
        Particle.publish("GKs_Argon", msg);
        ThingSpeak.setField(3,GK_tempF);
        ThingSpeak.setField(4,GK_humidity);
        ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
        delay(1000);
    }

    //Update the sensor read millis timer.
    lastSensorRead = millis();

    lasttempF = GK_tempF;
    lasthumidity = GK_humidity;
  }
}

Indoor Temperature/Humidity Sensor

C/C++
This is the Temperature/Humidity Sensor that is placed in the bathroom.
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>

#define DHTPIN D2
#define DHTTYPE DHT11

int Ravs_tempF;
int Ravs_humidity;
int pinDHT11 = 6;
DHT dht(DHTPIN, DHTTYPE);

int lasttempF = 0; 
int tempFdelta;
int lasthumidity = 0;
int humiditydelta;

unsigned long lastSensorRead = 0;
unsigned long sensorInterval = 5000;

char *message = "Ravs_Argon";
char msg[128];

void setup()
{
  Particle.variable("tempF", Ravs_tempF);
  Particle.variable("humidity", Ravs_humidity);

  dht.begin(); 

  Serial.begin(9600);
}


void loop()
{

  if (millis() - lastSensorRead > sensorInterval)
  {
    Ravs_humidity = dht.getHumidity();
    Ravs_tempF = dht.getTempFarenheit();
    tempFdelta = Ravs_tempF - lasttempF;
    tempFdelta = abs(tempFdelta);
    humiditydelta = Ravs_humidity - lasthumidity;
    humiditydelta = abs(humiditydelta);

    if (tempFdelta < 2 && humiditydelta < 2) //if temp difference is more than 1 degree F in 5 seconds it's probably a spike in the data
    {
      snprintf(msg, sizeof(msg), "Ravs_TempF\:\%d\,\ Ravs_Humidity\:\%d", Ravs_tempF, Ravs_humidity);
      Serial.println(msg);//for debugging

      Particle.publish("Ravs_Argon", msg);
      delay(1000);
    }

    //Update the sensor read millis timer.
    lastSensorRead = millis();

    lasttempF = Ravs_tempF;
    lasthumidity = Ravs_humidity;
  }
}

Reference Temperature Sensor Code

C/C++
This is the code for the main temperature sensor that will be used as a reference/base temperature.
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

// This #include statement was automatically added by the Particle IDE.
#include <JsonParserGeneratorRK.h>

// This #include statement was automatically added by the Particle IDE.
#include <LiquidCrystal.h>

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>

// This example assumes the sensor to be plugged into CONN2
#define DHTPIN D2     // what pin we're connected to

// Here we define the type of sensor used
#define DHTTYPE DHT11        // DHT 11

TCPClient client;
unsigned long myChannelNumber = 913676;
const char * myWriteAPIKey = "RU3LJ5FSFWP2XCTS";

unsigned long lastPubMillis = 0;
unsigned long pubInterval =1000;

int GK_tempF;
int GK_humidity;
int Ravs_tempF;
int Ravs_humidity;

int lasttempF = 0; 
int tempFdelta;
int lasthumidity = 0;
int humiditydelta;
unsigned long lastSensorRead = 0;
unsigned long sensorInterval = 1000;

//Global variables to store messages.
char *message = "Temp Humidity";
char msg[128];
char *Rmessage = "Temp Humidity";
char Rmsg[128];


void printJson(JsonParser &jp);

// Create a parser to handle 2K of data and 100 tokens
JsonParserStatic<2048, 100> jsonParser;

// this will be called whenever an event arrives we subscribed to
void GKHandler(const char *event, const char *data)
{
  Serial.println(data);       // print out the data as it comes in for debugging
  strncpy(msg, data, sizeof(msg)-1); // copy the incoming data to the global variable msg (with boundary limit)

  jsonParser.clear();         // make sure the parser buffer is fresh and empty
  jsonParser.addString(data); // copy the received data into the parser buffer for it to work with
  if (jsonParser.parse())   // let the parser do its job and split up the data internally
  {
    // first ask the parser for the value connected with the key 'GK_tempF'
    // if this is successful pop that value into the provided variable tempF
    // if not, the function will return false which - in turn - triggers the error output
    if (jsonParser.getOuterValueByKey("GK_tempF", GK_tempF) == false)
    {
      Serial.println("failed to get Temperature");
    }
    
    // do the same for 'humidity'
    // if(!someBoolean) is short hand for if(someBoolean == false)
    if (!jsonParser.getOuterValueByKey("GK_humidity", GK_humidity)) {
      Serial.println("failed to get Humidity");
    }
  }
}

void JRHandler(const char *event, const char *data)
{
  Serial.println(data);       // print out the data as it comes in for debugging
  strncpy(Rmsg, data, sizeof(Rmsg)-1); // copy the incoming data to the global variable msg (with boundary limit)

  jsonParser.clear();         // make sure the parser buffer is fresh and empty
  jsonParser.addString(data); // copy the received data into the parser buffer for it to work with
  if (jsonParser.parse())   // let the parser do its job and split up the data internally
  {
    // first ask the parser for the value connected with the key 'GK_tempF'
    // if this is successful pop that value into the provided variable tempF
    // if not, the function will return false which - in turn - triggers the error output
    if (jsonParser.getOuterValueByKey("Ravs_tempF", Ravs_tempF) == false)
    {
      Serial.println("failed to get Temperature");
    }
    
    // do the same for 'humidity'
    // if(!someBoolean) is short hand for if(someBoolean == false)
    if (!jsonParser.getOuterValueByKey("Ravs_humidity", Ravs_humidity)) {
      Serial.println("failed to get Humidity");
    }
  }
}


int Nichol_temp;
int Nichol_humidity;
int pinDHT11 = 6;

DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(7, 8, 6, 5, 4, 3);

void setup(){
    ThingSpeak.begin(client);
    dht.begin();
    Serial.begin(9600);
    lcd.begin(16,2);
    Particle.subscribe("GKs_Argon",GKHandler); //I am collecting data from GKs_Argon
    Particle.subscribe("Ravs_Argon",JRHandler);
}

void loop(){

//==================================================================
//DHT11 Takes Temperature and Humidity readings (Start)
//==================================================================

  if (millis() - lastSensorRead > sensorInterval)
  {
    Nichol_humidity = dht.getHumidity();
    Nichol_temp = dht.getTempFarenheit();
    tempFdelta = Nichol_temp - lasttempF;
    tempFdelta = abs(tempFdelta);
    humiditydelta = Nichol_humidity - lasthumidity;
    humiditydelta = abs(humiditydelta);

    if (tempFdelta < 2 && humiditydelta < 2) //if temp difference is more than 1 degree F in 5 seconds it's probably a spike in the data
    {
        Particle.publish("Nichol_temp", String(Nichol_temp) + " °F");
        Particle.publish("Nichol_humidity", String(Nichol_humidity) + "%");
        ThingSpeak.setField(1,Nichol_temp);
        ThingSpeak.setField(2,Nichol_humidity);
        ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
        delay(1000);
        lcd.clear();
        //Choosing the first line and row
        lcd.setCursor(0,0);
        //Typing Temp: to the first line starting from the first row
        lcd.print("Temp: ");
        //Typing the temperature readings after "Temp: "
        lcd.print((int)Nichol_temp);
        //Choosing the second line and first row
        lcd.print("F");
        lcd.setCursor(0,1);
        //Typing Humidity(%): to the second line starting from the first row
        lcd.print("Humidity(%): ");
        //Typing the humidity readings after "Humidity(%): "
        lcd.print((int)Nichol_humidity);
    }

    //Update the sensor read millis timer.
    lastSensorRead = millis();

    lasttempF = Nichol_temp;
    lasthumidity = Nichol_humidity;
  }

//==================================================================
//DHT11 Takes Temperature and Humidity readings (End)
//==================================================================
//  ThingSpeak.setField(1,Nichol_temp);
//  ThingSpeak.setField(2,Nichol_humidity);
//==================================================================
//Print data onto LCD Screen (Start)
//==================================================================
if (millis() - lastPubMillis > pubInterval)    
{    
    Serial.printlnf("RoomEnv: '%s'", msg);//for debugging
    Particle.publish("GK_Argon", msg);
    Particle.publish("Ravs_Argon", Rmsg);
    //Telling our lcd to refresh itself every 0.75 seconds
}
//==================================================================
//Print data onto LCD Screen (End)
//==================================================================
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 
}

Credits

ncassada

ncassada

1 project • 1 follower
John Ravaioli

John Ravaioli

1 project • 1 follower
Gautam Kumar

Gautam Kumar

1 project • 0 followers
I'm an international student at UNCC, studying Mechanical Engineering with a motorsports concentration.

Comments

Add projectSign up / Login