Saddat AhmadDaniel Law
Created November 11, 2020

Lane Tech HS - Quick Weather

I swipe my card through the photo-interrupter, which then texts me the weather.

62
Lane Tech HS - Quick Weather

Things used in this project

Hardware components

Argon
Particle Argon
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LED (generic)
LED (generic)
×1
Arduino photo interrupter
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Code

Test Weather

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

StaticJsonDocument<900> doc;

int ledPin = D5; // choose the pin for the LED
int inputPin = A5; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0;
double main_temp;
int last_time = 0;
int cur_time = 0;

void setup() {
    Particle.variable("main_temp", main_temp);
    pinMode(ledPin, OUTPUT); // declare LED as output
    pinMode(inputPin, INPUT); // declare sensor as input
    Particle.subscribe("hook-response/openWeather", myHandler, MY_DEVICES);
    last_time = millis();
    Serial.begin(9600);
}

void loop() {
    val = digitalRead(inputPin);
    if (cur_time - last_time >= 60000) {
        Serial.println("It has been 1 minute");
        
    }
    if (val == HIGH) { // check if the input is HIGH
        cur_time = millis();
        if ((pirState == LOW) && (cur_time - last_time > 60000)) {
            //Serial.println("on");
            digitalWrite(ledPin, HIGH); // turn LED ON
            Serial.println(cur_time - last_time);
            last_time = cur_time;
            cur_time = 0;
            pirState = HIGH;
            Particle.publish("openWeather");
        }
    } else {
        digitalWrite(ledPin, LOW); // turn LED OFF
        if (pirState == HIGH){
            //Serial.println("off");
            pirState = LOW;
        }
    }
}

void myHandler(const char *event, const char *data) {    
    const char* json = data;

    deserializeJson(doc, json);
    
    main_temp = doc["main"]["temp"];
    
    Serial.println(main_temp);
}

Credits

Saddat Ahmad
3 projects • 2 followers
Daniel Law
47 projects • 10 followers
Teacher. Maker. Citizen of the planet.

Comments