Back to Parent

//3 This #include statement was automatically added by the Particle IDE.
#include "OneWire.h"

#include "spark-dallas-temperature.h"

//#include <OneWire.h>

int ledPin = D1;
int speakerPin = D2;

// Data wire is plugged into port 0 on the Arduino
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire( D0 );

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature dallas(&oneWire);

// Create a variable that will store the temperature value
double temperature = 0.0;
double temperatureF = 0.0;

void setup(void) {
 // Register a Particle variable here
 Particle.variable("temperature", &temperature, DOUBLE);
 Particle.variable("temperatureF", &temperatureF, DOUBLE);

 // setup the library

pinMode(ledPin, OUTPUT);

pinMode(speakerPin, OUTPUT);


void loop(void) {

  // Request temperature conversion


  // get the temperature in Celcius
  float tempC = dallas.getTempCByIndex(0);
  // convert to double
  temperature = (double)tempC;

  // convert to Fahrenheit
  float tempF = DallasTemperature::toFahrenheit( tempC );
  // convert to double
  temperatureF = (double)tempF;


int temperatureHOT = 73;

if(temperatureF > temperatureHOT) {

    digitalWrite(ledPin, HIGH);

    digitalWrite(speakerPin, HIGH);
    digitalWrite(speakerPin, LOW);

  digitalWrite(ledPin, LOW);
  digitalWrite(speakerPin, LOW);

 delay(3000); //just here to slow down the output so it is easier to read
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!