faqs
guides

Microcontroller guide: PWM setup and RPM monitoring

This article provides information on controlling our fans via PWM when using microcontrollers, single-board computers or development boards, such as Raspberry Pi, Arduino, the ESP family, BeagleBone or STM32. Throughout the guide, these will be referred to as "controlling devices."

Introduction to fan control and fan specifications

First, some fundamental concepts including pin configuration, RPM and PWM are explained.

What are the wires of my 4-pin fan used for?

  • Black (Ground) - Connects to the ground of your microcontroller and external power source, when used.
  • Yellow (Power) ​- Supplies power to the fan (5V, 12V, or 24V depending on your fan model).
  • Green (RPM Signal) - "Tach" or tachometric signal. Sends the fan's speed (RPM) information to your controlling device.
  • Blue (PWM Signal) - Sends the PWM signal from your controlling device to the fan to adjust the fan speed.

These colours are typical for most Noctua 4-pin fans, except for the chromax version which uses single-colour cables. For better and a general understanding, please refer to this image:

Diagram illustrating the pin configuration of Noctua 4-pin fans. The terminal labels include "GROUND," "POWER," "RPM," and "PWM," indicating their respective connections. The image features a connector with four pins arranged in a row, with corresponding colored wires: black for GROUND, yellow for POWER, green for RPM, and blue for PWM.

Our article on pin configuration provides detailed information on the wiring of all our fans, including 3-pin fans and those of our chromax line that do not have colour-coded wires.

What is RPM?
RPM refers to the revolutions per minute, i.e. the fan speed.
The RPM signal provides back this speed information to the appliance that the fan is used with.

What is PWM?
PWM (Pulse Width Modulation) is a method of controlling fan speed, without adjusting the supplied voltage. The PWM signal is provided by your controlling device to the fan, so that the fan adjusts its speed accordingly.

A common metaphor used to explain PWM control is imagining turning a light on and off extremely fast. The longer the light stays on during each cycle the brighter the light appears overall. Similarly, PWM controls the fan speed with adjusting how long the signal stays "on" in each cycle. This is referred to as the duty cycle. The higher the duty cycle, the faster the fan speed.

The relationship between duty cycle and RPM is roughly linear with our fans, e.g. a 50% duty cycle results in roughly 50% of the maximum speed.

The following image shows a 25%, 50% and 75% duty cycle.

The image depicts three PWM duty cycle waveforms: the top shows 25% ON, 75% OFF; the middle shows 50% ON, 50% OFF; and the bottom shows 75% ON, 25% OFF.

Always use the designated PWM pin for fan speed control and do not use PWM over the power line, as this will damage the fan.

For proper control, the controlling device should be equipped with a CMOS inverter circuit, as is commonly found in GPIO pins on microcontrollers like Arduinos. Detailed technical information is provided in our PWM specification white paper.

Important aspects to keep in mind:

  • The target frequency of the PWM signal is 25 kHz, but frequencies in the range of 21 to 28 kHz are supported as well.
    Controlling the fan speed with a PWM signal that has a frequency outside that range will make the fan behave unpredictably. It may spin at a wrong speed, at full speed, or not at all.
  • Our fans recognise 3.3V or 5V as logical high, with the fan internally pulling up the voltage to either of these levels depending on the input signal. A voltage below 0.8V is recognised as logical low.
  • Duty cycles below 20% are not defined. However, most of our fans continue to operate below 20% and will stop at 0%. Some of our fans will continue to run at their minimum speed at 0%, this is specified in the product details on our website.
  • When there is no PWM signal connected, the fan will run at full speed.

Powering the fan

In some cases, it is possible to power a 5V fan directly via your controlling device. Please be cautious not to exceed the device’s current limit (for the pin used) when doing so. This information can typically be found in the device’s specification sheet. Exceeding the current limit will damage your device.

Regardless of whether you’re using a 5V, 12V or 24V fan, it is possible to power the fan via a suitable power supply (5V power supply for 5V fans, 12V power supply for 12V fans etc.) and to connect the fan to the controlling device for speed control only.

