Completed code:
/*This code was largely taken from the DIoT tutorial.
Original comments were removed so existing comments could be used to highlight
added work*/
//Define RGB and alarm pins
int red = D2;//red spot = too hot
int verde = D1;//green light = just right
int bleu = A0;//blue is bold = too cold
int alarm = D5;// bring the noise
#include "OneWire.h"
#include "spark-dallas-temperature.h"
OneWire oneWire(D0 );
DallasTemperature dallas(&oneWire);
double temperature = 0.0;
double temperatureF = 0.0;
void setup()
{
Particle.variable("temperature", &temperature, DOUBLE);
Particle.variable("temperatureF", &temperatureF, DOUBLE);
/*I added the following four lines to define the RGB pins and alarm as outputs*/
pinMode(red, OUTPUT);
pinMode(verde, OUTPUT);
pinMode(bleu, OUTPUT);
pinMode(alarm, OUTPUT);
dallas.begin();
}
void loop()
{
/*The following if statements are used to create ranges for each light*/
if (retemp() > 60) // too hot
{
digitalWrite(red, LOW);
digitalWrite(bleu, HIGH);
digitalWrite(verde, HIGH);
} else if (retemp() > 40) //between 60 and 40, the Goldilocks zone
{
digitalWrite(verde, LOW);
digitalWrite(bleu, HIGH);
digitalWrite(red, HIGH);
} else { //too cold
digitalWrite(bleu, LOW);
digitalWrite(verde, HIGH);
digitalWrite(red, HIGH);
}
delay(200); // changed delay time in hopes of overloading messaging system
Particle.publish("The Tea Temperature is", retemp()); //publishes temp Data
}
/*The klaxon function sounds a beep (not a real klaxon, I know,
but I like the word) when the tea reaches a drinkable temperature*/
void klaxon()
{
if (retemp() <= 61 && retemp() >= 59)
digitalWrite(alarm, HIGH);
delay(3000);
digitalWrite(alarm, LOW);
}
/*A lot of the original code got moved here so that it could return
a temperature value as an input for the RGB LED and speaker*/
double retemp() //Returns temperature
{
dallas.requestTemperatures();
float tempC = dallas.getTempCByIndex(0);
temperature = (double)tempC;
float tempF = DallasTemperature::toFahrenheit( tempC );
temperatureF = (double)tempF;
return tempC;
}
Circuit diagram (use Fritzing or similar)
Bill of parts:
1 Breadboard
1 Particle Photon
1 RGB LED
1 Piezo Speaker
1 Covered DS18B20 temperature sensor
1 470Ω resistor
3 1kΩ resistors
A whole mess of wires
Video of completed project
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. .