4 Channel PWM Arduino Fan Controller

GopherT

Joined Nov 23, 2012
8,009
I know this has been done, I've googled it, and found so many results - But I'm curious how others would do it.

I have a few 140mm Noctua PWM fans. I want to have an arduino control the fan speed based on temperature.

I found this (http://emc2arduino.wordpress.com/side-projects/automatic-4-channel-pwm-pc-automatic-fan-controller/), but wondered if you could use an arduino motor shield instead.
Yes, either I possible. The software will be different but both are possible.
 

Thread Starter

james211

Joined May 29, 2012
283
So the attached schematic seems like a good option for my fans, but I haven't a clue where to begin with code?

My goal is to have the arduino control the fan speed based on a temperature reading.

Any ideas on where to start with code?
 

Attachments

Thread Starter

james211

Joined May 29, 2012
283
Ok, I figured out some code that works almost 100% the way I want it to with one exception, it doesn't turn off when I want it to. Right now if the temp is above 80 it turns on high, below 80 turns to half speed. But below 77 I want it to turn off and thats what I can't figure out. Can you input a temp range..any ideas?

Here is the code:
Rich (BB code):
#include <OneWire.h>
#include <DallasTemperature.h>
#define fanPin 9

int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2

//Temperature chip i/o
OneWire ds(DS18S20_Pin);  // on digital pin 2

void setup() {
    Serial.begin(9600);
    pinMode(fanPin, OUTPUT);
    digitalWrite(fanPin, LOW);
}

void loop(void) {
  float temperature = getTemp();
  float tempF = (temperature * 9.0)/ 5.0 + 32.0;
  Serial.print(tempF);
  if (tempF > 80) {
                Serial.print("high");
        digitalWrite(fanPin, HIGH);
    } else if (tempF < 80){
                Serial.print("med");
        analogWrite(fanPin, 127);
        } else {
                Serial.print("off");
                digitalWrite(fanPin, LOW);
    }
  
  delay(1000); //just here to slow down the output so it is easier to read
  
}


float getTemp(){
  //returns the temperature from one DS18S20 in DEG Celsius

  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return -1000;
  }

  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      return -1000;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end

  byte present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad

  
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data = ds.read();
  }
  
  ds.reset_search();
  
  byte MSB = data[1];
  byte LSB = data[0];

  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
  
  return TemperatureSum;
  
}
 

lastRites

Joined Jul 9, 2011
13
A slight modification of the loop code snippet will get you temperature proportional fan control ;) :

Rich (BB code):
void loop(void)
 {   
 float temperature = getTemp();
 float tempF = (temperature * 9.0)/ 5.0 + 32.0;
 Serial.print(tempF);
 if (tempF<77)
  {
    digitalWrite(fanPin, LOW);
  }
else
 {
    tempF = map(tempF,77,80,50,255); 
    // speed = map(temp,leasttemp,maxtemp,leastspeed,maxspeed);
    Serial.println("Speed:");
    Serial.print(tempF);
    analogWrite(fanPin, tempF);
  }
}
 

SgtWookie

Joined Jul 17, 2007
22,230
You probably don't want to turn the fans completely off; it depends on how you're sensing the temperature.

One common method of ambient temp sensing is to have a thermistor mounted in the intake airstream of a fan, and have the speed of the fan be a function of the thermistor's temperature. However, you can't turn the fan completely off, or the thermistor will have a very delayed reaction to whatever it is that you are trying to keep cool.
 
Top