Pages: 1 2 [3] 4   Go Down
Author Topic: How do I control fan speed on 12V DC fan?  (Read 24257 times)
0 Members and 1 Guest are viewing this topic.
Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34585
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Is that the only code you are running? If so there is nothing that turns on the fan. It just sets the brightness of an LED to the value on the pot. If you still have your fan wired up as above it is connected to pin 7 which the code is not touching. If you move the base from pin 7 to pin 11 the fan should come on.

PS. When posting code here copy it, then hit the hash icon on the top row of the reply box (9 from the left) and paste the code between the two sets of square brackets that pop up. In that way you have a scrollable window and it saves space.
Logged

Norfolk
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you mike for the tip


Code:
int fanA= 4;
int fanB = 7;
int fanC= 8;


int fanaVal = 0;
int fanbVal = 0;
int fancVal = 0;
int potpinA = 0;
int potpinB = 1;
int potpinC = 2;

char controlChar;

void setup() {}



void loop() {
fanaVal = analogRead(potpinA);
fanbVal = analogRead(potpinB);
fancVal = analogRead(potpinC);

analogWrite(fanA, fanaVal);
analogWrite(fanB, fanbVal);
analogWrite(fanC,fancVal);
}




So the above code gets it to respond to the potentiometer but it seems that there is no real noticeable change in the speed and when i check the power range the fan is receiving it just jumps from 0V to 11.47V when i turn the 10K pot...any thoughts as to why i'm still not getting any feasible range of voltages?


Would it be possible to apply power to the fan and then let it coast to a certain rpm then apply power again kind of to perpetuate a slower rotation, is that possible?

thanks!!
Logged

Yours in Design,
-Ray-

Eagle Scout ‘08
Bishop Ireton H.S. ‘08
Old Dominion University '12
Web Designer

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Remember that analogRead() returns 0-1023 and analogWrite() needs 0-255.  You'll need to do some scaling!
Logged

Norfolk
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Very true(i'm mostly familiar with 255 in DMX lighting control) but shouldn't i get more than a 0.27 voltage change on a 10K pot?

Is Arduino written in C or JAVA?
Logged

Yours in Design,
-Ray-

Eagle Scout ‘08
Bishop Ireton H.S. ‘08
Old Dominion University '12
Web Designer

Norfolk
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Come to think of it i'm not sure it matters what it's written in since AP JAVA was a year ago and C++ is this coming semester so i'm stuck in the no man's land of forgot more than i learned and won't brush up until class starts   :-p
Logged

Yours in Design,
-Ray-

Eagle Scout ‘08
Bishop Ireton H.S. ‘08
Old Dominion University '12
Web Designer

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
shouldn't i get more than a 0.27 voltage change on a 10K pot?

Well, that depends on how the pot is wired up.  Can you show us a schematic?
Logged

Norfolk
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure thing...comin' right up
Logged

Yours in Design,
-Ray-

Eagle Scout ‘08
Bishop Ireton H.S. ‘08
Old Dominion University '12
Web Designer

Norfolk
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset



There ya go!
« Last Edit: January 07, 2009, 04:13:12 pm by Chronicdiving » Logged

Yours in Design,
-Ray-

Eagle Scout ‘08
Bishop Ireton H.S. ‘08
Old Dominion University '12
Web Designer

canada
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Insert text here:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The analogWrite functions only work with pins marked with PWM! You need to change the motor pins to ones marked with PWM.

That should solve your problem!

Nigel
Logged


Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

with the pot wired like that (which is correct), you should get a voltage range of zero to 5V on your analog input pin.  You can, of course, check that with a multimeter.

But, do you need any pinMode() calls in your 'setup()' function?  Do you need to select analog input mode on potPinA, potpinB, potpinC?  And do you need to specify PWM output on the other pins?  I'm not sure, myself, but I have seen that sort of thing in other Sketch code.
Logged

Norfolk
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Great! I changed the code to the one below and it's working great...only down side is this 10K doesn't seem to be very coarse so i'll get 100K or maybe 1M that way it will be easier to change...i've got a 2-11.47V range so there's enough variation that i was seeing different patterns which is really cool...thanks Nigel for the correction!



Code:
int fanA= 3;
int fanB = 5;
int fanC= 6;


int fanaVal = 0;
int fanbVal = 0;
int fancVal = 0;
int potpinA = 0;
int potpinB = 1;
int potpinC = 2;

char controlChar;

void setup() {}



void loop() {
fanaVal = analogRead(potpinA);
fanbVal = analogRead(potpinB);
fancVal = analogRead(potpinC);

analogWrite(fanA, fanaVal);
analogWrite(fanB, fanbVal);
analogWrite(fanC,fancVal);
}

Logged

Yours in Design,
-Ray-

Eagle Scout ‘08
Bishop Ireton H.S. ‘08
Old Dominion University '12
Web Designer

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The value of the pot won't affect the "coarseness" or "fineness" of the control.  And 10k is as large a value as will work properly with the Arduino (due to the ADC input capacitance).  Could you compensate for the difficulty in control by scaling or offsetting the numbers in the code?

Oh, and that code still has no pinMode() calls nor scaling -- are you sure it's the right version?
« Last Edit: January 07, 2009, 07:42:45 pm by anachrocomputer » Logged

Norfolk
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Anachrocomputer, thanks!, lol i have no idea to 1/2 those questions but the current code seems to be working just fine

Grumpy_mike...i was sleuthing around and i found your website...great stuff! tutorials are also good...what magazine did you used to write for again?




So here's the code I have for my past LED project

Code:
int bluePin = 9;
int redPin = 10;
int greenPin = 11;


// readings from the serial port
int blueVal = 0;
int redVal = 0;
int greenVal = 0;

char controlChar;
 
void setup() {
  analogWrite(redPin, redVal);
  analogWrite(greenPin, greenVal);
  analogWrite(bluePin, blueVal);
  
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() >= 2) {
    controlChar = Serial.read();
    if (controlChar == 'r') {
      redVal = Serial.read();
      analogWrite(redPin, redVal);
    } else if (controlChar == 'g') {
      greenVal = Serial.read();
      analogWrite(greenPin, greenVal);
    } else if (controlChar == 'b') {
      blueVal = Serial.read();
      analogWrite(bluePin, blueVal);
    }
  }
}


