Brian FinchAndrew Norman
Published

Weather Comparison Station with GPS, Temp, and Humidity

Project using GPS and temperature sensors to compare weather in different locations.

BeginnerFull instructions provided391
Weather Comparison Station with GPS, Temp, and Humidity

Things used in this project

Hardware components

Argon
Particle Argon
×2
GPS NEO-6M
×2
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Custom parts and enclosures

Flow Chart

Schematics

Circuit Diagram Download

Circuit Diagram

Code

GPS and Temp Sensor Code

C/C++
This code outputs data from the NEO-6M GPS module and DHT22 Temperature sensor to the particle cloud.
// This #include statement was automatically added by the Particle IDE.
#include <TinyGPS-gngga.h>

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

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

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

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

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

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


#include "PietteTech_DHT.h" 

#define DHTTYPE  DHT22       // Sensor type DHT11/21/22
#define DHTPIN   D3   
// Copyright © 2016-2017 Daniel Porrey. All Rights Reserved.
//
// This file is part of the Particle.GPS library.
// 
// Particle.GPS library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// Particle.GPS library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Particle.GPS library. If not, 
// see http://www.gnu.org/licenses/.
//
#include "Particle-GPS.h"

// ***
// *** Create a Gps instance. The RX an TX pins are connected to
// *** the TX and RX pins on the electron (Serial1).
// ***
Gps _gps = Gps(&Serial1);

// ***
// *** Create a timer that fires every 1 ms to capture
// *** incoming serial port data from the GPS.
// ***
Timer _timer = Timer(1, onSerialData);


PietteTech_DHT DHT(DHTPIN, DHTTYPE);
int n;

void setup()
{
    Serial.begin(9600);
  while (!Serial.available() && millis() < 30000) {
    Serial.println("Press any key to start.");
    Particle.process();
    delay(10000);
  }
  Serial.println("DHT Simple program using DHT.acquireAndWait");
  Serial.print("LIB version: ");
  Serial.println(DHTLIB_VERSION);
  Serial.println("---------------");
  DHT.begin();
  // ***
  // *** Initialize the USB Serial for debugging.
  // ***
  Serial.begin();
  Serial.println("Initializing...");

  // ***
  // *** Initialize the GPS.
  // ***
  _gps.begin(9600);

  // ***
  // *** Request that all data be sent.
  // ***
  _gps.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA);

  // ***
  // *** Start the timer.
  // ***
  _timer.start();
}

void onSerialData()
{
  _gps.onSerialData();
}

void loop()
{
  // ***
  // *** This will display the strings received from
  // *** the GPS unit. Some may be empty if the GPS
  // *** is not set to send all data.
  // ***
  Serial.print("Data[0] = "); Serial.println(_gps.data[0]);
  Serial.print("Data[1] = "); Serial.println(_gps.data[1]);
  Serial.print("Data[2] = "); Serial.println(_gps.data[2]);
  Serial.print("Data[3] = "); Serial.println(_gps.data[3]);
  Serial.print("Data[4] = "); Serial.println(_gps.data[4]);
  Serial.print("Data[5] = "); Serial.println(_gps.data[5]);
  Serial.print("Data[6] = "); Serial.println(_gps.data[6]);
  Particle.publish("Brian_GPS", String(_gps.data[0]), PUBLIC);
  Particle.publish("Brian_GPS", String(_gps.data[1]), PUBLIC);
  
  
  Serial.print("\n");
  Serial.print(n);
  Serial.print(": Retrieving information from sensor: ");
  Serial.print("Read sensor: ");

  int result = DHT.acquireAndWait(1000);

  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;
}
  delay(1000);
  
  
  Serial.print("Humidity (%): ");
  Serial.println(DHT.getHumidity(), 2);

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

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

  Serial.print("Temperature (K): ");
  Serial.println(DHT.getKelvin(), 2);
  
    int temp_c = (DHT.getCelsius()); // read DHT sensor
    int temp_f = (DHT.getFahrenheit()); // read DHT sensor
    int humid = (DHT.getHumidity()); // read DHT sensor
  
   // Send publish from particle...
    Particle.publish("T_C", String(temp_c),60,PUBLIC);
    Particle.publish("T_F", String(temp_f),60,PUBLIC);
    Particle.publish("H_%", String(humid),60,PUBLIC);

  n++;
  delay(10000);
}

