Joshua LewisZachary Ford
Published

Group 11 2 State Weather Comparison

During the Covid Pandemic many students were separated due to online learning. We will be comparing daily life of weather in 2 states

IntermediateFull instructions provided2 hours174
Group 11 2 State Weather Comparison

Things used in this project

Hardware components

Argon
Particle Argon
×2
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×2
Resistor 220 ohm
Resistor 220 ohm
×2
water level sensor
×2
LED (generic)
LED (generic)
×2
Breadboard (generic)
Breadboard (generic)
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Paper Schematic for the circuit

All Pins and wires are labeled and travel to their destination.

Code

Pittsburgh code

C/C++
This code publishes the Pittsburgh weather data and has an led that turns on if it is raining in Charlotte.
// 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>

// 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

DHT dht(DHTPIN, DHTTYPE);

bool humid = false;

TCPClient client;

unsigned long myChannelNumber = 1248317;
const char * myWriteAPIKey = "X2EO5EGJ2NDZHE9B";

int led1 = D3;
int resval = 0;  // Holds pin value
int respin = A3; // sensor pin used
int rp = 0; //rain sensor value
const char *fc;
const char *hc;

void setup() {
   
    ThingSpeak.begin(client);
   
 pinMode(D2, OUTPUT);
 Particle.subscribe("It's Raining", led, "Ford_IOT");
 pinMode(led1, OUTPUT);
 Serial.begin(9600);
 dht.begin();
 
}

void led(const char *event, const char *data) {
if (event){
    
    digitalWrite(led1, HIGH);
    delay (500);
    digitalWrite(led1, Low);
    delay (500);
    
    digitalWrite(led1, HIGH);
    delay (500);
    digitalWrite(led1, Low);
    delay (500);
    
    Particle.publish("Raining Charlotte", PRIVATE);
}
}

void loop() {
   
     resval = analogRead(respin);
   
    if (resval<=100){
        rp = 0;
        Particle.publish("Not Raining in Pittsburgh", String (rp), PRIVATE);
    }
      else if (resval>100 && resval<=2000){
        rp = 1;
        Particle.publish("It's Raining in Pittsburgh", String (rp), PRIVATE);
    }  
  
    delay(1000);
   
    // Wait a few seconds between measurements.
    delay(2000);

    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds
    float hp = dht.getHumidity();
    // Read temperature as Celsius
    float tp = dht.getTempCelcius();
    // Read temperature as Farenheit
    float fp = dht.getTempFarenheit();

    // Check if any reads failed and exit early (to try again).
    if (isnan(hp) || isnan(tp) || isnan(fp)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
    }
   
   Particle.publish("Temperature Pittsburgh", String (fp), PRIVATE);
   Particle.publish("Humidity Pittsburgh", String (hp), PRIVATE);

  ThingSpeak.setField(1,hp);
  ThingSpeak.setField(2,fp);
  ThingSpeak.setField(3,rp); //creates rain channel\

  Serial.print(dht.getHumidity());
  Serial.println("hp");
  Serial.print(dht.getTempFarenheit());
  Serial.println("tp");
  Serial.println("rp"); //outputs rain float value 
   
  //Serial.println("rc"); //outputs Charlotte rain
 
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);  

  delay(2000); // ThingSpeak will only accept updates every 2 mins.
}

Charlotte Weather Code

C/C++
Same purpose at the Pittsburgh code.
// 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>

// 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

DHT dht(DHTPIN, DHTTYPE);

bool humid = false;

TCPClient client;

unsigned long myChannelNumber = 1248317;
const char * myWriteAPIKey = "X2EO5EGJ2NDZHE9B";

int resval = 0;  // Holds pin value
int respin = A3; // sensor pin used
float rc = 0; //rain sensor value
int led1 = D3;

void setup() {
    
     ThingSpeak.begin(client);
   
 pinMode(D7, OUTPUT);
 Particle.subscribe("It's Raining in Pittsburgh", led, "JoshIOT");
 pinMode(led1, OUTPUT);
 Serial.begin(9600);
 dht.begin();
 
  Particle.subscribe("It's Raining in Pittsburgh", led, "JoshIOT");
 
 pinMode(led1, OUTPUT);
 
}
 
void led(const char *event, const char *data) {
if (event){
    
    digitalWrite(led1, HIGH);
    delay (500);
    digitalWrite(led1, Low);
    delay (500);
    
    digitalWrite(led1, HIGH);
    delay (500);
    digitalWrite(led1, Low);
    delay (500);
    
    Particle.publish("Raining Pittsburgh", PRIVATE);
}
}

void loop() {
   
     resval = analogRead(respin);
   
    if (resval<=100){
        rc = 0;
        Particle.publish("Not Raining", String (rc), PRIVATE);
    }
      else if (resval>100 && resval<=2000){
        rc = 1;
        Particle.publish("It's Raining", String (rc), PRIVATE);
    }  

    delay(1000);
   
    // Wait a few seconds between measurements.
    delay(2000);

    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds
    float hc = dht.getHumidity();
    // Read temperature as Celsius
    float tc = dht.getTempCelcius();
    // Read temperature as Farenheit
    float fc = dht.getTempFarenheit();

    // Check if any reads failed and exit early (to try again).
    if (isnan(hc) || isnan(tc) || isnan(fc)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
    }
   
    Particle.publish("Temperature_Char", String (fc), PRIVATE);
    Particle.publish("Humidity_Char", String (hc), PRIVATE);
    
  ThingSpeak.setField(4,hc);
  ThingSpeak.setField(5,fc);
  ThingSpeak.setField(6,rc);
 
  Serial.print(dht.getHumidity());
  Serial.println("hc");
  Serial.print(dht.getTempFarenheit());
  Serial.println("tc");
  Serial.println("rc"); //outputs rain float value
  
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);  

  delay(2000); // ThingSpeak will only accept updates every 2 mins.

}

Credits

Joshua Lewis
1 project • 1 follower
Zachary Ford
0 projects • 0 followers
Mechanical Engineer May '22

Comments