Need help: Arduino and fan (pwm)

I'M CONTROL THE SPEED OF MY PC 12V FAN (0-255) BUT THE FAN START WITH OFF MODE (SPEED 0).

MY Q IS: WHAT I NEED TO ADD TO MY CODE TO START THE FAN AT 25 (ON) WHEN MY ARDUINO UNO START, AND AFTER THAT GIVE MY THE OPTION TO INCREASE THE SPEED (25 TO 255).

int motorPin = 3;
 
void setup() 
{ 
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
  while (! Serial);
  Serial.println("Speed 0 to 255");
} 
 
 
void loop() 
{ 
  if (Serial.available())
  {
    int speed = Serial.parseInt();
    if (speed >= 0 && speed <= 255)
    {
      analogWrite(motorPin, speed);
    }
  }
}

How is the fan connected to the Arduino? What is powering the fan? Circuit diagram, please.

groundfungus:
How is the fan connected to the Arduino? What is powering the fan? Circuit diagram, please.

  • (12 VDC) TO FAN +
  • (12 VDC) TO D (transistor)
    G (transistor) TO ARDUINO PIN 3
    S (transistor) TO GND & -

THE FAN HAVE ONLY 2 WIRES!!! (- +)

I CAN BUY ONE - BUT I NEED TO KNOW WHAT THE COMMAND TO START THE FAN (POWER ON) AND AFTER THAT, INCREASE THE SPEED. FOR 2 WIRES & 4 WIRES (PWM).

I INCREASE THE SPEED FROM 0 TO 255 WITH NO PROBLEMS, BUT THE FAN DON'T START AUTO WHAN THE THE UNO POWER ON.

INT FANSPEED = 25; - DON'T WORK.

This should start the fan from a base of 25.

int motorPin = 3;
 
void setup() 
{ 
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
  while (! Serial);
  Serial.println("Speed 0 to 255");
 
  analogWrite(motorPin,25); //add this line and speed should start at 25 
} 
 
 
void loop() 
{ 
  if (Serial.available())
  {
    int speed = Serial.parseInt();
    if (speed >= 0 && speed <= 255)
    {
      analogWrite(motorPin, speed);
    }
  }
}

ardoking:
I CAN BUY ONE - BUT I NEED TO KNOW WHAT THE COMMAND TO START THE FAN (POWER ON) AND AFTER THAT, INCREASE THE SPEED. FOR 2 WIRES & 4 WIRES (PWM).

I INCREASE THE SPEED FROM 0 TO 255 WITH NO PROBLEMS, BUT THE FAN DON'T START AUTO WHAN THE THE UNO POWER ON.

INT FANSPEED = 25; - DON'T WORK.

Why are you screaming?

PaulS:
Why are you screaming?

who?! you :slight_smile:

cattledog:
This should start the fan from a base of 25.

int motorPin = 3;

void setup()
{
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
  while (! Serial);
  Serial.println("Speed 0 to 255");

analogWrite(motorPin,25); //add this line and speed should start at 25
}

void loop()
{
  if (Serial.available())
  {
    int speed = Serial.parseInt();
    if (speed >= 0 && speed <= 255)
    {
      analogWrite(motorPin, speed);
    }
  }
}

cattledog:
This should start the fan from a base of 25.

int motorPin = 3;

void setup()
{
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
  while (! Serial);
  Serial.println("Speed 0 to 255");

analogWrite(motorPin,25); //add this line and speed should start at 25
}

void loop()
{
  if (Serial.available())
  {
    int speed = Serial.parseInt();
    if (speed >= 0 && speed <= 255)
    {
      analogWrite(motorPin, speed);
    }
  }
}

Thank you :slight_smile: