Controlling 12V PWM fan using 5V arduino with potentiometer

My goal is to control a 12V PWM Fan using an Arduino Nano, also I want to control the fan speed with a potentiometer. My first setup looks like this:

This works for roughly 10 sec before the arduino starts overheating, this causes the fan to periodically spin faster and slower when the potentiometer is set to, e.g., half speed.
My solution was to use a voltage transformer to power the arduino and the potentiometer with 5V instead:

Sadly, the control will not work like this. The fan spins at full speed, no matter how the potentiometer is set. For the sake of completeness, this is the code I use, largely copied from here:

const byte OC1A_PIN = 9;
const byte OC1B_PIN = 10;

const word PWM_FREQ_HZ = 25000; //Adjust this value to adjust the frequency
const word TCNT1_TOP = 16000000/(2*PWM_FREQ_HZ);

int potVal;
int potPin = A2;
int fanVal;

void setup() {

  pinMode(OC1A_PIN, OUTPUT);

  // Clear Timer1 control and count registers
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;

  // Set Timer1 configuration
  // COM1A(1:0) = 0b10   (Output A clear rising/set falling)
  // COM1B(1:0) = 0b00   (Output B normal operation)
  // WGM(13:10) = 0b1010 (Phase correct PWM)
  // ICNC1      = 0b0    (Input capture noise canceler disabled)
  // ICES1      = 0b0    (Input capture edge select disabled)
  // CS(12:10)  = 0b001  (Input clock select = clock/1)

  TCCR1A |= (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11);
  TCCR1B |= (1 << WGM13) | (1 << CS10);
  ICR1 = TCNT1_TOP;

  OCR1A = 0;
  OCR1B = 0;
}

void loop() {
  potVal = analogRead(potPin);
  fanVal = map(potVal, 0, 1023, 0, 100);
  setPwmDuty(fanVal);
}

void setPwmDuty(byte duty) {
  OCR1A = (word) (duty*TCNT1_TOP)/100;
}

I suspect this to be a problem because the arduino is on the 5V circuit and the fan is on the 12V circuit. But as I am a beginner in working with arduino and microcontrollers I have no idea how to fix this. I hope someone can help me make my circuit work.

You feed 5 volt to Vin. Is the Nano a 3.3 volt device?
On other controllers You should feed 5 volt to the 5 volt pin.

Here is a picture of the controller I use:

It does not have a dedicated 5V pin, only VIN. Before I VIN it to feed 12V.
It has a dedicated 5V pin, but using it instead does not make a difference.

Read the specs or the datasheet! 5 volt to Vin might be okey.

Looking at your diagram, it appears that you may be feeding 12V to the Nano analog in!

It would be better to have the positive end of the pot connected to the Nano 5V out, This way, you will be sure not to exceed the max input voltage to the analog pin

Posting schematics is the proper way to show the wiring, not pictures.

I already know, that this microcontroller runs using 5V. For circuits that are purely 5V I never had a problem.

You mean in the first diagram? Do you suggest to connect 5V pin of the nano to the potentiometer but let the ground connection as is?

Hi,
If you haven't burned your nano yet, forget about this option.
By moving the potentiometer to 12V, you will inject 12V into the A2 of the nano, and maybe say goodbye to this port or the nano.

Adjust_Fan

1 Like

Yes, the first diagram. And leave the ground of the potentiometer connected to the ground of the Nano.

Basically, the potentiometer is a fixed resistor from one end terminal to the other. Often you will find this is 10k resistance. But that number will vary depending on the model you choose.

The wiper arm will then pick up the voltage that will depend on the position of the arm. If the arm is at the ground end of the pot, it should read 0, and at the other end, it will read 5V, provided that end is being fed 5V.
If it is connected to 12V, then the Nano analog input will see 12V, and as ruilviana said above, it will probably fry the port and possibly the whole chip.

The only way for you to know for sure is to try and see if it still works.

You cannot connect the Nano Input or output to 12V.
The below is the proper way to set this up. IF the motor PWM input will accept a 5V signal.

R1 being approximately 5K ohms (4k to 6.5k) will protect the nano outputs if the fan control goes to 12V. This is only for protection!

If the Fan PWM input requires a 12 Volt signal you will need a Mosfet (2N7000 or eq) between the Nano and Fan PWM input.

Problem is that the third wire of a 3-pin fan is not a PWM input, but a tach output.
A 4-pin fan is needed for speed control (supply, ground, tach, PWM).
Or a bunch of external parts (resistors, transistors, etc.)

Not soldering the pins of a Nano also won't work.
Leo..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.