This takes info from a program that reads the internal mic on the computer to create a "beat to music" effect





How could I get the fan sketch that's uploaded to the board to interpret the data from the LED program?

Thanks!
Logged

Yours in Design,
-Ray-

Eagle Scout ‘08
Bishop Ireton H.S. ‘08
Old Dominion University '12
Web Designer

Norfolk
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

anachrocomputer...so 10K pot is the highest the arduino can read? I guess scaling would work, so you would have to basically write it so that it was a 10:1 ratio with the pot taking 10x as many degrees to change 1 volts worth, yeah?

I'm pretty positive that's the right code...although i haven't done any scaling yet(i'm not strong enough in coding to really put any of this stuff together myself yet although hopefully after this semester is over i should be able to)


Here's what's on the board right now and when i turn the pot the fans slow down and speed up...i put a multimeter on the + and - of the fan and i got 3-11.47V


Code:
int fanA= 3;
int fanB = 5;
int fanC= 6;


int fanaVal = 0;
int fanbVal = 0;
int fancVal = 0;
int potpinA = 0;
int potpinB = 1;
int potpinC = 2;

char controlChar;

void setup() {}



void loop() {
fanaVal = analogRead(potpinA);
fanbVal = analogRead(potpinB);
fancVal = analogRead(potpinC);

analogWrite(fanA, fanaVal);
analogWrite(fanB, fanbVal);
analogWrite(fanC,fancVal);
}


« Last Edit: January 07, 2009, 07:52:00 pm by Chronicdiving » Logged

Yours in Design,
-Ray-

Eagle Scout ‘08
Bishop Ireton H.S. ‘08
Old Dominion University '12
Web Designer

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Higher value pots than 10k will work, but there is a (theoretical) small error due to input capacitance at the AVR's pin.  And anyway, the value of the pot won't affect the voltage when it's wired up as you have is, as a voltage divider.  When the pot's wiper is half-way along the track, the voltage will be 2.5V at the analog pin, regardless of the value of the pot.

Wait a minute, that's made me think of something!  Is your pot a "log" or "lin" pot?  Logarithmic or linear, that is?  Log pots are sometimes called "audio taper" in the USA, I think.  You need a linear pot for this sort of application.  Check the voltage at the pot's centre terminal as you turn it, and see if half-way corresponds to 2.5V.
« Last Edit: January 07, 2009, 07:57:50 pm by anachrocomputer » Logged

Pages: 1 2 [3] 4   Go Up
Jump to: