Go Down

Topic: PC Thermostat (Read 82 times) previous topic - next topic


Hello Community! I have just finished a simple piece of equipment to control the case fan inside my PC tower. My setup allows it to be mounted inside the case, and it only needs a serial connection when you set its threshold, so you can see what the actual amount is. You use a pot to adjust the threshold from 30 to 80 degrees Celsius, the average range in my PC with a little room to spare. It has two indicator LEDs and it uses a 5v relay. You can always modify it!

My code is and will always be in the public domain, so enjoy it as you wish! I only ask what you did with it so I can get some ideas. Thanks!

Code: [Select]

//You need: a TMP36 sensor, 2 LEDs of choice, resistors for those LEDs, a 10k Pot, a 5v relay, and a PC fan to control

const int relayPin = 12; //a pin to control the relay
const int controlPin = A1; //receive the thermostat setting
const int thermoSensor = A0; //the temp sensor
const int ledOn = 5; //some status LEDs, this one is Green
const int ledOff = 4; //this one is Red

double threshhold; //store the pot value as a desired 'set' temp.

double voltageReading; //variables to calculate and store the temperature in Celsius
double pcTemperature; //the ambient temperature inside the case

void setup() {
  // put your setup code here, to run once:
  pinMode(thermoSensor, INPUT); //the sensors
  pinMode(controlPin, INPUT);

  pinMode(relayPin, OUTPUT); //the output devices
  pinMode(ledOn, OUTPUT);
  pinMode(ledOff, OUTPUT);

void loop() {
  // put your main code here, to run repeatedly:
  threshhold = analogRead(controlPin); //doing it like this for simplicity
  threshhold = map(threshhold, 0, 1023, 10, 30); //30 Celsius to 80 Celsius, but for debugging, 10 to 30 degrees

  pcTemperature = pcReading(); //get the temp

  if (pcTemperature >= threshhold)
  if (pcTemperature < threshhold)

  displayStats(threshhold, pcTemperature); //show some information to help set the device


int pcReading() //get the temperature information from the PC
 int reading = analogRead(thermoSensor);  //read the voltage
 float voltage = reading * 5.0;           //multiply it by the power supplied to the sensor (5v)
 voltage /= 1024.0;                       //turn it into an easier value to calculate
 float temperatureC = (voltage - 0.5) * 100 ; //calculate temperature in Celsius
 return temperatureC;

void fanOn()
  digitalWrite(ledOn, HIGH); //update the signals
  digitalWrite(ledOff, LOW);

  digitalWrite(relayPin, HIGH); //activate the relay

void fanOff()
  digitalWrite(ledOn, LOW); //update the signals
  digitalWrite(ledOff, HIGH);

  digitalWrite(relayPin, HIGH); //deactivate the relay

void displayStats(double threshhold, double pcTemperature)
  Serial.print("SET ");
  Serial.print("CURRENT ");
-My name is Michael Pate, but you can call me Mike.

First rule: Thou Shalt Check Voltages!

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131