// 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 0 on the Arduino
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(D0 );
DallasTemperature dallas(&oneWire);
int servoPin = A5;
Servo myServo;
int servoPos = 90;
double temperature = 0.0;
double temperatureF = 0.0;
void setup()
{
Particle.variable("temperature", &temperature, DOUBLE);
Particle.variable("temperatureF", &temperatureF, DOUBLE);
myServo.attach( A5 );
Particle.function("servo", servoControl);
dallas.begin();
Serial.begin(9600);
pinMode(D1, OUTPUT);
pinMode(D2,OUTPUT);
}
void loop()
{
dallas.requestTemperatures();
float tempC = dallas.getTempCByIndex(0);
temperature = (double)tempC;
float tempF = DallasTemperature::toFahrenheit( tempC );
temperatureF = (double)tempF;
Serial.print( "Temp in C = ");
Serial.print( tempC );
Serial.print( "\t\t F = ");
Serial.println( tempF );
delay(5000);
if(temperature<25)
{
digitalWrite(D2, HIGH);
digitalWrite(D1, LOW);
servoControl("10");
delay(1000);
}else if(temperature>25)
{
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
servoControl("170");
delay(1000);
}
else
{
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
}
}
int servoControl(String command)
{
int newPos = command.toInt();
servoPos = constrain( newPos, 0 , 180);
myServo.write( servoPos );
return 1;
}
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. .