bokumin.org

Github

Turn your case fan into a mini fan

This article is a translation of the following my article:

 

 

* Translated automatically by Google.
* Please note that some links or referenced content in this article may be in Japanese.
* Comments in the code are basically in Japanese.

 

by bokumin

 

How to Fan-speed control

 

Introduction

 

It’s been hot around my desk lately. I thought it would be a good idea to buy a small USB type fan, but I had an extra case fan that I had taken out of a case somewhere, so I’m using it as a simple electric fan.

 

 

Some case fans are quiet and have a strong airflow, but this fan was so noisy that I couldn’t work with it as soon as I plugged it in, so I decided to adjust the airflow.
This time, I will introduce how to adjust fan air volume on Linux.

 

Using the case fan as an electric fan is different from its original purpose. Case fans were originally designed for the purpose of air circulation and cooling within the PC case, and are not designed for direct cooling of the human body. You are solely responsible for any malfunctions or accidents caused by continuous use for long periods of time or use for different purposes.

 

Ambient environment

 

OS: ArchLinux
Motherboard: nct6776 chipset
Fan: Supports 4-pin PWM/3-pin DC fan

 

The whole motherboard looks like this.

 

 

This motherboard only had one 4-pin connector for the case fan, the rest were 3-pin. The 3-pin one has DC voltage control, so its accuracy is poor, and the control is usually limited to 7V to 12V, so this time I used the 4-pin one.

 

 

Adjustment method

 

This time I used hwmon, which is a standard Linux kernel feature.
First, let’s check which fan corresponds to the 4 pins mentioned earlier.

 

# sensorsをインストール
# Arch linuxの場合
$ sudo pacman -S lm_sensors

# センサー情報を表示
$ sensors
nct6776-isa-0290
Adapter: ISA adapter
Vcore:         808.00 mV (min =  +0.00 V, max =  +1.74 V)
in1:             1.83 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
AVCC:            3.33 V  (min =  +2.98 V, max =  +3.63 V)
+3.3V:           3.31 V  (min =  +2.98 V, max =  +3.63 V)
in4:            64.00 mV (min =  +0.00 V, max =  +0.00 V)  ALARM
in5:             1.73 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
in6:           800.00 mV (min =  +0.00 V, max =  +0.00 V)  ALARM
3VSB:            3.41 V  (min =  +2.98 V, max =  +3.63 V)
Vbat:            3.23 V  (min =  +2.70 V, max =  +3.63 V)
fan1:          1730 RPM  (min =    0 RPM)
fan2:          1591 RPM  (min =    0 RPM)
fan3:             0 RPM  (min =    0 RPM)
fan4:             0 RPM  (min =    0 RPM)
fan5:             0 RPM  (min =    0 RPM)

 

This case is an open frame one, so there is no other case fan attached. Therefore, either fan1 or fan2 will be the CPU fan and the other will be the case fan.
If you make random adjustments here, it may cause a problem when it is the CPU fan, so it is a good idea to remove the case fan and check which one is the case fan.

 

$ sensors
nct6776-isa-0290
Adapter: ISA adapter
Vcore:         920.00 mV (min =  +0.00 V, max =  +1.74 V)
in1:             1.83 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
AVCC:            3.31 V  (min =  +2.98 V, max =  +3.63 V)
+3.3V:           3.31 V  (min =  +2.98 V, max =  +3.63 V)
in4:            72.00 mV (min =  +0.00 V, max =  +0.00 V)  ALARM
in5:             1.73 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
in6:           800.00 mV (min =  +0.00 V, max =  +0.00 V)  ALARM
3VSB:            3.41 V  (min =  +2.98 V, max =  +3.63 V)
Vbat:            3.23 V  (min =  +2.70 V, max =  +3.63 V)
fan1:             0 RPM  (min =    0 RPM)
fan2:          1591 RPM  (min =    0 RPM)
fan3:             0 RPM  (min =    0 RPM)
fan4:             0 RPM  (min =    0 RPM)
fan5:             0 RPM  (min =    0 RPM)

 

When I removed the case fan and tried running it again, fan1 was 0 RPM, so this time I will control fan1.

 

# PWMファイルの一覧表示
ls /sys/class/hwmon/hwmon*/pwm*

# 必要なら
# 特定のhwmonデバイスの詳細確認
ls -la /sys/class/hwmon/hwmon2/

 

Generally, the Linux hwmon fan number and pwm number match.
Therefore,

 

fan1pwm1
fan2pwm2
fan3pwm3

 

There is a correspondence between fans and PWM channels with the same number.
* Taking exceptions into consideration, when adjusting the fan, it is important to make small adjustments and check each time with the sensors command, rather than suddenly stopping the fan.

This time, we confirmed that PWM1 corresponds to CHA_FAN1, so we will proceed from there.
First, change the control mode to manual.

 

sudo echo 1 | sudo tee /sys/class/hwmon/hwmon2/pwm1_enable

 

Next, let’s set the fan speed. In the case of PWM, it is possible to adjust between 0 and 255.

 

sudo echo 150 | sudo tee /sys/class/hwmon/hwmon2/pwm1

 

Once you have found a good balance between sound and wind by changing the numbers, you are done. I settled around 120.

 


If you want to automatically adjust from startup, we recommend doing the following. First, let’s create a shell script.

 

#シェルスクリプト作成
sudo vim /usr/local/bin/fan-control.sh

#!/bin/bash
echo 1 > /sys/class/hwmon/hwmon2/pwm1_enable
echo 128 > /sys/class/hwmon/hwmon2/pwm1

 

Next, grant execution permission.

 

sudo chmod +x /usr/local/bin/fan-control.sh

 

Let’s create a service file.

 

sudo vim /etc/systemd/system/fan-speed-control.service

[Unit]
Description=Fan Speed Control
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/fan-control.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

 

Enable the service.

 

sudo systemctl enable fan-speed-control.service

 

At the end

 

It’s much cooler now than when there was no wind. Personally, I don’t think it’s better to turn on the air conditioner in the first place, but if you’re interested, please give it a try.
*As mentioned in the beginning, case fans are not designed to cool the human body in the first place, so you need to be careful.
*If your fingers or objects touch the rotating part of the fan, it may cause injury or malfunction. Before use, please clean the area around your desk and install it carefully so that small items such as pens and cables do not come into contact with the fan. We recommend that you fix it in a safe position, especially when using it for a long time.

 

End