Offline
Newbie
Karma: 0
Posts: 9
|
 |
« on: January 01, 2013, 05:44:13 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
SE USA
Offline
Faraday Member
Karma: 35
Posts: 3649
@ssh0le
|
 |
« Reply #1 on: January 01, 2013, 05:59:32 pm » |
|
|
|
|
|
Logged
|
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #2 on: January 01, 2013, 06:02:33 pm » |
sorry but it didnt work i tried it while i was looking for an answer but thanks for trying 
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 99
Posts: 6784
-
|
 |
« Reply #3 on: January 01, 2013, 06:30:43 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #4 on: January 01, 2013, 06:42:24 pm » |
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); }
//
|
|
|
|
« Last Edit: January 01, 2013, 06:52:08 pm by MadMatt »
|
Logged
|
|
|
|
|
Montreal
Offline
Edison Member
Karma: 18
Posts: 2227
Per aspera ad astra.
|
 |
« Reply #5 on: January 01, 2013, 06:57:27 pm » |
Have you put a resistor in series with arduino output?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #6 on: January 01, 2013, 07:10:56 pm » |
yes a 560 ohm resistor for the transistor or else the voltage is too high for it :/
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 99
Posts: 6784
-
|
 |
« Reply #7 on: January 01, 2013, 07:56:12 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Montreal
Offline
Edison Member
Karma: 18
Posts: 2227
Per aspera ad astra.
|
 |
« Reply #8 on: January 01, 2013, 08:29:58 pm » |
y = map(x, 1, 50, 50, 1); First parameter is expected to be variable. http://arduino.cc/en/Reference/Map
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #9 on: January 02, 2013, 12:17:52 am » |
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 :/ it gets annoying as well
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 99
Posts: 6784
-
|
 |
« Reply #10 on: January 02, 2013, 08:54:06 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #11 on: January 04, 2013, 02:24:00 am » |
yeah its going on and off like you said and it is making a hearable noise and is consistent any soloutions?
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 99
Posts: 6784
-
|
 |
« Reply #12 on: January 04, 2013, 09:10:52 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 31
Posts: 1730
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #13 on: January 04, 2013, 09:21:39 am » |
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.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #14 on: January 04, 2013, 09:48:33 am » |
making a hearable noise The pwm frequency is too high.
|
|
|
|
|
Logged
|
|
|
|
|
|