Josh SchnepfGunter HayesCarson Andrijanoff
Published © GPL3+

IOT Mini Weather Station Project

Our project is a portable weather station consisting of a temperature sensor, humidity sensor and a photoresistor (measuring brightness).

IntermediateFull instructions provided2 hours561
IOT Mini Weather Station Project

Things used in this project

Hardware components

Argon
Particle Argon
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
Signal and Power pins may be flipped depending on your DHT11 and Photoresistor
×1
KY-018
Generic Photoresistor
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×16
LED (generic)
LED (generic)
×4

Software apps and online services

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

Story

Read more

Schematics

Full Schematic

Breadboard View

DH11 and KY-018 may have flipped S and Power pins depending on the manufacturer and batch. Our group had variations in these, please wire as labeled on the sensor module board, and if the DH11 heats up, or the KY-018 fails to register values, try flipping the Signal wire with the Power wire.

Code

Asheville Code

C/C++
This is the code for the Asheville based Argon, it measures local temperature, humidity, and daylight levels, posts data to the Particle console, and triggers and subscribes to events to trigger the on board LEDs. ThingSpeak Channel Number and API Write keys have been X-ed out of this code as to prevent others from writing to our channel, you'll need your own channel and API Write key to post data.
// 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 D2
#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); //stuff for sensor

//int  sensorPin  =  A0;     // select the input  pin for  the photoresistor
//int  sensorValue =  0;  // variable to  store  the value  coming  from  the sensor
int pr = A0;//variable for photoresistor value
int led1 = D3;//variable for D3 led1
int led2 = D4;//variable for D4 led2
int led3 = D5;//variable for D5 led3
int led4 = D6;//variable for D6 led4 data posted confirmation led

bool humid = true;

TCPClient client;

unsigned long myChannelNumber = XXXXXXX;//defines thingspeak channel number
const char * myWriteAPIKey = "XXXXXXXXXXXXXXXX";//provides and defines API Write key for the channel

void setup() {
 ThingSpeak.begin(client);//prep to comm with thingspeak
 pinMode(D2, OUTPUT);//defines pin D2 as an output
 Serial.begin(9600);//begins serial monitor
 dht.begin();//starts DHT11 sensor combo
 pinMode(A0, INPUT);//defines A0 as photoresistor input
 pinMode(D3, OUTPUT);//defines D3 as output for led1
 pinMode(D4, OUTPUT);//defines D4 as output for led2
 pinMode(D5, OUTPUT);//defines D5 as output for led3
 pinMode(D6, OUTPUT);//defines D6 as output for led4
 Particle.subscribe("DayWilm", handler3, "WILM");//track the event DayWilm, and define handler function as handler3 - Gunter's daylight
 Particle.subscribe("NightWilm", handler3N, "WILM");//track the event NightWilm and define handler function as handnight3 - Gunter's nighttime
 Particle.subscribe("DayClt", handler2, "CLT");
 Particle.subscribe("NightClt", handler2N, "CLT");

}

//below are the handler functions for the above subscribed events, first for Charlotte numbered as 2, and then Wilmington numbered as 3

void handler2(const char *event, const char *data) {
    digitalWrite(led2, LOW);
    if (event) {
        
        digitalWrite(led2, HIGH);
        delay(400);
        
    }
    else {
        
        digitalWrite(led2, LOW);
        delay(400);
        
    }
}

void handler2N(const char *event, const char *data) {
    if (event) {
        
        digitalWrite(led2, LOW);
        delay(400);
        
    }
}

//below is for Wilmington

void handler3(const char *event, const char *data) {
    digitalWrite(led3, LOW);
    if (event) {
        
        digitalWrite(led3, HIGH);
        delay(400);
        
    }
    else {
        
        digitalWrite(led3, LOW);
        delay(400);
        
    }
}

void handler3N(const char *event, const char *data) {
    if (event) {
        
        digitalWrite(led3, LOW);
        delay(400);
        
    }
}

void loop() {

    digitalWrite(led4, LOW);
    delay(400);
    float fa = dht.getTempFarenheit();// Read temperature in Farenheit
    float ha = dht.getHumidity();// Read Humidity
    float photores = analogRead(pr);//define photoresistor analog read
    ThingSpeak.setField(1,fa);//assigns thingspeak field 4 to temp farenheit
    Serial.print(dht.getTempFarenheit());//prints dht farenheit temp
    Serial.println("fa");
    ThingSpeak.setField(2,ha);//assigns thingspeak field 2 to humidity
    Serial.print(dht.getHumidity());//prints dht humidity
    Serial.println("ha");
    ThingSpeak.setField(3,photores);//assigns thingspeak field 3 to photoresistor value
    Serial.print(analogRead(photores));
    Serial.println("photores");
    digitalWrite(led4, HIGH);
    Particle.publish("TempAvl", String (fa), PRIVATE);
    Particle.publish("HumAvl", String (ha), PRIVATE);
    if (photores < 25) {
        digitalWrite(led1, LOW);
        Particle.publish("NightAvl", String (photores), PRIVATE);
        delay(400);
    }
    else {
        digitalWrite(led1, HIGH);
        Particle.publish("DayAvl", String (photores), PRIVATE);
        delay(1000);
    }
    delay(400);
  
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);  //writes fields assigned above to our channel using the channel number and API Write key
}

Charlotte Code

C/C++
This is the code for the Charlotte based Argon, it measures local temperature, humidity, and daylight levels, posts data to the Particle console, and triggers and subscribes to events to trigger the on board LEDs. ThingSpeak Channel Number and API Write keys have been X-ed out of this code as to prevent others from writing to our channel, you'll need your own channel and API Write key to post data.
// 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
DHT dht(DHTPIN, DHTTYPE);

int pr = A0;//variable for photoresistor value
int led1 = D3;//variable for D3 led1
int led2 = D4;//variable for D4 led2
int led3 = D5;//variable for D5 led3
int led4 = D6;//variable for D6 led4 data posted confirmation led

bool humid = true;

TCPClient client;

unsigned long myChannelNumber = 1359813;//defines thingspeak channel number
const char * myWriteAPIKey = "KABPIVBQFTNZPVY7";//provides and defines API Write key for the channel

void setup() {
    ThingSpeak.begin(client);
    Serial.begin(9600);
    dht.begin();
    pinMode(A0, INPUT);//defines photoresistor input pin A0
    pinMode(D3, OUTPUT);//defines D3 as output for led1
    pinMode(D4, OUTPUT);//defines D4 as output for led2
    pinMode(D5, OUTPUT);//defines D5 as output for led3
    pinMode(D6, OUTPUT);//defines D6 as output for led4
    Particle.subscribe("DayAvl", handler1, "AVL");
    Particle.subscribe("DayWilm", handler3, "WILM");
    Particle.subscribe("NightAvl", handler1N, "AVL");
    Particle.subscribe("NightWilm", handler3N, "WILM");
}

//handler functions to turn leds on and off for asheville daylight

void handler1(const char *event, const char *data) {
    digitalWrite(led1, LOW);
    if (event) {
        
        digitalWrite(led1, HIGH);
        delay(400);
        
    }
    else {
        
        digitalWrite(led1, LOW);
        delay(400);
        
    }
}

void handler1N(const char *event, const char *data) {
    if (event) {
        
        digitalWrite(led1, LOW);
        delay(400);
        
    }
}

//handler functions to turn leds on and off for wilmington daylight

void handler3(const char *event, const char *data) {
    digitalWrite(led3, LOW);
    if (event) {
        
        digitalWrite(led3, HIGH);
        delay(400);
        
    }
    else {
        
        digitalWrite(led3, LOW);
        delay(400);
        
    }
}

void handler3N(const char *event, const char *data) {
    if (event) {
        
        digitalWrite(led3, LOW);
        delay(400);
        
    }
}

void loop() {
    float ff = dht.getTempFarenheit();// Read temperature in F
    float hh = dht.getHumidity();// Read Humidity
    float photores = analogRead(pr);//define photoresistor analog read

    ThingSpeak.setField(4,ff);
    Serial.print(dht.getTempFarenheit());
    Serial.println("ff");
    ThingSpeak.setField(5,hh);
    Serial.print(dht.getHumidity());
    Serial.println("hh");

    Particle.publish("TempClt", String (ff), PRIVATE);
    Particle.publish("HumClt", String (hh), PRIVATE);

    if (photores < 25) {
        digitalWrite(led2, LOW);
        Particle.publish("NightClt", String (photores), PRIVATE);
        delay(400);
    }
    else {
        digitalWrite(led2, HIGH);
        Particle.publish("DayClt", String (photores), PRIVATE);
        delay(400);
    }
    delay(400);
    
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
}