GPS and Temp Sensor Code(2)

C/C++
This is a code from a second Argon which also reports GPS and Temperature sensor data to the cloud
// This #include statement was automatically added by the Particle IDE.
#include <TinyGPS-gngga.h>

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

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

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

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

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

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


#include "PietteTech_DHT.h" 

#define DHTTYPE  DHT22       // Sensor type DHT11/21/22
#define DHTPIN   D3   
// Copyright © 2016-2017 Daniel Porrey. All Rights Reserved.
//
// This file is part of the Particle.GPS library.
// 
// Particle.GPS library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// Particle.GPS library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Particle.GPS library. If not, 
// see http://www.gnu.org/licenses/.
//
#include "Particle-GPS.h"

// ***
// *** Create a Gps instance. The RX an TX pins are connected to
// *** the TX and RX pins on the electron (Serial1).
// ***
Gps _gps = Gps(&Serial1);

// ***
// *** Create a timer that fires every 10 ms to capture
// *** incoming serial port data from the GPS.
// ***
Timer _timer = Timer(10, onSerialData);


PietteTech_DHT DHT(DHTPIN, DHTTYPE);
int n;

int temp_f2;

void setup()
{
    Serial.begin(9600);
  while (!Serial.available() && millis() < 30000) {
    Serial.println("Press any key to start.");
    Particle.process();
    delay(10000);
  }
  Serial.println("DHT Simple program using DHT.acquireAndWait");
  Serial.print("LIB version: ");
  Serial.println(DHTLIB_VERSION);
  Serial.println("---------------");
  DHT.begin();
  // ***
  // *** Initialize the USB Serial for debugging.
  // ***
  Serial.begin();
  Serial.println("Initializing...");

  // ***
  // *** Initialize the GPS.
  // ***
  _gps.begin(9600);

  // ***
  // *** Request that all data be sent.
  // ***
  _gps.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA);

  // ***
  // *** Start the timer.
  // ***
  _timer.start();


  Particle.subscribe("T_F", tempfHandler, MY_DEVICES);
  Particle.variable("temp_f2", temp_f2);

}


void onSerialData()
{
  _gps.onSerialData();
}

void loop()
{
  // ***
  // *** This will display the strings received from
  // *** the GPS unit. Some may be empty if the GPS
  // *** is not set to send all data.
  // ***
  Serial.print("Data[0] = "); Serial.println(_gps.data[0]);
  Serial.print("Data[1] = "); Serial.println(_gps.data[1]);
  Serial.print("Data[2] = "); Serial.println(_gps.data[2]);
  Serial.print("Data[3] = "); Serial.println(_gps.data[3]);
  Serial.print("Data[4] = "); Serial.println(_gps.data[4]);
  Serial.print("Data[5] = "); Serial.println(_gps.data[5]);
  Serial.print("Data[6] = "); Serial.println(_gps.data[6]);
  
  Particle.publish("GPS_0", String(_gps.data[0]), PRIVATE);

  
  Serial.print("\n");
  Serial.print(n);
  Serial.print(": Retrieving information from sensor: ");
  Serial.print("Read sensor: ");

  int result = DHT.acquireAndWait(5000);

  Serial.print("Humidity (%): ");
  Serial.println(DHT.getHumidity(), 2);

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

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

  Serial.print("Temperature (K): ");
  Serial.println(DHT.getKelvin(), 2);
  
    int temp_c = (DHT.getCelsius()); // read DHT sensor
    int temp_f = (DHT.getFahrenheit()); // read DHT sensor
    int humid = (DHT.getHumidity()); // read DHT sensor
  
   // Send publish from particle...
    Particle.publish("T_C", String(temp_c),PRIVATE);
    Particle.publish("T_F", String(temp_f),PRIVATE);
    Particle.publish("H_%", String(humid),PRIVATE);

  n++;
  delay(10000);
}



void tempfHandler(const char *event, const char *data)
{
temp_f2 = atof(data);
}

Credits

Brian Finch

Brian Finch

1 project • 0 followers
Andrew Norman

Andrew Norman

0 projects • 0 followers

Comments

Add projectSign up / Login