// This #include statement was automatically added by the Spark IDE.
#include "OneWire.h"
// This #include statement was automatically added by the Spark IDE.
#include "spark-dallas-temperature.h"
// -----------------
// Read temperature
// -----------------
// Data wire is plugged into port D0 of Particle
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire( D0 );
int switchPin = D3;
int LedPin = D1;
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature dallas(&oneWire);
// Create a variable that will store the temperature value
double temperature = 0.0;
#include <math.h>
void setup()
{
pinMode( switchPin , INPUT_PULLUP); // sets switch as input
pinMode( LedPin , OUTPUT );
// Register a Particle Core variable here
Particle.variable("temperature", &temperature, DOUBLE);
// setup the library
dallas.begin();
Serial.begin(9600);
}
void loop()
{
int buttonState = digitalRead( switchPin );
if( buttonState == LOW )
{
// turn the switch On
digitalWrite( LedPin, HIGH);
// Request temperature conversion (traditional)
dallas.requestTemperatures();
sin( 23423 );
// get the temperature in Celcius
float tempC = dallas.getTempCByIndex(0);
// convert to double
temperature = (double)tempC;
if( temperature < 8 )
{
// send text message for temperatures less than 8 celcius
digitalWrite( LedPin, LOW);
String body = "Change the ice!";
Particle.publish("twilio", body, PRIVATE);
}
else{
// Publich in particle the temperature
Particle.publish("temperature",String(temperature));
digitalWrite( LedPin, LOW);
}
delay(7000);
} else {
// otherwise
// turn the switch Off
digitalWrite( LedPin, LOW);
}
}
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. .