Abby McConnellRyan KistemakerJonas Nielsen
Published

Weather Sensor and Clothing Suggestion Generator - MEGR 3171

Using three Particle Argons, this system senses the temperature and humidity and outputs a clothing combination for optimal comfort.

BeginnerFull instructions provided10 hours344
Weather Sensor and Clothing Suggestion Generator - MEGR 3171

Things used in this project

Hardware components

Argon
Particle Argon
×3
Breadboard (generic)
Breadboard (generic)
×1
Temperature Sensor
Temperature Sensor
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Rotary Potentiometer, 10 kohm
Rotary Potentiometer, 10 kohm
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Humidity Sensor Circuit Diagram

Temperature Sensor Circuit Diagram

LCD Display Circuit

Project Flow Chart

Code

Temperature Sensor Code

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

TCPClient client;

unsigned long myChannelNumber = 1352061;
const char * myWriteAPIKey = "RUZQZYJ8SDJ84MXY";

int B = A5;
int C = D7;
int previouschecktime = 0;
double temperature_celcius() {
    return (analogRead(B) *(3.3/4096) -.5)/ .01;
    // conversion from analog reading to millivolts, and manufacturer offset
} 
// Should be direct connection
#define Data_Upload_Frequency 10000


void setup() {
    ThingSpeak.begin(client);
    
Particle.variable("outputTemperatureCelcius133171",temperature_celcius);
Particle.subscribe("recievedconfirmation",clean);
Particle.subscribe("Howard_LCD",sweep);
pinMode(C, OUTPUT);
}


void loop() {
temperature_celcius();
int fahr;
    fahr = ((1.8*temperature_celcius())+32); //converts the temp in C to temp in F
if (previouschecktime + Data_Upload_Frequency < millis()){
    previouschecktime = millis();
    }
     Particle.publish("Gordon_TempC", String(temperature_celcius()));
    Particle.publish("Gordon_TempF", String(fahr));
    
     ThingSpeak.writeFields(1352061, myWriteAPIKey); 
      ThingSpeak.setField(3,fahr);
}


      
void clean(const char *event, const char *data){
    if (data){
    digitalWrite(C, HIGH);
    delay(2000);
    digitalWrite(C, LOW);
    delay(8000);
    }
}

void sweep(const char *event, const char *data){
    if (data){
    delay(5000);
    digitalWrite(C, HIGH);
    delay(2000);
    digitalWrite(C, LOW);
    }
}

void tempsubscribe(const char *event, String data){
    int dataval;
    dataval=String(data).toInt();
    if (dataval > 80){
    digitalWrite(B, HIGH);
    }
    else{
    digitalWrite(B, HIGH);
    delay(1000);
    digitalWrite(B, LOW);
    }
    if ((previouschecktime + Data_Upload_Frequency < millis()) && (dataval)) {
    int previouschecktime = millis();
    delay(4000);
    publishdata();
    }
}

 
void publishdata() {
    Particle.publish("recievedconfirmation", "TemperatureRecieved1", PRIVATE); 
    }

Humidity/Temperature Sensor Code

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

// This example assumes the sensor to be plugged into CONN2
#define DHTPIN D6     // 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 = 1352061;
const char * myWriteAPIKey = "RUZQZYJ8SDJ84MXY";

void setup() {
    
    ThingSpeak.begin(client);
    
 pinMode(D7, OUTPUT);
 Serial.begin(9600); 
 dht.begin();
 Particle.subscribe("Howard_LCD", l, ALL_DEVICES);

}

void loop() {
    // Wait a few seconds between measurements.
    delay(2500);

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

    // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t) || isnan(f)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
    }
    
    Particle.publish("Wilton_TempF", String (f));
    Particle.publish("Wilton_Humidity", String (h));

  ThingSpeak.setField(1,h);
  ThingSpeak.setField(2,f);
  
  Serial.print(dht.getHumidity());
  Serial.println("h");
  Serial.print(dht.getTempFarenheit());
  Serial.println("t");

  
  ThingSpeak.writeFields(1352061, myWriteAPIKey);  

  delay(5000); // ThingSpeak will only accept updates every 15 seconds. 

}

    void l(const char *event, const char *data) {
        
            digitalWrite(D7, HIGH);
            delay(2000);
            digitalWrite(D7, LOW);
            delay(1000);
       
    }

LCD Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <LiquidCrystal.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 D6     // what pin we're connected to

// Here we define the type of sensor used
#define DHTTYPE DHT11        // DHT 11 

//DHT dht(DHTPIN, DHTTYPE);
int tempf=0;
int humidity=0;
LiquidCrystal lcd(5, 4, 3, 2, 1, 0);



void setup() {

  lcd.clear();
  lcd.begin(16, 2);
  //lcd.setCursor(0,0);
  //lcd.print("Temp");
  //lcd.setCursor(0,1);
  //lcd.print("Humid");
  Particle.subscribe("Wilton_Humidity", h, ALL_DEVICES);
  Particle.subscribe("Gordon_TempF", f, ALL_DEVICES);
    // We open up a serial port to monitor the sensor values
    //Serial.begin(9600); 
   //Serial.println("DHT11 test!");

    //dht.begin();
}

void loop() {
    // Wait a few seconds between measurements.
    delay(2000);


    Particle.publish("Howard_LCD",PUBLIC);
}
    void f(const char *event, const char *data) {
    // Print the data over serial
    lcd.clear();
   String temp=data;
   tempf=temp.toInt();
    lcd.setCursor(0,0);
    lcd.print(data);
    lcd.setCursor(4,0);
    lcd.print("F     ");
    if (tempf > 72) {
  lcd.setCursor(8,1);
  lcd.print("Shorts");
   }else {
  lcd.setCursor(8,1);
  lcd.print("Pants");
    }
}
    void h(const char *event, const char *data) {
    
    lcd.clear();
    lcd.setCursor(7,0);
    lcd.print(data);
    lcd.setCursor(10,0);
    lcd.print("%     ");
    String humid=data;
    humidity=humid.toInt();
    if (humidity > 64) {
  lcd.setCursor(0,1);
  lcd.print("T-Shirt");
   }else {
  lcd.setCursor(0,1);
  lcd.print("LSleeve");
}
    }

Credits

Abby McConnell

Abby McConnell

1 project • 3 followers
Ryan Kistemaker

Ryan Kistemaker

1 project • 3 followers
Jonas Nielsen

Jonas Nielsen

1 project • 4 followers

Comments