Thomas CobbCesar Valverde
Published © GPL3+

MEGR 3171 - Group 22 - Environment Comparison Circuit

This IoT project allows for the environmental conditions of two or more places to be compared at any time and chose which study friendly.

BeginnerFull instructions provided5 hours192
MEGR 3171 - Group 22 - Environment Comparison Circuit

Things used in this project

Hardware components

Argon
Particle Argon
×2
Humidity and Temperature Sensor
Adafruit Humidity and Temperature Sensor
×2
Jumper wires (generic)
Jumper wires (generic)
×8
Breadboard (generic)
Breadboard (generic)
×2

Software apps and online services

ThingSpeak API
ThingSpeak API

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

System Schematic

Above shows the pin connections for the Particle Argon and the BME 280 Sensor. This would be the same for every argon used in this project.

Code

Sensor 1 Data Acquisition

C/C++
This code is run through the second Argon. The code first measures the same four pieces of data (temperature, humidity, barametric pressure, and approximate altitude) as the other pieces of code. Once the data has been gathered from sensor 1 then the code compares the results from each sensor. Whichever sensor has the more preferred measurement results will then be sent the task of turning on the LED for that particle. This means that whichever particle has the more preferred environmental measurements will have their LED on.
//Cesar Valverde & Thomas Cobb
//MEGR3171 UNC CHARLOTTE
//Introduction to Instrumentation
// BME280 Sensor 1


#include <Adafruit_BME280.h> //Library for BME280 Sensor
/***************************************************************************
  This is a library for the BME280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BME280 Breakout
  ----> http://www.adafruit.com/products/2650

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface. The device's I2C address is either 0x76 or 0x77.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
  See the LICENSE file for details.
 ***************************************************************************/
 
 
#include <JsonParserGeneratorRK.h> //library that helps with the ThingsSpeak Integration


#include <Wire.h>
#include <SPI.h>
#define SEALEVELPRESSURE_HPA (1013.25)  //Constant needed to convert presssure
#include "math.h" //enables math operators 



Adafruit_BME280 bme; // I2C

unsigned long delayTime; //setting delay variable

void setup() {
    Serial.begin(9600);
    while(!Serial);    // used to get serial running
    Serial.println(F("BME280 Sensor")); 

    unsigned status;
    
    
    //Error check for BME280 Sensor
        status = bme.begin();  
        if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        while (1) delay(10);
    }
    
    Serial.println("BME280");
    
    delayTime = 1200000; //Delay of 20 min to read bme280 sensor
    
    Serial.println();
    

Particle.subscribe("TJ-temp",Compare); //particle subscribe to particle 2 event

    pinMode(D7, OUTPUT); //setting up on-board led as an ouput

}


void loop() { 
    printValues(); //Loop to print bme 280 sensor values
    delay(delayTime); //loop the delay between output values
}


void printValues() {  //Function that serial prints the bme sensors values 

    
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature()); //temperature reading
    Serial.println(" *C");

    Serial.print("Pressure = ");
    Serial.print(bme.readPressure() / 100.0F); //pressure reading
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); //altitude reading
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity()); //humidity reading
    Serial.println(" %");

    Serial.println(); //print value
  
    //create a payload for JSON Generator
  createEventPayload(bme.readTemperature(), bme.readPressure() / 100.0F, bme.readAltitude(SEALEVELPRESSURE_HPA), bme.readHumidity());
}



//Calling the JSON Generator
 void createEventPayload(int temp, int press, int altit, int humid) //setting up the JSON generator
 {
     JsonWriterStatic<256> jw;
      {
          JsonWriterAutoObject obj(&jw);
          jw.insertKeyValue ("temp", bme.readTemperature());
          jw.insertKeyValue ("press", bme.readPressure() / 100.0F);
          jw.insertKeyValue ("altit", bme.readAltitude(SEALEVELPRESSURE_HPA));
          jw.insertKeyValue ("humid", bme.readHumidity());
      }
     Particle.publish("cv-bme280",jw.getBuffer(), PRIVATE); //publishing JSON data
 }
 