Wilmington Code

C/C++
This is the code for the Wilmington based Argon, it measures local temperature, humidity, and daylight levels, posts data to the Particle console, and triggers and subscribes to events to trigger the on board LEDs. ThingSpeak Channel Number and API Write keys have been X-ed out of this code as to prevent others from writing to our channel, you'll need your own channel and API Write key to post data.
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>

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

#define DHTPIN D2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

int pr = A0;//variable for photoresistor value
int led1 = D3;//variable for D3 led1
int led2 = D4;//variable for D4 led2
int led3 = D5;//variable for D5 led3
int led4 = D6;//variable for D6 led4

bool humid = true;

TCPClient client;

unsigned long myChannelNumber = 1359813;//defines thingspeak channel number
const char * myWriteAPIKey = "KABPIVBQFTNZPVY7";//provides and defines API Write key for the channel

void setup() {
   ThingSpeak.begin(client);
    Serial.begin(9600);
    dht.begin();
    pinMode(A0, INPUT);//defines photoresistor input pin A0
    pinMode(D3, OUTPUT);//defines D3 as output for led1
    pinMode(D4, OUTPUT);//defines D4 as output for led2
    pinMode(D5, OUTPUT);//defines D5 as output for led3
    pinMode(D6, OUTPUT);//defines D6 as output for led4
    //the following registers/subscribes to a notification from a specific Particle.publish() event.
    //this allows devices to communicate in theory
    Particle.subscribe("DayAvl", handler1, "AVL");//track the event DayAvl, and define handler function as handler1
    Particle.subscribe("DayClt", handler2, "CLT");//track the event DayClt, and define handler function as handler2
    Particle.subscribe("NightAvl", handler1N, "AVL");
    Particle.subscribe("NightClt", handler2N, "CLT");
}

//handler functions to turn leds on and off for asheville daylight

void handler1(const char *event, const char *data) {
    digitalWrite(led1, LOW);
    if (event) {
        
        digitalWrite(led1, HIGH);
        delay(400);   
        
    }
    else {
        
        digitalWrite(led1, LOW);
        delay(400);
        
    }
}

void handler1N(const char *event, const char *data) {
    if (event) {
        
        digitalWrite(led1, LOW);
        delay(400);
        
    }
}

//handler functions to turn leds on and off for charlotte daylight

void handler2(const char *event, const char *data) {
    digitalWrite(led2, LOW);
    if (event) {
        
        digitalWrite(led2, HIGH);
        delay(400);
        
    }
    else {
        
        digitalWrite(led2, LOW);
        delay(400);
        
    }
}

void handler2N(const char *event, const char *data) {
    if (event) {
        
        digitalWrite(led2, LOW);
        delay(400);
        
    }
}

void loop() {
    digitalWrite(led4, LOW);
    delay(1000);
    float photores = analogRead(pr);
    float ft = dht.getTempFarenheit();
    float ht = dht.getHumidity();
  
    ThingSpeak.setField(6,ft);//assigns thingspeak field 6 to wilmington farenheit measurement
    Serial.print(dht.getTempFarenheit());
    Serial.println("ft");
    ThingSpeak.setField(7,ht);//assigns thingspeak to field 7 to wilmington farenheit measurement
    Serial.print(dht.getTempFarenheit());
    Serial.println("ht");

    Particle.publish("TempWilm", String(ft), PRIVATE);
    Particle.publish("HumWilm", String(ht), PRIVATE);
    digitalWrite(led4, HIGH);

    if (photores < 25) {
        digitalWrite(led3, LOW);
        Particle.publish("NightWilm", String (photores), PRIVATE);
        delay(400);
    }
    else {
        digitalWrite(led3, HIGH);
        Particle.publish("DayWilm", String (photores), PRIVATE);
        delay(400);
    }

    delay(4000);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
}

Credits

Josh Schnepf
1 project • 3 followers
Gunter Hayes
1 project • 3 followers
Carson Andrijanoff
0 projects • 3 followers

Comments