Commit 90eb586a authored by Tobias Rautenkranz's avatar Tobias Rautenkranz
Browse files

Add post raspberry pi fan control

parent ac52aec2
layout: post
title: Temperature Based Fan Control for the Raspberry Pi
lang: en
category: code
tags: code hardware
The fan (3010S DC 5V 0.20A) I use in the
[NESPi CASE]( with a
[Rapsberry Pi 3 Model B+](
is quite loud.
To reduce the noise, a system to switch the fan on/off based on demand was
![abstract]({{ "/img/raspberry-pi-fancontrol/installed.jpg" | relative_url }})
Several similar approaches have been implemented; e.g.:
[TheDrHax/rpi-fan-control]( and
[How to control a fan to cool the CPU of your RaspBerryPi - Edo Scalafiotti](
or lowerning the supply voltage to 3.3 V:
# Control Circuit
The fan has two wires: +5 V and ground.
It is controlled with a
[GPIO pin](
connected to a custom MOSFET circuit
supplying the fan. The used n-channel IRF3710 MOSFET requires a Gate Threshold
Voltage above the 3.3 V of the GPIO pin. Thus, a drive circuit similar to
[Fig 1. Inverting Driver](
was constructed (The pull down transistor _R6_ for the transistor base was
omitted). Parts were chosen by what I had lying around.
The completed circuit:
![circuit front]({{ "/img/raspberry-pi-fancontrol/circuit_front.jpg" | relative_url }})
[circuit back]({{ "/img/raspberry-pi-fancontrol/circuit_back.jpg" | relative_url }})
The inverting configuration results in the default state of the fan being on.
Which theoretically is safer with respect to high temperatures and also allows the
takeover of the software control after startup to be audibly confirmed.
## Installation
A hole was drilled in the support structure of a screw hole of the case. Using
a zip tie through the MOSFET heat sink the circuit was affixed to the case.
![installation of circuit]({{ "/img/raspberry-pi-fancontrol/on_case.jpg" | relative_url }})
The circuit is connected to the 2 pin fan connector on the case circuit board
and to GPIO pin 21 on the Rapsberry Pi with the green wire.
The fan is connected to the 2 pin header on the control circuit.
# Control Software
The software is a C++ program reading the CPU temperature from _/sys/_ and
using the [WiringPi]( library to control the fan with a
GPIO pin. When the on or off threshold temperature is reached, the fan is switched
on respectively off.
Due to the use of systemd for starting the program no special damonization code
is needed (see:
[New-Syle Daemons](
A _.service_ file for systemd is provided.
## Pulse Width Modulation
A try with Pulse Width Modulation (PWM) had no usable success; both with
Software and Hardware Modulation. While the fan
could be slowed somewhat (not to low percentages ~30%), the modulation increased
the noise. A dedicated PWM input on the fan (4 wire connector) would probably be
needed for a successful PWM.
Contrary success using Software PWM is noted by:
[soulgriever/FanGPIO]( and
[GPIO en C: Control automático de ventilador según temperatura - josrios](
## Source Code
The source code is at:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment