add wishlist add wishlist show wishlist add compare add compare show compare preloader icon-theme-126 icon-theme-161 icon-theme-138 icon-theme-027 electro-thumb electro-return-icon electro-brands-icon electro-payment
  • +1 (857) 226-1305
  • +86 18825289328

Procedure for Adjusting Fan Speed on the Raspberry Pi 5 Controller

1. Introduction

The Raspberry Pi 5 features a dedicated 4-pin PWM fan header enabling automatic, temperature-based speed control via system configuration files. This method eliminates the need for complex scripting, utilizing simple configuration to intelligently modulate fan RPM according to CPU temperature. This approach ensures optimal thermal management while minimizing unnecessary acoustic noise and power consumption.

This tutorial details the process of modifying the Raspberry Pi 5 config.txt configuration file to achieve variable fan speed control across different temperature thresholds.

2. Operational Procedure

2.1 Preparation

Verify the correct connection of the 4-pin PWM fan to the Raspberry Pi 5. The fan header is located adjacent to the GPIO pins and designated with a FAN silkscreen label. Ensure the Raspberry Pi is connected to a network, fully booted, and accessible via a remote connection protocol such as SSH or MobaXterm. This tutorial utilizes MobaXterm as the primary operational example.

2.2 Editing the Configuration File

Launch a terminal session and execute the following command to edit the config.txt file:

sudo nano /boot/firmware/config.txt

Scroll to the bottom of the file and append the fan control configuration. As an example, the following configuration initiates the fan at 25°C with a speed value of 150, increases the speed to 200 at 30°C, and maximizes the speed to 255 at 40°C:

# Fan temperature-speed control configuration

dtoverlay=gpio-fan,gpiopin=18

dtparam=fan_temp0=25000 # 25°C represented as 25000 millidegrees Celsius

dtparam=fan_temp0_speed=150 # The speed is set to 150 at 25°C, within the range of 0 to 255

dtparam=fan_temp0_hyst=1000 # A temperature hysteresis of 1°C triggers a speed reduction when the temperature drops below 24°C

dtparam=fan_temp1=30000 # 30°C

dtparam=fan_temp1_speed=200 # The speed is set to 200 at 30°C

dtparam=fan_temp2=40000 # 40°C

dtparam=fan_temp2_speed=255 # Full speed at 40°C where 255 is the maximum value

Press Ctrl+O to save the file and Ctrl+X to exit the text editor.

2.3 Rebooting the Raspberry Pi to Apply Configuration

Execute the following command in the terminal to reboot the Raspberry Pi:

sudo reboot

2.4 Verifying the Configuration

After rebooting, use the following command to check real-time CPU temperature changes:

watch -n 1 vcgencmd measure_temp

After the test is completed, press Ctrl + C to stop the stress test.

If necessary, utilize a stress testing utility to artificially elevate CPU temperatures and observe subsequent fan speed modulations:

# Install the stress testing utility if it is not already installed ensuring the Raspberry Pi 5 controller maintains an active network connection:

sudo apt install stress

# Initiate the stress test to force all four cores to operate at maximum load:

stress -c 4

3. Precautions

3.1 Parameter Range Specifications

  1. The unit for temperature parameters is millidegrees Celsius where 25000 equals 25°C.
  2. The rotational speed parameter ranges from 0 to 255, with 255 representing full-speed operation.
  3. Setting the temperature hysteresis parameter between 1000 and 2000 representing 1 to 2°C is recommended to prevent frequent fan start-stop cycling.

3.2 Hardware Compatibility

  1. Make sure to use a 4-pin PWM fan. A standard 2-pin fan does not support speed control.
  2. The fan must be correctly connected to the dedicated fan header on the Raspberry Pi 5 to avoid incorrect pin connections.

3.3 Configuration Modifications

  1. To adjust temperature or speed parameters, simply re-edit the config.txt file and perform a system reboot.
  2. A maximum of three temperature thresholds, defined as temp0, temp1, and temp2, can be configured and must be ordered from lowest to highest temperature.

3.4 Troubleshooting

  1. If the fan is not working, check whether the configuration is correct, especially the GPIO pin setting, which should be set to pin 18.
  2. If the fan runs continuously at maximum speed, the configuration may not be applied, or the fan might lack PWM speed control support.
  3. After modifying the configuration, the Raspberry Pi must be rebooted for the changes to take effect, as hot reload will not apply the configuration.
Light
Dark