DC Fan Help

Hi im new to the forums (and arduino) and was having some trouble

i want to control a 12V DC CPU fan that i have setup. I can do so by varying the output to a transistor (BC338) but when i do the transistor tends to flick on and off and so does the fan(the fan gets horribly annoying when it does 0.o), and so i was wondering is there anyway to fix it. After all the things ive read, its to do with the pwm output where it doesnt change the voltage but changes the duty cycle so it is constantly switching on and off, so i was wondering if there is way to convert this to a certain voltage?

Thx in advance MadMatt

http://provideyourown.com/2011/analogwrite-convert-pwm-to-voltage/

sorry but it didnt work i tried it while i was looking for an answer but thanks for trying :smiley:

MadMatt:
when i do the transistor tends to flick on and off and so does the fan(the fan gets horribly annoying when it does 0.o)

The PWM frequency is high enough that the individual pulses should not be perceptible if it's working correctly, so I wonder whether there's something other than PWM happening here. Is it possible the Arduino is resetting for some reason? You could use trace output on the Serial port to find out.

im really new to C im surprised i could do what i did with arduino so how do i do that (i use game maker instead of C but i must say GML is a bit like C)

oh and this is my code:

//

const int transistorPin = 9;

void setup() {pinMode(transistorPin,OUTPUT);}

void loop()
{
//int sensorValue = analogRead(A0);
int outputValue = map(255,0,1023,0,255);
analogWrite(transistorPin,outputValue);
}

//

Have you put a resistor in series with arduino output?

yes a 560 ohm resistor for the transistor or else the voltage is too high for it :confused:

That sketch looks similar to the example in the documentation for analogWrite() and I'd expect the example to work. I see you've commented out the analogRead() part and are just outputting a constant 255 (100% duty cycle). Does this sketch actually show the problem?

y = map(x, 1, 50, 50, 1);

First parameter is expected to be variable.
http://arduino.cc/en/Reference/Map

yeah sorry that was the sketch of when i had the fan at high

//

const int transistorPin = 9;

void setup() {pinMode(transistorPin,OUTPUT);}

void loop()
{
//int sensorValue = analogRead(A0);
int outputValue = map(120,0,1023,0,255);
analogWrite(transistorPin,outputValue);
}

//

this one is where the fan makes a horrible on/off noise because each time a cycle comes round (e.g 50%) it goes on/off each time so instead of adjusting the voltage it keeps on going on and off so it makes a noise when the fan keeps going on and off :confused: it gets annoying as well

Given that you are outputting a constant value, you might just as well put that value directly in the call to analogWrite() rather than map it from another constant.

When you say it's making a noise, do you mean the motor is stuttering on/off of that the motor moves smoothly but makes an audible noise? Can you describe the noise - is it steady and consistent?

yeah its going on and off like you said and it is making a hearable noise and is consistent any soloutions?

Clarify - is the motor stuttering on and off, or is it moving steadily?

What is the noise like?

You can see and hear what's going on - we can only guess from your description, which hasn't told us much so far.

You might need a capacitor to smooth out the output signal of the transistor, going to the motor. Just put a capacitor from the between the motor contacts, make sure you wire it correctly (polarized). It should get rid of any noise, unless the noise is not from the PWM but from a defect in the motor itself.

470uf should be more than enough.

making a hearable noise

The pwm frequency is too high.

You might need a capacitor to smooth out the output signal of the transistor, going to the motor. Just put a capacitor from the between the motor contacts, make sure you wire it correctly (polarized). It should get rid of any noise, unless the noise is not from the PWM but from a defect in the motor itself.

470uf should be more than enough.

thanks soo much that really worked :smiley: sorry about everyones else suggestions didnt really help :confused:

The simplest things can sometimes make the biggest differences.

MadMatt:
sorry about everyones else suggestions didnt really help :confused:

np, wont bother again

next time google + motors, good luck

MadMatt:
You might need a capacitor to smooth out the output signal of the transistor, going to the motor. Just put a capacitor from the between the motor contacts, make sure you wire it correctly (polarized). It should get rid of any noise, unless the noise is not from the PWM but from a defect in the motor itself.

470uf should be more than enough.

thanks soo much that really worked :smiley: sorry about everyones else suggestions didnt really help :confused:

That solution has two problems: (a) you are probably exceeding the current rating of the transistor, because there will be a surge of current to charge the capacitor every time the transistor turns on; (b) you will probably find that you have only a small amount of control over the fan speed, it will mostly run near full speed.

If you want to control a PC-type fan, the best solution is to buy a 4-pin fan designed for PWM control. These have a separate PWM input. They are designed to work using a PWM frequency around 25KHz, so you need to increase the Arduino PWM frequency.

sorry about everyones else suggestions didnt really help :confused:

Don't feel bad for others, feel bad for yourself for missing a good chance to learn.