It looks like that would work fine. If you wanted you could also likely read the speed of the fan back using another pin on the Arduino to connect to the sense pin, but that is probably over-complicating things.
Pin 1 Black (GND), Pin 2 Yellow (PWR), Pin 3 Green (SGN), Pin 4 Blue (PWM)
I would hook the 12v (Yellow) to a power supply and ground (Black) to both the power supply and the arduino. Finally hook the PWM digital pin 9 to the PWM wire (Blue) on the fan. Do not know what to do with the signal (Green) wire?
Still looking for code to read the PWM from the fan though....
Pin 1 Black (GND), Pin 2 Yellow (PWR), Pin 3 Green (SGN), Pin 4 Blue (PWM)
I would hook the 12v (Yellow) to a power supply and ground (Black) to both the power supply and the arduino. Finally hook the PWM digital pin 7 to the PWM wire (Blue) on the fan. Do not know what to do with the signal (Green) wire?
Still looking for code to read the PWM from the fan though....
David
IIRC, the green wire is a tach signal, that you can use to determine the current speed of the fan.
I gather that the PWM would be in the range of 0-255 when writing out to it from the ardunio?
int pwmPin  = 9;  // fan PWM -> connected to digital pin 9
int pwmVal  = 0;
int DEBUGÂ Â = 1; // DEBUG counter; if set to 1, will write values back via serial
void setup()
{
 pinMode(pwmPin, OUTPUT);  // sets the pin as output
 if (DEBUG) {
  Serial.begin(9600);
 }
}
// Main program
void loop()
  analogWrite(pwmPin, pwmVal);
  if (DEBUG) { // If we want to read the output
   if (pwmVal != 255) {
    pwmVal += 10;
    Serial.print(pwmVal); // Print red value
    Serial.print("\t");  // Print a tab
   } else {
    Serial.print('at max high'); // Print red value
    Serial.print("\t");  // Print a tab
   }
  }
  delay(wait); // Pause for 'wait' milliseconds before resuming the loop
}
I gather that the PWM would be in the range of 0-255 when writing out to it from the ardunio?
Yes.... except that the Arduino PWM is under 500Hz, and the datasheet says it needs 25kHz PWM. The other ref I gave says it must be between 21 and 28kHz....
The datasheet shows the relationship between duty cycle and speed. PWM = 0 is 0%, 255 is 100%. As you'll see, PWM duty cycle below 30% (~80) still gives 1200rpm; above that it looks more or less linear up to full speed.
I looked at the sheet and i must say, i don't understand the code on there and what it is doing in order to produce the values needed to send to the PWM fan?
Mind throwing together some code for me to visualize it better?
mixania:
Seems good, but consider geting some electronics to handle the current required for the fan and as for a termometer consider buying some thermistors: Thermistor 10K - SEN-00250 - SparkFun Electronics
I already have DS18B20 Thermometer Temperature Sensor as the temp sensor for it to use.
I haven't tried it myself, but the article that terryking228 linked to lists the available PWM frequencies and I don't see any listed within the 21-28 KHz range that you're looking for.
You could try searching Nick Gammon's forum for his articles on timers - he covers this area very well and I expect you'll find a definitive answer there as to whether it's possible to achieve the frequency you need.
I don't see any listed within the 21-28 KHz range that you're looking for.
I suspect that is a 'recommended" range and I bet that any somewhat lower frequency would work. Just test the fan speed separately to start. Let us know what you find...
The recommended frequency range looks like it might have been set to make sure that the switching frequency is above the range of human hearing. This keeps the fan from making an annoying high pitched noise. If this is the reason for the recommendation you could push the frequency lower without too much issue. There could be other reasons for the recommendation, but this is a likely one. I would raise my PWM frequency as much as I could, but them just go with whatever I had.
I hooked the incorrect pin on the fan for the PWM so now it does change speeds but when i put it on "1" its still pretty loud/fast. Its spinning about 2,040 RPMs on "1".