-
Notifications
You must be signed in to change notification settings - Fork 0
/
how_to_control_fan_in_rpi.txt
69 lines (49 loc) · 1.34 KB
/
how_to_control_fan_in_rpi.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
1.Create the file /etc/rc.local
vim /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
echo "14" > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio14/direction
echo 0 > /sys/class/gpio/gpio14/value
2. Write a file named fancontrol under /home/ubuntu/bin folder
vim /home/ubuntu/bin/fancontrol
#!/bin/bash
#if temperature is over 65 degress Celcius (in centicelcius value) trigger the FAN
threshold=65000
while :
do
temp=$(< /sys/class/thermal/thermal_zone0/temp)
if [ "$temp" -gt "$threshold" ]; then
echo 1 > /sys/class/gpio/gpio14/value
else
echo 0 > /sys/class/gpio/gpio14/value
fi
sleep 10
done
3. Make "fancontrol" script executed via creating a systemd startup script.
vim /etc/systemd/system/fancontrol.service
[Unit]
Description=The fancontrol startup script
# After=network.target
# After=systemd-user-sessions.service
# After=network-online.target
[Service]
# User=spark
# Type=simple
# PIDFile=/run/my-service.pid
ExecStart=/home/ubuntu/bin/fancontrol start
# ExecReload=/home/transang/startup.sh reload
# ExecStop=/home/transang/startup.sh stop
# TimeoutSec=30
# Restart=on-failure
# RestartSec=30
# StartLimitInterval=350
# StartLimitBurst=10
[Install]
WantedBy=multi-user.target
sudo systemctl enable fancontrol
sudo systemctl start fancontrol
sudo systemctl status fancontrol
4. reboot rpi