Code: Select all
// This sketch is a simple if-then system. If the analog input sensor exceeds the first setpoint, pin 4 goes high.
// If the sensor exceeds the second setpoint, pin 2 goes high.
int thermistorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(4, OUTPUT); // declare pin 4 as an output (coolant pump)
pinMode(2, OUTPUT); // declare pin 5 as an output (AC compressor)
Serial.begin(9600); //turn serial monitor on for double-checking.
}
void loop() {
sensorValue = analogRead(thermistorPin); // read the value from the sensor
Serial.print(sensorValue); // print the sensor value on the screen
Serial.println("");
delay(500); // gives the sensor time to stabilise
if (sensorValue > 625)
digitalWrite(4, HIGH); // if the reading exceeds 625, turn 4 on
else
digitalWrite(4, LOW); // otherwise leave it off
if (sensorValue > 640)
digitalWrite(2, HIGH); // if the temperature sensor exceeds 640, turn 2 on
else
digitalWrite(2, LOW); // otherwise leave it off
}