/*
* Project Thermal-Compare
* Description:
* Author: Nicholas Stone
* Date: 1/29/2017
* Version: 2
*/
#include "OneWire.h"
#include "spark-dallas-temperature.h"
//instances
OneWire oneWire(D0);
DallasTemperature dallas(&oneWire);
//vars
// double tempC = 0.0;
int tempF = 0;
int MasterTempF = 70;
int MaxTempDiff = 1;
//Sample Rate est (Loop Rate)
int sampleRate = 5000;
//Burst Rate of published messages (15 minutes)
int burstRate = 900000;
int timeSincePublish= 900000;
//motion read
int motionPin = D1;
int motionValue = 0;
int motionState = 0;
int motionRate = 900000;
int timeSinceMotion = 0;
//LED
int ledPin = D2;
void setup() {
//Register
// Particle.variable("tempC", &tempC, DOUBLE);
Particle.variable("tempF", &tempF, INT);
//Particle.variable("motion",&motionValue,INT);
//Particle.variable("tSincePublish",&timeSincePublish,INT);
Particle.variable("tSinceMotion",&timeSinceMotion,INT);
Particle.variable("motionStatus",&motionState,INT);
pinMode(motionPin, INPUT);
pinMode(ledPin, OUTPUT);
//start library
dallas.begin();
}
void loop() {
//check motion
motionValue = digitalRead(motionPin);
if(motionValue == 1) {
motionState = 1;
timeSinceMotion = 0;
digitalWrite(ledPin, HIGH);
} else{if(timeSinceMotion>=motionRate) {
motionState = 0;
digitalWrite(ledPin, LOW);
} else {
timeSinceMotion = timeSinceMotion + sampleRate;
digitalWrite(ledPin, LOW);
}
}
//request conversion
dallas.requestTemperatures();
//get temperature in Celsius and convert to Fahrenheit
tempF = (int)DallasTemperature::toFahrenheit(dallas.getTempCByIndex(0));
//check if difference exceeds configuration and enough time has passed since the last publication
if(abs(tempF - MasterTempF)>MaxTempDiff && timeSincePublish>=burstRate){
Particle.publish("TempDiffExceeded", "true");
// reset burst rate time counter
timeSincePublish = 0;
}
timeSincePublish = timeSincePublish + sampleRate;
delay(sampleRate);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .