void setup() {
// put your setup code here, to run once:
pinMode(A0, INPUT);
pinMode(2, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(115200);
Serial.println("Hello !");
}
int setTemperature = 18;
int hysteresis = 1;
int nextLoop_ms = 0;
int period_ms = 100;
void loop() {
if (millis() > nextLoop_ms) {
nextLoop_ms += period_ms;
// Read temperature: convert the 0-1023 sensor reading to 20-50°C temperature range.
digitalWrite(13, HIGH);
float temperature = map((float)analogRead(A0), 0., 1023, -20, 50);
float command = 0.0;
if (temperature < setTemperature) {
// It's cold: turn on the heater
digitalWrite(2, HIGH);
command = 1.0;
} else {
// It's warm: turn off the heater
digitalWrite(2, LOW);
}
Serial.print(temperature);
Serial.print(", ");
Serial.print(command);
Serial.println();
digitalWrite(13, LOW);
}
}