Back to Parent

// 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"

int REDPin = A0; // RED pin of the LED to PWM pin **A0**

int GREENPin = D1; // GREEN pin of the LED to PWM pin **D0**

//int BLUEPin = D1; // BLUE pin of the LED to PWM pin **D1**

int brightness = 255; // Full brightness for an ANODE RGB LED

int buzzPin = D3;

// -----------------

// Read temperature

// -----------------

// 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;

#include <math.h>

void setup()

{

pinMode(REDPin, OUTPUT); // sets AO pin as output

pinMode(GREENPin, OUTPUT); // sets D0 pin as output

// pinMode(BLUEPin, OUTPUT); // sets D1 pin as output

pinMode(buzzPin, OUTPUT);

// Register a Particle Core variable here

Particle.variable("temperature", &temperature, DOUBLE);

Particle.variable("temperatureF", &temperatureF, DOUBLE);

// setup the library

dallas.begin();

Serial.begin(9600);

}

void loop()

{

// Request temperature conversion (traditional)

dallas.requestTemperatures();

sin( 23423 );

// 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;

// Print out

Serial.print( "Temp in C = ");

Serial.print( tempC );

Serial.print( "\t\t F = ");

Serial.println( tempF );

if(temperature>50){

//checking if temperature is greater than 50C then,

digitalWrite(REDPin, LOW);//turn on red led

digitalWrite(GREENPin, HIGH);//turn off green led

digitalWrite(buzzPin,HIGH);//turn on sound

delay(1000);

digitalWrite(buzzPin,LOW);//turn off sound

delay(1000);

Particle.publish("Its_cooked","Its_time_to_eat");

}else{//if temperature is less than or equal to 50C then

digitalWrite(GREENPin,LOW);//turn on green led

digitalWrite(REDPin,HIGH);//turn off red led

digitalWrite(buzzPin,LOW);//turn off sound

}

delay(2000);

}
Click to Expand

Content Rating

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

0