Arduino PWM to PC fan Problem :S

So I have my arduino hooked up to the PC fan PWM input, although it is a 12v fan to play it safe i wanted to get it working with the arduino with a 9V battery before I hook it up to the mains. It is a 4 wire fan and I'm connecting the Arduino PWM pin directly to the pwm wire on the fan as you can see below:

the problem I'm having is that the analogWrite() code I'm using doesn't seem to work, there is no difference in fan speed when I set it to 255 or even when I set it to 0. To make your lives easier I've included the code below:

int pcFan = 3; // PC fan is connected to the Digital pin 3
int led = 13; // I'm using the built-in LED on pin 13 to tell me when the fan should be moving at full speed or not.

void setup()
{
  pinMode (pcFan, OUTPUT);
  pinMode (led, OUTPUT);
}

void loop()
{
  analogWrite(pcFan, 0); // Turn Fan and LED off for 5 seconds
  digitalWrite(led, LOW);
  delay(5000);

  analogWrite(pcFan, 255); // Spin Fan at full speed and turn on LED on for 5 seconds
  digitalWrite(led, HIGH);
  delay(5000);
}

any help would be most appreciated,
thanks in advance.

Hi bro........ Is there any library for controlling bldc motors with esc using arduino>>>> i cant understand the way to control it ...will this work:(

#include <Servo.h>
Servo.motor;
void trottle() {
speed(0);
delay(1000);
}
void speed(int rpm) {
int angle = map(rpm, 0, 100, 0, 180);
 motor.write(angle);
}
void setup() {
motor.attach(9);
trottle();
}
void loop() {
speed(40);
delay(1000);
}

@missisipihipi

Hi
so the cabel to control your motor is connected to a digital pin on your Arduino. Why do you use an analog command then?

analogWrite(pcFan, 0);

You have to use an digital command ( sorry if that is called different ).

digitalWrite(pcFan, 0);

So try it with this code :

int pcFan = 3; // PC fan is connected to the Digital pin 3
int led = 13; // I'm using the built-in LED on pin 13 to tell me when the fan should be moving at full speed or not.

void setup()
{
  pinMode (pcFan, OUTPUT);
  pinMode (led, OUTPUT);
}

void loop()
{
  digitalWrite(pcFan, 0); // Turn Fan and LED off for 5 seconds
  digitalWrite(led, LOW);
  delay(5000);

  digitalWrite(pcFan, 255); // Spin Fan at full speed and turn on LED on for 5 seconds
  digitalWrite(led, HIGH);
  delay(5000);
}

I use the "analogWrite()" command because that is the only way to PWM a pin, "digitalWrite()" (if i'm not mistaken) can not do PWM signals, it can only do "HIGH" or "LOW"

Did you tried it? It won´t damage your Arduino?

i have tried it and i get exactly the same result as before, fan spins at same speed regardless of weather i put a "255" or a "0"

Ok I dont know what is wrong then but i found a similar Tutorial in a book called 30 projects fo the evil Genius. Here is the Website: www.arduinoevilgenius.com

But anyway here is the code:

int motorPin = 11;

void setup()
{
  
  pinmode(motorPin, OUTPUT);
  analogWrite(motorPin, 0);
  Serial.begin(9600);
}


void loop()
{
  if (Serial.available())
  {
    char ch = Serial.read();
    if (ch>= '0' && ch<= '9')
    { 
      
        int speed = ch - '0';
        analogWrite(motorPin, speed*28);
     }
   }
}

I quickly copied it from the book so if there are any mistakes in the code you can download it from the link at the top. When you send values from 0 to 9 to your Arduino you can control the speed of the motor.

BEFORE UPLOADING:
This project requieres additionaly to th arduino and the fan an BD139 power transistor and a 270Ohm 0.5W resistor.

Connecting it: (sorry I didn´t find a circuit diagramm :()

Arduino:
Digital Pin 11 to 270 Ohm resistor

Transistor:
B:270 Ohm Resistor
C:Motor
E:GND

Motor:
12V
Collector of Transistor

With this tutorial you also don´t have to worry about the 2 other cables on the Motor you just need the positive an negative cabel. But remember THIS IS NOT MY TUTORIAL.

Hope I could help you.

thank you for your reply and i am aware that it is possible to achieve a similar result with the use of an NPN transistor, but i specifically bought the fan because of its PWM capabilities and would really rather be able to do it directly (but thanks anyway)

Seriously does noone have any idea why this isn't working? i'm at my wits end! :~ :blush: =(

From this document - http://formfactors.org/developer/specs/4_Wire_PWM_Spec.pdf ?

2.1.4 PWM Control Input Signal
The following requirements are measured at the PWM (control) pin of the fan cable connector see
Figure 7 and Table 1:
PWM Frequency: Target frequency 25 kHz, acceptable operational range 21 kHz to 28 kHz
Maximum voltage for logic low: VIL = 0.8 V
Absolute maximum current sourced: Imax = 5 mA (short circuit current)
Absolute maximum voltage level: VMax = 5.25 V (open circuit voltage)
This signal must be pulled up to a maximum of 5.25V within the fan.

The default Arduino PWM frequency is 488Hz.