Controlling the speed of a fan with PWM

Last modified 1 week

We are going to see how to control the speed of a fan with PWM. What it consists of and why to do it this way.

Fans are often used for cooling computers, microcontrollers, power supplies, amplifiers, graphics cards, etc. and controlling the speed of a fan with PWM can be very desirable to reduce the noise generated by these devices.

These are usually small, low-power fans, operating on direct current and low voltages of between 5V and 12V.

These fans have an electric motor that rotates the blades and creates an airflow that dissipates the heat generated by the components.

There are different types of cooling fans, depending on their size, shape, number of blades, noise, power consumption and performance. Some examples are:

  • Axial fans: these are the most common and are characterised by their blades parallel to the motor shaft. They are suitable for moving large volumes of air at low pressure and are usually placed at the rear or side of computer cases.
  • Centrifugal fans: have blades perpendicular to the motor shaft and generate a radial airflow. They are more efficient than axial fans for moving air at high pressure and are often used in liquid cooling systems or power supplies.
  • Tangential fans: have blades arranged in the shape of a cylinder and create an airflow parallel to the motor shaft. They are very quiet and are used in equipment that requires uniform cooling, such as projectors or amplifiers.

To control the speed of these low-power fans, the PWM (Pulse Width Modulation) technique can be used, which consists of varying the width of the electrical pulses that feed the motor. In this way, the power and consumption of the fan can be regulated, as well as the noise level and the temperature of the system.

If you don't know what a PWM signal is, I explain it in the following article:

To apply PWM, an electronic circuit is needed to generate the pulses with the desired frequency and duty cycle. The duty cycle is the percentage of time the pulse is on high relative to the total period. For example, a 50% duty cycle means that the pulse is high half the time and low half the time.

The PWM circuit can be built with discrete components, such as transistors, resistors and capacitors, or with integrated circuits, such as the 555 or the Arduino. The PWM circuit is connected to the red wire of the fan, which is the positive power supply, while the black wire, which is the negative, is connected directly to the power supply. Some fans also have a yellow wire, which is the wire that sends a signal with the fan speed to the system.

We are going to focus, for practical reasons, on the small 5V DC fans that are used in small devices, such as our beloved Raspberry Pi mini computers.

Types of 5V DC fans

There are basically three types of fans that we can use to cool our devices, and we are going to see what they are and their main characteristics. I will tell you that, for the most part, the first type, the basic DC fan, is used most of the time.

Basic DC fan (two wires)

This is a simple fan that only has a DC motor that moves the blades. In this case, its speed will depend on the voltage we feed it with.

It has only two wires, the positive and negative power wires (which, by the way, you can connect backwards and the fan will rotate in the opposite direction).

These are the typical, cheap fans that you can find everywhere.

DC fan with tachometer output (three wires)

Like the previous one, it is a simple DC motor, exactly the same as the previous one.

The difference is that it has a third cable (the tachometer output) that allows our device to know at what speed the fan is actually spinning.

DC fan with PWM input (three wires)

It is a DC fan that integrates, inside the fan itself, the speed control circuit that we are going to mount on this page.

In practice, this fan is not often encountered. Why? Because active PWM control usually needs an output so that the controller knows whether it is spinning and at what speed.

This type of fan can easily be made with a basic DC fan + PWM control circuit. It will be the same, except that the control circuit will be outside the fan.

DC fan with PWM input and with tachometer output (four wires)

This type of fan is a mixture of the two previous ones, as it includes the circuit to control its speed and, in addition, it has an output so that the device to which it is connected (a Raspberry Pi, for example) knows how many RPM it is spinning at.

They are usually the best quality and quietest fans, with the best bearings and the longest durability. The problem is that they are usually expensive fans (starting at 15 euros, but can go up to €50, €100 and more).

How to regulate the speed of a DC fan?

Basically, there are two ways to regulate the speed of the small direct current (DC) fans that we use to cool our devices:

  • Voltage regulation
  • PWM control

Regulating the speed of a fan by voltage

The DC fans we use in, for example, Raspberry Pi are usually 5V.

This means that, if we power them with 5V, we should (at least in theory) achieve the results indicated by the fan manufacturer in terms of speed, noise, airflow, power consumption, etc.

If we power one of these 5V fans with 3.3V we will get the fan to spin slower (in most, some, very few, 5V fans do not get to move with only 3.3V), this will have the following implications:

  1. The fan will spin more slowly, so it will make less noise.
  2. By turning more slowly, the airflow will decrease, and with it its cooling capacity.
  3. It will consume less energy, but will be less efficient

This tells us that if we want to reduce the noise of our fan in a very simple way, and we can afford to reduce the cooling capacity without the Raspberry Pi getting too hot (which is usually not a problem), we just need to power the fan from the 3.3V pin, rather than the 5V pin, to achieve this.

Fortunately, powering the fan at 3.3V is very easy on the Raspberry Pi, and we do not need any additional hardwareWe have a 3.3V output on the expansion port and we can use it to power the fan.

It is obvious, but the disadvantage of this system is that we can only lower the speed, we cannot regulate it. In addition, the fan will spin at "whatever it touches" feeding it at 3.3V, and it will depend on each model, we can't make any adjustment.

PWM fan speed control

The second way to regulate the speed of a fan, and the best for our purposes, is by using a type of signal called PWM (Pulse Width Modulation).

Don't worry if you don't know what a PWM signal is, there is a blog article in which I explain it in a simple way, what is a PWM signal.

The great advantage of using a PWM signal is that we can turn the fan at any speed we wantbetween the minimum allowed by the fan (below this minimum, which depends on each fan, it will simply stop, while it tries to rotate) and the maximum corresponding to its nominal supply voltage (minus any losses generated by our circuit).

Another advantage of using PWM is that many modern computers and microcontrollers are specially equipped to generate such a signal natively. Even their hardware includes PWM generators that do not require the involvement of the CPU, or other elements, to operate.

It also has a small disadvantage, and that is that most of the time we will need some additional electronics to control the fan via PWM, as the PWM signal provided to our device (the Arduino or Raspberry Pi, for example) is too "small" and needs to be "amplified".

What next?

Now that we know how to control the speed of a motor using a PWM signal, the most fun part is to implement it.

In the following article you can see in detail how to build a driver with a BJT transistor.

You will find a tutorial on the blog in which you will be able to see how to controlling a fan via PWM on a Raspberry Pi 4:

Leave a comment