Brushless Fan (5v) for Rock64 Clear Case Soft PWM Drive 2N2222

In this photo blog I'm going to put it all together ( this Rock64 cased fan design has been a while in the design and organizing phases! ).

All of the scripts are included in this post to actually make the software pwm 5v brushless fan function. I have included updated schematic|block-diagram and have included instructions (tutorial style) for reproducing the experiments.


The concept is simple;  a script activates a gpio mux line ( cyclic ON|OFF ) which in turn drives the base of an NPN driver transistor;  the driver transistor handles the current for the 5v brushless fan -- turning the fan motor ON|OFF many times each minute with a duty-cycle which reduces the fan's current draw, and reduces the fan's noise, while still providing good air flow.  In addition, the script can be more complicated ( should you desire ) to speed or slow the fan motor based on the thermal condition in the sysfs !

Preparation and Electronics ( schematic | block-diagram )


The schematic|block-diagram above is a rework of my schematic from the PineA64+ forum of the same topic.  The concept is precisely the same;  the only differences are the language ( bash script vs python ) and the details of which pin controls the duty cycle and which pin(s) control the process.  ie., in this example the process is controlled via gpio pin, not signaling via the OS.

You may use either a PN2222, or a 2N2222 transistor.  Notice the transistor is placed in the black lead ( negative ) of the motor assembly ( pay attention to the emitter | collector designations on your transistor datasheet! ).

Don't forget the base biasing ( current limiting ) 1K ohm resistor;  a common mistake.


The pics above detail the finished prototype;  the only difference here between the prototype and the completed project is that the completed project will have internal wiring ( including the transistor heatsink, cable, and biasing resistor ).

There are several things to notice in the pic top left;  my fan projects ( active SBC cooling ) all use heatsinks on the driver transistor.  This keeps the cost low, while still improving the life of the transistor.  Commercial ones are available, but I made this one from inexpensive brushed aluminum from a jewelry hobby store.

Notice the hole in the top cover over the SoC heatsink.  The inductor blower fan evacuates the case hundreds of times per minute, and the entry point for that airflow is directly over the heatsink fins.  To accomplish this the other openings in the case need to be minimized ( note the temporary gpio cover , taped index card with hole punches ).
The fan is mounted on the bottom of the case which is not only more aesthetic (IMHO) but its also quieter when placed there ( from experience! ). The finished project will deviate from this prototype by adding a foam-slit cover for the gpio(s) and by adding a lite surgical gauze filter for the airflow entry point;  this also helps to keep the board and the fan blades clean and quiet.

Please note the green loop of wire on the gpio PI-2 bus;  this wire runs from gpio89 to gpio83, and is used to signal the control loop when to break.  gpio89 is held high;  when gpio89 pulls gpio83 low, the control loop breaks and the script exits ( of course the fan motor then stops spinning ).


The induction blower fan is seen in this pic (above) mounted on the bottom case of the Rock64 clear shipping case.  Again, the final will have internal wiring.  The fan blades are quite powerful even at lower soft-pwm speeds. The induction blower assembly evacuates the case air exhausting it out across the bottom under the case ( virtually silently ).

This required a considerable amount of dremel work ( don't forget eye protection and filter mask while breathing ).

I mounted the blower assembly with two small machine screws ( M2 ) cut to proper length with a dremel cutter wheel.  The holes in the bottom case are just a tiny bit smaller than 2mm, so that the threads of the M2 metric screws bite into the plastic housing without any other hardware ( like washers, nuts, etc ).

It took four weeks to get these Gdt fans from Shenzhen, so order early !

Wrap-up , Health Monitor,  and Scripts (codes)


The pic above shows the prototype ( lower right foreground );  note the fan assembly position -- it is important to have the mounting 'feet' (M3 stilts) long enough that the fan assembly clears the table top;  otherwise, the noise from the fan will be transmitted to the table ( not good ).  The final project will have little rubber footies on the M3 bolt tops which will further reduce what little noisy vibration might be left over.

On the Samsung display ( background ) you will notice some readouts. My idle temps with this setup ( 1200 Mhz ) are in the mid 30 ℃ , and even loaded most times the temps are in the high 30 ℃ to low 40 ℃.

Below I'm listing the three scripts that I use to control this fan motor. is used to export and setup all of my gpio(s) to user space.  This script is generic and does the setup for ALL of my projects.  In other words, I only setup pins once after I log on;  each subsequent script ( including ) relies on the  Also, the script MUST be run BEFORE running the script. pulls gpio30 low and then releases it-- setting gpio89 HIGH.  gpio89 MUST be HIGH  or the script will not run more than one cycle!  Finally , is where the software pwm magic happens.  

Note:  a jumper wire MUST run from gpio89 to gpio83 !  Failure to do this will cause loss of control over your fan motor.

Here are the scripts, followed by usage :

echo 83 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio83/direction
echo 82 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio82/direction
echo 100 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio100/direction
echo 101 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio101/direction
echo 102 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio102/direction
echo 103 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio103/direction
echo 88 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio88/direction
echo 89 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio89/direction

Don't forget to make the script executable with :   chmod  0754

Run the script as root:

       sudo  -i

echo 0 > /sys/class/gpio/gpio89/value
sleep 1.25
echo 1 > /sys/class/gpio/gpio89/value

Run the above script with :

Its important that this script is run AFTER the, and BEFORE the !  gpio89 must be held HIGH or the script will not start !

#        sudo ./ pwm_pin# ctrl_pin# time_ON time_OFF &

while [ `cat /sys/class/gpio/gpio$2/value` -gt 0 ]; do
  echo 1 > /sys/class/gpio/gpio$1/value
  sleep $3
  echo 0 > /sys/class/gpio/gpio$1/value
  sleep $4
echo 0 > /sys/class/gpio/gpio$1/value

The script is generic in the sense that all of its critical values are passed in as parameters.  It basically sets up a controlled forever loop that activates the soft pwm gpio line ON|OFF until the control pin is pulled low-- does that job.

Run as root in the background with :

       sudo  -i  82  83  .088  .022  &

Just a quick note about the pins:   

       gpio82  is  Pi P5+ bus  GPIO2_C2   pin(4)
       gpio83  is  Pi P5+ bus  GPIO2_C3   pin(6)
       gpio89  is  Pi P5+ bus  GPIO2_D1   pin(21)

The fan motor and transistor assembly plugs into the PI-2 bus pin(4  +5v) and pin(6  gnd).

marcushh777    Cool

please join us for a chat @   or ssl

( I regret that I am not able to respond to personal messages;  let's meet on irc! )

Messages In This Thread
RE: Brushless Fan (5v) for Rock64 Clear Case Soft PWM Drive 2N2222 - by MarkHaysHarris777 - 08-31-2017, 02:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to enable ES9023-based DAC hat on Rock64? lowry 2 187 03-18-2021, 03:44 PM
Last Post: zborgerd
  1wire DS18b20 on Rock64? mypineme 3 1,137 02-10-2021, 11:21 AM
Last Post: TRS-80
Heart Best quick/easy way to control case fan speed? idillicah 1 794 12-15-2020, 04:57 PM
Last Post: kidfrostbite
  Display options for the Rock64 joey49 1 676 11-23-2020, 09:52 AM
Last Post: joey49
  Are HW design files available for ROCK64? irenek 1 1,030 09-29-2020, 05:57 PM
Last Post: tllim
  No sound from Rock64 DAC codebreaker 2 973 09-29-2020, 02:14 PM
Last Post: codebreaker
  Which Voltage and Amper to supply both Rock64 + External drive enclosure ? prog-amateur 0 933 08-21-2020, 09:16 PM
Last Post: prog-amateur
  Assembling the premium aluminum case mlefevre 7 3,966 07-09-2020, 05:30 AM
Last Post: flyingscorpio
Information Rock64 RTL8188EU Wifi Adapter from Pine Store Tested Well MarkHaysHarris777 7 4,575 05-13-2020, 06:00 PM
Last Post: Leon Rembowski
  accident got 12v at my rock64 lifeform 1 1,206 04-17-2020, 09:46 AM
Last Post: fire219

Forum Jump:

Users browsing this thread: 1 Guest(s)