Controlling a PWM 4 wire fan

Good day, i am using a Arduino Nano and i have a code to control the speed of a PWM 4 wire fan via a potentiometer and a PWM of 25 kHz, the potentiometer increase or decreases the duty cycle from 0% to 100%.

The code works fine but i want to control 2x of the same fans each with its own potentiometer individually.

The other thing is i want the fans to completely stop when the potentiometer is on 0 but it seems even if the PWM duty cycle is on 0% the fan still rotates.

Can a mosfet be used to shut off the power. How do i implement this in the code?

This is the code i`m using at the moment.

int potVal;
int potPin = A2;
int fanVal;

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);

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

void setup() {
pinMode(OC1A_PIN, OUTPUT);

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

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

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

The other thing is i want the fans to completely stop when the potentiometer is on 0 but it seems even if the PWM duty cycle is on 0% the fan still rotates.

If the potval is less than a certain threshold send a digitalWrite (fan pin, LOW) to turn it off. If it still will not turn off, there is something funny with the driver.

Most 4-pin fans don't NEED 25kHz to work.
Did you first try a basic sketch like this one (untested).
Leo..

const byte potPin = A2;
const byte fanPin = 5;

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

void loop() {
  analogWrite(fanPin, analogRead(potPin) >> 2);
}

I did get the fan working like it should but even on 0% duty cycle the fan still spins.

The fan data sheet states that the fan does not turn of at 0% duty cycle.

So i added a mosfet in the circuit and edited the code to turn the mosfet on or off.

I now have one fan working with the code but my application requires two fans controlled.

Each fan with it`s own pot so that they can be controlled individually.

How do i control them individually with the same Arduino Nano?

const byte pot1Pin = A2;
const byte pot2Pin = A3;
const byte fan1Pin = 5;
const byte fan2Pin = 6;

void setup() {
  pinMode(fan1Pin, OUTPUT);
  pinMode(fan2Pin, OUTPUT);
}

void loop() {
  analogWrite(fan1Pin, analogRead(pot1Pin) >> 2);
  analogWrite(fan2Pin, analogRead(pot2Pin) >> 2);
}