Created
February 26, 2019 20:00
-
-
Save undocumented-code/dc4f912a97ff098e055c8a84cb629da6 to your computer and use it in GitHub Desktop.
Simple Fan Controller for the TC74 and some 6 pin server fans. https://blog.tuckerosman.com/2019/02/building-temperature-based-fan.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//See https://blog.tuckerosman.com/2019/02/building-temperature-based-fan.html for more information. | |
//#include <Math.h> | |
//#define CURVE_FACTOR 1.03 | |
#include <TC74_I2C.h> | |
#define FANSPEED_PIN 4 | |
TC74_I2C TC74(TC74_A0); | |
int temperature; | |
void setup() { | |
pinMode(FANSPEED_PIN, OUTPUT); | |
digitalWrite(FANSPEED_PIN, HIGH); | |
TC74.Init(); | |
delay(1000); | |
} | |
void loop() { | |
temperature = TC74.ReadTemp(); | |
if (temperature != 128 && temperature != 0) { //Is this a valid temperature? | |
//The exponential curve I wanted to use. Takes more cycles since the ATTiny85 has no float hardware | |
//analogWrite(FANSPEED_PIN, ceil(255 * (pow(CURVE_FACTOR,temperature)/42.69))); | |
analogWrite(FANSPEED_PIN, (255/127)*temperature); | |
} else { | |
//If we did not get a valid temperature, then blow the fans at full speed just to be safe. | |
digitalWrite(FANSPEED_PIN, HIGH); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment