Im trying to make an arduino controlled PWM fan using a potentiometer. Ive connected the circuit as in the diagram below (The transistor is a TIP120 if it's hard to read):

Circuit Diagram

Here is my code:

int fan = 9;
void setup() {
  pinMode(fan, OUTPUT);

void loop() {
  int pot = analogRead(A0);
  int sig = map(pot, 0, 1023, 0, 255);
  analogWrite(fan, sig);


My problem is the readings from the potentiometer are, in my opinion, random. When I turn the pot, there isn't any differnce. An example of the readings are below:

65 118 193 134 67 116 192 137 66 112 193 144 64 106 194 145 65 104 193 148 64

The connections seem to be good, im using a breadbord and I've soldered wires to the pins on the pot (It didn't make a difference). Thanks for any help.

P.S Ive tried two different pots and I get the same result

  • Try to run the program with the fan disconnected: only the pot and the serial output. Is it as erratic as with the fan? – Edgar Bonet May 29 at 13:10
  • Just tried it, and the numbers look slightly more stable but still no responce when turning pot. I'm beginning to think the pot is faulty as they were cheap from ebay anyway – Niall895 May 29 at 13:59
  • And what if you connect A0 to the 3.3V output of the Uno? – Edgar Bonet May 29 at 14:03
  • Fan spins below top speed on 3.3v, full speed on 5v and stops on ground – Niall895 May 29 at 14:20
  • 1
    I know it is silly, but have you connected the potentiometer pins correctly? Can you check the potentiometer resistance with an ohmmeter? – JSC May 29 at 20:50

In my experience it is bad connections 90 percent of the time.

| improve this answer | |

In your setup you may need

pinMode(A0, INPUT);

At least, that seemed to fix a similar problem I was having.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.