Hi all,
Below is my code to control a fan turning on using a thermister. The idea is, if it's >55degC, the fan stays ON. If the the temp is < 40deg C the fan turns off. When I use a potentiometer and simulate the voltage fairly quickly it works perfectly. If I rotate the potentiometer slowly on the way down to around 3.3V, sometimes the fan never turns off. There is some fluctuation with the fan because I can hear it. The Fan is ramped up/down using PWM. Any hlp would be appreciated! Thanks.
ATtiny85
-------u-------
RST - A0 - (D 5) --| 1 PB5 VCC 8 |-- +5V
| |
A3 - (D 3) --| 2 PB3 PB2 7 |-- (D 2) - A1 -->
| |
Thermister I/P A2 - (D 4) --| 3 PB4 PB1 6 |-- (D 1) - PWM --> Fan Mosfet
| |
Gnd ---| 4 GND PB0 5 |-- (D 0) - PWM -->
-----------------
V1.0
25.03.22
*/
int thermisterPin = A2;
int thermisterReading;
int fanPWMPin = 1;
int pwmLevelHigh = 255;
int pwmStep = 0;
boolean fanTriggered = false; //Require a first trigger to start controlling fan
void setup() {
pinMode (fanPWMPin, OUTPUT);
}
void loop() {
thermisterReading = analogRead(thermisterPin);
if (thermisterReading > 777) // 3.8V = ~55degC
{
if (pwmStep < 255)
{
pwmStep++;
}
else
{
;
}
analogWrite (fanPWMPin, pwmStep);
delay(7);
fanTriggered = true;
}
else if ((thermisterReading > 675) && (fanTriggered == true)) //3.3V = ~40degC
{
analogWrite (fanPWMPin, pwmLevelHigh);
}
else if ((thermisterReading <= 675) && (fanTriggered == true))
{
if (pwmStep > 0)
{
pwmStep--;
analogWrite (fanPWMPin, pwmStep);
delay(7);
}
else
{
fanTriggered = false;
}
}
}