#include <Servo.h>
//https://wokwi.com/projects/339227323398095442
#include <TM1637.h>
const float BETA = 3950;
const int CLK = 9;
const int DIO = 8;
TM1637 tm(CLK, DIO);
Servo myservo;
int pos = 0;
void setup() {
tm.init();
tm.set(BRIGHT_TYPICAL);
// put your setup code here, to run once:
Serial.begin(9600);
myservo.attach(3); //connected at PWM 3
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
}
unsigned int counter = 0;
void loop() {
// put your main code here, to run repeatedly:
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
counter = (int)celsius;
//display temp
tm.display(0, (counter / 100) % 10);
tm.display(1, (counter / 10) % 10);
tm.display(2, (counter / 1) % 10);
tm.display(3, counter % 10);
if(celsius > 23.9){
// Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
digitalWrite(A1, HIGH);
digitalWrite(A2, LOW);
//open the window
pos = 180;
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(250);
}
else{
digitalWrite(A2, HIGH);
digitalWrite(A1, LOW);
//Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
//close window
pos = 90;
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(250);
}
delay(1000);
}