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
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"
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
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.
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)
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.