//Running the comparing feature whenever sensor 2 data is published
void Compare(String event, String data){
    event == "TJ-temp";
    int dataval;         //setting up the integer
dataval = String(data).toInt(); //naming the data from the event as the integer
     
        //comparison of data
    if (dataval < bme.readTemperature() ){        //if the incoming data is less than the temperature read from the sensor
             
             //publish that location of particle 1 is better
             Particle.publish("BME280_Compare","Cesar's Place", PRIVATE);
             
             //turn on led
             digitalWrite(D7, HIGH);

    } 
    else {                                      // if incoming data is greater than the temperature read from the sensor
            //publish that the location of particle 2 is better
            Particle.publish("BME280_Compare","Thomas' Place", PRIVATE);
            
            //turn off led
            digitalWrite(D7, LOW);
        }
    }

  

Sensor 2 Data Acquisition

C/C++
This code is run through Agron 1 to gather the temperature, humidity, barametric pressure, and approximate altitude. Once those values have been obtained, they are sent to Argon 2 and compared to the values gathered by its code.
//Cesar Valverde & Thomas Cobb
//MEGR3171 UNC CHARLOTTE
//Introduction to Instrumentation
// BME280 Sensor 1


#include <Adafruit_BME280.h> //Library for BME280 Sensor
/***************************************************************************
  This is a library for the BME280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BME280 Breakout
  ----> http://www.adafruit.com/products/2650

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface. The device's I2C address is either 0x76 or 0x77.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
  See the LICENSE file for details.
 ***************************************************************************/
 
 
#include <JsonParserGeneratorRK.h> //library that helps with the ThingsSpeak Integration


#include <Wire.h>
#include <SPI.h>
#define SEALEVELPRESSURE_HPA (1013.25)  //Constant needed to convert presssure
#include "math.h" //enables math operators 



Adafruit_BME280 bme; // I2C

unsigned long delayTime; //setting delay variable

void setup() {
    Serial.begin(9600);
    while(!Serial);    // used to get serial running
    Serial.println(F("BME280 Sensor")); 

    unsigned status;
    
    
    //Error check for BME280 Sensor
        status = bme.begin();  
        if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        while (1) delay(10);
    }
    
    Serial.println("BME280");
    
    delayTime = 1200000; //Delay of 20 min to read bme280 sensor
    
    Serial.println();
    

Particle.subscribe("TJ-temp",Compare); //particle subscribe to particle 2 event

    pinMode(D7, OUTPUT); //setting up on-board led as an ouput

}


void loop() { 
    printValues(); //Loop to print bme 280 sensor values
    delay(delayTime); //loop the delay between output values
}


void printValues() {  //Function that serial prints the bme sensors values 

    
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature()); //temperature reading
    Serial.println(" *C");

    Serial.print("Pressure = ");
    Serial.print(bme.readPressure() / 100.0F); //pressure reading
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); //altitude reading
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity()); //humidity reading
    Serial.println(" %");

    Serial.println(); //print value
  
    //create a payload for JSON Generator
  createEventPayload(bme.readTemperature(), bme.readPressure() / 100.0F, bme.readAltitude(SEALEVELPRESSURE_HPA), bme.readHumidity());
}



//Calling the JSON Generator
 void createEventPayload(int temp, int press, int altit, int humid) //setting up the JSON generator
 {
     JsonWriterStatic<256> jw;
      {
          JsonWriterAutoObject obj(&jw);
          jw.insertKeyValue ("temp", bme.readTemperature());
          jw.insertKeyValue ("press", bme.readPressure() / 100.0F);
          jw.insertKeyValue ("altit", bme.readAltitude(SEALEVELPRESSURE_HPA));
          jw.insertKeyValue ("humid", bme.readHumidity());
      }
     Particle.publish("cv-bme280",jw.getBuffer(), PRIVATE); //publishing JSON data
 }
 

//Running the comparing feature whenever sensor 2 data is published
void Compare(String event, String data){
    event == "TJ-temp";
    int dataval;         //setting up the integer
dataval = String(data).toInt(); //naming the data from the event as the integer
     
        //comparison of data
    if (dataval < bme.readTemperature() ){        //if the incoming data is less than the temperature read from the sensor
             
             //publish that location of particle 1 is better
             Particle.publish("BME280_Compare","Cesar's Place", PRIVATE);
             
             //turn on led
             digitalWrite(D7, HIGH);

    } 
    else {                                      // if incoming data is greater than the temperature read from the sensor
            //publish that the location of particle 2 is better
            Particle.publish("BME280_Compare","Thomas' Place", PRIVATE);
            
            //turn off led
            digitalWrite(D7, LOW);
        }
    }

  

Credits

Thomas Cobb
2 projects • 2 followers
Contact
Cesar Valverde
0 projects • 1 follower
UNCC
Contact

Comments

Please log in or sign up to comment.