const float BETA = 3950; // should match the Beta Coefficient of the thermistor
// Relay pin
const int motorRelay = 2;
void setup() {
// initializes serial communication at 9600 bits per second:
Serial.begin(9600);
//sets the relay pin to output
pinMode(motorRelay, OUTPUT);
// sets the relay to the starting state
digitalWrite(motorRelay, HIGH);
}
void loop() {
// reads the sensor
int analogSensorOne = analogRead(A0);
// calculates the temperature in C°
float motorOne = 1 / (log(1 / (1023. / analogSensorOne - 1)) / BETA + 1.0 / 298.15) - 273.15;
// prints out the value
Serial.print("Temperature: ");
Serial.print(motorOne);
Serial.println("°C");
// Monitors the temperature and switches the relay acordingly
if (motorOne > 60) {
digitalWrite(motorRelay, LOW);
}
}