When using an external power supply, always connect the fan’s Ground wire to the controlling device's Ground pin to maintain a common reference point which is needed to allow for PWM control. The schematic below demonstrates how this can be implemented, using an Arduino UNO as an example.

Diagram showing the connection of a Noctua fan to an Arduino UNO and an external power supply.

Implementing PWM control

To control fan speed via PWM, a fan with PWM functionality is needed. All of our PWM-compatible fans include “PWM” in their product designation, e.g. "NF-A12x25 PWM".

Once the fan’s power and Ground wires are connected as described in the previous section (either to an external power source or directly to your device, if supported), you can connect the fan’s PWM wire to a pin on your device that supports PWM generation. You can find this information in your device’s specification sheet, which typically includes a pinout diagram showing the function of each pin. Pins that support PWM are often marked with a tilde (~) or asterisk (*).

You will first need to configure the PWM frequency in code (ideally at 25 kHz), typically by using a timer in output compare mode. The PWM frequency is set once and remains constant during operation.

The duty cycle, which determines the fan speed, can then be adjusted through code to set the desired speed.

Reading RPM signals

To optionally monitor fan speed, you can connect the fan’s RPM wire to an input pin on your device.

Our fans generate two pulses per revolution, and the RPM signal is provided through an open collector output. The signal therefore does not carry a voltage of its own, but instead needs to be pulled up to the appropriate voltage level on your device. Typically, this can be achieved by enabling pull-up for the pin that the RPM wire is connected to, or in a more sophisticated setup using an external pull-up resistor (e.g. 1 kΩ).

For cleaner RPM signals, especially in cases where electrical noise may interfere with accurate readings, we recommend adding a 1 µF non-polarised decoupling capacitor between the RPM wire and Ground. This capacitor filters out noise and stabilises the signal. Its correct placement is shown in the connection schematic above.

Calculating Fan Speed (RPM)

The fan speed is a digital pulse signal with a frequency in Hertz (Hz). To calculate the fan speed, this signal can be converted to rotations per minute. This can be done by multiplying the frequency by 60 (to obtain cycles per minute), and then dividing by 2 (as each revolution equals two cycles). For example, if the RPM signal has a frequency of 80 Hz, the fan speed results in 2400 RPM:
(80 × 60 / 2) = 2400 RPM

On your controlling device, you might not be able to work with the RPM signal’s frequency in Hz directly. Instead, you can detect the rising edge of each pulse in the RPM signal. The frequency is the inverse of the time between two rising edges, calculated as:
f [Hz] = 1 / time between pulses

Therefore, when using rising edge detection, you can calculate the fan speed in RPM with the following formula:
fan speed (RPM) = (1 / time between two rising edges [s]) × 60 / 2

Troubleshooting

The fan speed doesn’t change as expected. / The fan always runs at full speed regardless of PWM duty cycle.
Ensure that the PWM frequency is set in the range of 21 to 28 kHz. Frequencies outside of that range might not be detected correctly.

The fan speed settings in my code work only occasionally, seemingly at random.
Ensure that the fan’s Ground wire is properly connected to the controlling device’s Ground pin to provide a common reference point.

The RPM signal stays at 0.
Ensure that you have activated the pull-up resistor on the pin of your controlling device that reads the RPM signal or that you have put an external pull-up resistor in place correctly.

My RPM measurement is too high.
Remember to divide the detected pulses by two, as each fan revolution generates two pulses.

Glossary

CMOS Inverter Circuit – A type of logic circuit that inverts the input signal

Controlling Device – A microcontroller, single-board computer or development board, such as Raspberry Pi, Arduino, the ESP family (such as the ESP32), BeagleBone or STM32

Duty Cycle – The proportion of time that a PWM signal is "on" expressed as a percentage. A higher duty cycle results in a higher fan speed.

GPIO Pin – General Purpose Input/ Output Pin on a microcontroller or microprocessor that can be configured as either input or output

Pull-Up Resistor – A resistor used to ensure that a signal reads as high unless it is actively driven low

PWM – Pulse Width Modulation, a technique used to control fan speed

RPM – Revolutions Per Minute, describes the fan speed

Signal Noise – Unwanted fluctuations in a signal, often created by interference