/**
Projeto Janela Automática
Quando a temperatura chega abaixo de 19 Graus a janela fecha,
se estiver acima ou igual a 19 Graus ela abre.
Zion team
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int val; // variable to read the value from the analog pin
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
void setup() {
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
delay(1000);
if (celsius < 19) {
myservo.write(180); // tell servo to go to position in variable 'pos'
delay(15);
}
if (celsius >= 19) {
myservo.write(0); // tell servo to go to position in variable 'pos'
delay(15);
}
}