Raspberry Pi Home Server

This is a tutorial for a DIY home server using a Raspberry Pi; featuring automatic fan control, incremental backup, photo stream, self-diagnostics and more… The server described in this article is being used for hosting the current website.

As seen in the above picture, it is a Raspberry Pi 3 B+ connected to a pair of hard disks, one main and one backup HDD, 4 Terabytes each. The oversized cooling fan mounted on top is controlled over the Raspberry Pi’s GPIO pin and keeps the CPU temperature at a constant 50 °C.

The system is characterized by a very low power consumption of about 5 Watts when idling. It is a very stable system and can run for months or even years without a single reboot.

Except for the Raspberry and HDDs, the whole setup was built from components that had been laying around at home. Thus one can notice that this device had not been built with aesthetics, but with reliability in mind.

I hope that you find this page useful and will be happy the hear your feedback.


The server consists of the following hardware:

  • Rasberry Pi 3 B+ (ARMv8, 64 bit, 1.4 GHz, 1GB SDRAM)
  • Enclosure: official Raspberry Pi
  • Memory card: SandDisk Ultra 32 GB microSDHC
  • HDD: 2x Western Digital Elements WDBU6Y0040BBK-WESN 4 TB USB
  • Cooling Fan: Papst 8412 N/2GH, 8 cm, 12 V DC, 235 mA
  • Heat sink kit

Power Supply

The whole system is powered by two independent USB power cables. One of the cables is used for powering the two HDDs, while the other cable is used for powering the Raspberry Pi. It is worth to note that the Raspberry Pi’s on-board power supply provides enough current to power-up at most one single USB hard drive, however it is highly recommended not to do so as this would subject the Raspberry to occasional undervoltage.

The following figure shows the schematic of the custom USB cable that has been designed for powering the HDD from an external power supply. The micro-USB cables bundled with the HDDs have been modified by cutting the red wire and connecting the HDD side of it to the positive lead of external power supply while leaving the Raspberry side of it disconnected. The black wire has been been left uncut and connected to the negative lead of the power supply.

A high-quality USB power adapter with multiple ports, rated above 2.5 Amperes, is recommended for this application.

Depending on the load, the power consumption of the system ranges between 5 and 10 Watts.


The Raspberry Pi requires active cooling in order to maintain its CPU clock frequency of 1.4 GHz. Without any active cooling, the CPU would quickly throttle down to 1.2 GHz as soon as it is subjected to any noticeable load. The Raspberry Pi is cooled by an oversize 12 Volt fan that is powered by Pi’s 5 Volt power supply way below the fan’s nominal voltage. The fan’s relatively large diameter enables it to provide adequate cooling despite the relatively low RPM due to the undervoltage. The advantage of such a setup is that it results in a virtually silent cooling system. The fan is temperature-controlled via GPIO through a NPN transistor, the fan control system is described further down below.

 Mechanical Design

The enclosure of the Raspberry Pi is mounted on a piece of wood with the help of 4 stand-offs. Each of the two hard disks are secured via its own releasable cable tie fastened by a couple of screws to wooden base.

Pieces of the same kind of cable tie, cut and with holes drilled in it is used to secure the cooling fan on top of the Pi’s enclosure. The enclosure itself is left open from the top and the sides in order to allow for the air to flow. A piece of automotive electrical tape seals the gap between the enclosure and the fan.

The space underneath the Raspberry Pi that has been created by the stand-offs is used for stowing excess cables and the fan control circuit board.

The USB power cables are secured to the wooden base via a piece of cable tie held by two screws. This effectively relieves any excessive strain from the USB connectors.

The images below show the hardware setup from different perspectivees

Fan Control over GPIO

Fan control is achieved via one of the Raspberry Pi’s GPIO pins. The GPIO pins on the Raspberry can only supply 3.3 Volts and their output current is way too low to power the fan. In order to solve this issue, the GPIO signal drives the base of a NPN transistor which in turn switches the 5 V power supply and can provide enough current for running the fan.

The figure below shows the pinout of the 40 pin GPIO header on the Raspberry Pi 3 and similar models (source: www.elektronik-kompendium.de/sites/raspberry-pi/1907101.htm).

GPIO header pinout

For the sake of convenience, GPIO pin GPIO 14 (pin 8) and the adjacent ground (pin 6) and 5 V (pin 4) pins are used for connecting the fan control circuit. This way we can use one single 2.54 mm female pin header to connect to the 3 adjacent pins. Nevertheless, you may use any of the available GPIO and power pins for the same purpose.

The figure below shows the schematic of the fan control circuit. Please note that the GPIO pin GPIO 14 has a dual purpose and can also act as URAT TXO.

Fan control circuit diagram

In the above schematic, pin GP14 (GPIO 14) drives the base of the BC337 NPN transistor via a 10 Kiloohm current-limiting resistor. The transistor is configured in a common-emitter circuit, which means that the emitter (pin with the small arrow) is connected directly to the negative power supply, while the collector is connected to the negative pole of the fan DC motor. The positive pole of the fan motor is connected to the +5 V power supply.

The GPIO pin is controlled by the following shell script that can be configured to run as a Linux service. Please note that the GPIO initialisation part of the script must run as root. The below code is already integrated into the software package that can be downloaded further down below. A form of this code can be found under /opt/nastia-server/bin/fan.sh and /opt/nastia-server/sbin/init-gpio.sh.

You may change the value of the GPIO_PIN variable in the above script to match the GPIO pin in use. Upon startup, the script will initialize the GPIO pin and set its direction to out. Then it will enter an infinite loop where it will read the current CPU temperature, compare it to the THRESHOLD value and change the logic state of the GPIO pin depending on the result of the comparison. The script will then suspend itself via the sleep command for INTERVAL seconds.

A temperature threshold of 50 °C in combination with an interval of 5 seconds leads to a good compromise in keeping a steady CPU temperature without having the fan run too often.


The Raspberry Pi runs on a standard Raspbian Linux distribution. The “nastia-server” home server automation toolbox has been deployed on the Raspberry Pi. This software package has been purpose-built for the current application and provides a collection of automation tools for running a home server. For the most part, nastia-server consists of a series of Bash shell scripts that have been configured to run as Cron jobs or services.

The following functionalities are supported by the toolbox:

  • Media stream:
    • Automatically fetches your media files from the Dropbox Camera Uploads directory, or any other pre-defined directory, renames them according to the EXIF date and stores them into monthly sub-directories.
    • Detects and eliminates duplicate media files.
    • Checks image files for corruption.
  • Automated system backup:
    • Incremental backup of the storage hard-drive, mimicks the Apple Time Machine behavior.
    • Creates a backup copy of important configuration files.
    • Creates a backup image of the Raspberry Pi SD card to an external hard drive.
  • Dynamic DNS: communicates the server’s public IP address to the Dynamic DNS service.
  • System diagnostics: runs extensive system diagnostics every night and send an automated test report via email.
  • Fan control: controls the CPU cooling fan over the Raspberry Pi’s GPIO pin.

The nastia-server software package and the required installation instructions can be found on GitHub under the following address:


Last updated on March 21st, 2019

Leave a Reply

Your email address will not be published. Required fields are marked with an *.