Fall2020.MEGR3171.Group13
Published

Atmospheric Condition Data Acquisition

With this climate monitor the temperature, pressure, and humidity can be observed for your area!

BeginnerShowcase (no instructions)241
Atmospheric Condition Data Acquisition

Things used in this project

Hardware components

Argon
Particle Argon
×3
Breadboard (generic)
Breadboard (generic)
×3
Elegoo Dupont Cables
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×3
BMP180
×3

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Ubidots
Ubidots

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic for Atmospheric Condition Data Acquisition

This is the schematic for the Atmospheric Data Acquisition Device

Code

Atmospheric Condition Data Acquisition

C/C++
This is an example of the code used for one of the three particle devices.
#include <BMP085.h>
#include <PietteTech_DHT.h>
#include <Ubidots.h>

#define DHTTYPE  DHT11       // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN   A4          // Analog pin for communications

PietteTech_DHT DHT(DHTPIN, DHTTYPE);
BMP085 myBarometer;

float temperature;
float pressure;
float atm;
float altitude;
float h;
float t;
float f;

    // Establish a webhook to Ubidots
const char *WEBHOOK_NAME = "Badger_Hobbit_2.0";
Ubidots ubidots("webhook", UBI_PARTICLE);

void myHandler(const char *event, const char *data)
{
  Serial.println();
  Serial.println(event);
  Serial.println(Time.timeStr());
}

void setup()
{
  Serial.begin(9600);
  DHT.begin();
  myBarometer.init();
  Particle.subscribe("Handshake_Diligent_Octopus", myHandler);
  Particle.subscribe("Handshake_moneypit", myHandler);
}

void loop()
{
        // BMP180 READINGS -----------------------------------------------------------
  Serial.print("\n");
  Serial.println("-----Retrieving information from BMP180 sensor:");
  
  temperature = myBarometer.bmp085GetTemperature(myBarometer.bmp085ReadUT());   // Get the temperature, bmp085ReadUT MUST be called first
  pressure = myBarometer.bmp085GetPressure(myBarometer.bmp085ReadUP());         // Get the temperature
  altitude = myBarometer.calcAltitude(101900);                                  // Get the altitude
  atm = pressure / 101325;
  
  Serial.print("Temperature: ");
  Serial.print(temperature, 2);         // Display 2 decimal places
  Serial.println(" Celsius");

  Serial.print("Pressure : ");
  Serial.print(pressure, 0);            // Whole number only.
  Serial.println(" Pa");
  
  Serial.print("Pressure : ");
  Serial.print(atm, 4);               // Display 4 decimal places
  Serial.println(" atm");

  Serial.print("Altitude: ");
  Serial.print(altitude, 2);            // Display 2 decimal places
  Serial.println(" m");

  Serial.println();
 
        // DHT11 READINGS -----------------------------------------------------------

  Serial.print("\n");
  Serial.println("-----Retrieving information from DHT11 sensor:");
  
  int result = DHT.acquireAndWait(5000);        // Wait up to 5 seconds. Input a value for max wait time or leave blank for indefinite.

  switch (result) {
  case DHTLIB_OK:
    Serial.println("OK");
    break;
  case DHTLIB_ERROR_CHECKSUM:
    Serial.println("Error\n\r\tChecksum error");
    break;
  case DHTLIB_ERROR_ISR_TIMEOUT:
    Serial.println("Error\n\r\tISR time out error");
    break;
  case DHTLIB_ERROR_RESPONSE_TIMEOUT:
    Serial.println("Error\n\r\tResponse time out error");
    break;
  case DHTLIB_ERROR_DATA_TIMEOUT:
    Serial.println("Error\n\r\tData time out error");
    break;
  case DHTLIB_ERROR_ACQUIRING:
    Serial.println("Error\n\r\tAcquiring");
    break;
  case DHTLIB_ERROR_DELTA:
    Serial.println("Error\n\r\tDelta time to small");
    break;
  case DHTLIB_ERROR_NOTSTARTED:
    Serial.println("Error\n\r\tNot started");
    break;
  default:
    Serial.println("Unknown error");
    break;
  }
  
  h=DHT.getHumidity();
  t=DHT.getCelsius();
  f=DHT.getFahrenheit();
  
  
  Serial.print("Humidity (%): ");
  Serial.println(h, 2);

  Serial.print("Temperature (oC): ");
  Serial.println(t, 2);

  Serial.print("Temperature (oF): ");
  Serial.println(f, 2);
  
  Serial.println();
  Serial.println();
  Serial.println();

        // Publish both sensor's readings
  //Particle.publish("Badger_Hobbit_DHT11_Readings", String::format("{\Hum(\%)\": %4.2f, \"Temp(oC)\": %4.2f, \"Temp(oF)\": %4.2f}", h,t,f));
  //Particle.publish("Badger_Hobbit_BMP180_Readings", String::format("{\"Temp(\%)\": %4.2f, \"Pres(\%)\": %4.2f, \"Alt(\%)\": %4.2f}", temperature, pressure, altitude));
  
        // Publish Handshake
  Particle.publish("Handshake_Badger_Hobbit", String(Time.timeStr()));

        // Send varibles to Ubidots via a webhook
  ubidots.add("Humidity", h);
  ubidots.add("TempC", t);
  ubidots.add("Pressure", pressure);

        // SEND GPS COORDINATES TO UBIDOTS -----------------------------------------------------------

  float value = analogRead(A0);
  
        // Harcoded Coordinates
  float latitude = 35.15825471519051;
  float longitude = -80.7692742929311;

        // Reserves 10 bytes of memory to store context keys values, add as much as needed
  char *str_lat = (char *)malloc(sizeof(char) * 10);
  char *str_lng = (char *)malloc(sizeof(char) * 10);

        // Saves the coordinates as char
  sprintf(str_lat, "%f", latitude);
  sprintf(str_lng, "%f", longitude);

        // Reserves memory to store context array
  char *context = (char *)malloc(sizeof(char) * 50);

        // Adds context key-value pairs
  ubidots.addContext("lat", str_lat);
  ubidots.addContext("lng", str_lng);

        // Builds the context with the coordinates to send to Ubidots
  ubidots.getContext(context);

        // Sends the position
  ubidots.add("position", value, context); // Change for your variable name

  bool bufferSent = false;
  bufferSent = ubidots.send(WEBHOOK_NAME, PUBLIC); // Will use particle webhooks to send data

  if (bufferSent) {
        Serial.println("Values sent by the device");
        Serial.println(Time.timeStr());
    }

        //  Free memory
 free(str_lat);
 free(str_lng);
 free(context);

 delay(260000);      // Wait 260 seconds
}

Credits

Fall2020.MEGR3171.Group13

Fall2020.MEGR3171.Group13

1 project • 0 followers

Comments

Add projectSign up / Login