Orange Pi PC: Fan on GPIO


1 1

Recommended Posts

Hi all,


I'm not very familiar with linux scripting especially for controlling GPIO on Orange Pi. So my question is: is it possible to connect a fan to a GPIO port that is activated when temperature goes above a given value? Does anyone have a script for that or can suggest how to get it done?

I have a plastic housing for the board and a fan attached to it that is constantly running. But for 95% of the time I don't have load on the pi and don't need the fan...



Thanks in advance

Link to post
Share on other sites

Donate and support the project!

First, make sure you know how to control your fan via GPIO: you will need either NPN or MOSFET transistor and a resistor (depending on transistor type), you can look here for example schematics:


The most simple script for your task will look like this:


# see script.fex and board schematics for GPIO mappings
# i.e.GPIO12 = PA07 = Pin 29 on 40-pin header
# "critical" temperature value, no hysteresis for simplicity

echo $GPIO > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio${GPIO}/direction

while true; do
  if [[ $(cat /sys/class/thermal/thermal_zone0/temp) -gt $TEMP ]]; then
    echo 1 > /sys/class/gpio/gpio${GPIO}/value
    echo 0 > /sys/class/gpio/gpio${GPIO}/value
  sleep 10

You will need to assign correct GPIO number and "critical" temperature value to make this work

Link to post
Share on other sites

Does anybody know if GPIO outputs are pull-upped or pull-downed by default? I mean - what is initial GPIO level (low/high)? What is initial state (out or in)? These answers are important for choosing transistor type (NPN/PNP or N-MOS/P-MOS).


if by default level is "high" - 3.3 V then NPN/N-MOS would be a choice (then related control application can switch off fan by setting "low"). If "low" - then PNP or P-MOS (related control application will switch off fan by setting "high"). The reason is that fan should be running even if related control program (application, shell script etc.) failed to run or was not started.

Link to post
Share on other sites

"Does anybody know if GPIO outputs are pull-upped or pull-downed by default?"


You should test !


MOST are not pulled up at boot, but my experience with RPI is that it depends on the PIN.


And if your system crash, I am not sure anyone can assure you that it cannot run at full speed without having started the fan. But these cards are not expensive ...


If you have important / high availibility (or expensive) systems, it could be interesting to use a 10$ card to monitor them, remote access them via serial port and/or "out of band" network, and power them on and off.

Link to post
Share on other sites

You can check my Orange PI PC Fan controller Project at

if that helps.


It includes circuits, guides and source code to control the fan also. 


I have also had PCB's manufactured for it to get it nicer, but I have not tested those yet, and wont post their blueprints until I have verified them for errors.


After I got the fan controller on it t hen Orange PC is a very fast and viable server. Compared to without fan when it was constantly going to turtle slow speed due to heat.

Link to post
Share on other sites

After I got the fan controller on it t hen Orange PC is a very fast and viable server. Compared to without fan when it was constantly going to turtle slow speed due to heat.


Just for the record: Using a fan with any H3 board is NOT NECESSARY when using Armbian!


You write on your site:

On the first machine we set up then machine seemed to be running Owncloud stable at 49 – 50 C on the CPU, but on 2nd day we noticed it going to 75 C and everything went very slow due to CPU core shut downs.


Shutting down cores is a clear sign that you used Xunlong's original THS settings back then (which are Allwinner's default and these are known to be bullshit, same with A83T and A64).


We improved THS settings a lot (stopping overvolting, defining intelligent throttling, cores shutting down only as a last resort) and all you need if you want to run heavy workloads with any H3 board is a cheap heatsink. No fan needed. Really.


Further readings:

TL;DR: Don't waste your time with fans and fan control with any H3 board, better use Armbian instead. Better settings increase performance and reduce temperatures/consumption.

Link to post
Share on other sites

I use Armbian and would never use anything else ! (I love Armbian)


But the performance for me was very poor as soon as the machine was under heavy load before adding fan controller.  And the nice thing about having fan controller is that it only turns on when its actually needed if setting its settings high enough.

Link to post
Share on other sites

But the performance for me was very poor as soon as the machine was under heavy load before adding fan controller.  And the nice thing about having fan controller is that it only turns on when its actually needed if setting its settings high enough.


Again: Using Armbian settings you don't need a fan. When we started supporting H3 boards in Armbian our first settings were already optimized since the settings used were bronco's from Orange Pi forums (bronco was my nickname there and I started to test/implement this stuff at the end of last year, due to a mistake we used even improved settings in Armbian then which further decreased temperatures).


We then fine tuned these settings, added a script to bring back killed CPU cores to cope with the rare cases where cores had to be killed which involved really heavy workloads and now we have this ability added to the kernel since Zador provided a kernel patch that brings back killed CPU cores.


So you're definitely talking about wrong settings and not Armbian's :)


Further readings:

TL;DR: Instead of wasting time with fans and their controllers better use a cheap heatsink, update your Armbian installation to latest settings (apt-get upgrade) and read through the links above. Thermal/performance problems are solved when using Armbian with Armbian settings. No need for fans any more!

Link to post
Share on other sites

I dont understand how it could be "wrong settings" and not Armbians. Its images from your website. With no settings changed.


I don't understand either. Really: cpuburn-a7 is the most heavy CPU bound workload known for H3 boards (way more heavy than stuff like sysbench or preview generation and so on) and we have numbers for that (using H3 boards with and without heatsink but allowing airflow around, I never cramped SBCs in tiny enclosures since it's known what then happens).


With Armbian everything's already installed to get a clue. Please do the following:

sudo systemctl stop pi-fan-controller
sudo armbianmonitor -r
stress -c 2 -t 120 && sysbench --test=cpu --cpu-max-prime=20000 run --num-threads=$(grep -c '^processor' /proc/cpuinfo)
sudo armbianmonitor -u

This will install RPi-Monitor, heats up the SoC a little, then run sysbench and provides debug info. Please provide sysbench result, a graph showing stress and sysbench execution (SoC temperature and CPU clockspeed are enough) and the support URL from 'armbianmonitor -u'. Some background information:

Link to post
Share on other sites

Hello to all
Now I'm doing my device based on Orange PC
It will be in the casing so it needs cooling.
I assembled a small fee for fan control
And he wrote a program for controlling and monitoring work
It can run as a daemon :)


To use I chose to 12V FAN 3PIN. To safely manage them with our Pi PC is necessary to collect the scheme in three transistors.
In the transistor Q3 will be lost that is 0.6V 5% of 12V. Therefore, the maximum speed of passport we can not achieve.
I have received the maximum at 2400 rpm of maximum 2500 passport.
Capacitor C1 pick up empirically, since of it will depend on the minimum threshold drawdown tachometer. As the tachometer now use Hall sensor.
For myself, I put 100uF, because with 50uF at a duty ratio of less than 50% control of the lost turnover.
To work it is necessary:
- Kernel with support for GPIO Support (sysfs interface)
- WiringOP from WereCatf

git clone -b h3
cd WiringOP
chmod +x ./build
sudo ./build

- Unpack the archive
- Define the value set that you need.
    Pina, minimum and maximum temperature, the number of Hall sensor pulses per revolution of the cooler, while the demon of the reaction, the minimum duty cycle.
- compile

g++ OPi-fan.c  -o OPi-fan  -lpthread -lwiringPi

- Copy of your directory in /usr/local/bin

cp ./OPi-fan /usr/local/bin

After that it can be used using various keys run.
The daemon reads the CPU temperature and basis of specified minimum and maximum temperature calculates the duty cycle of the PWM.
The software PWM. The same demon able to calculate RPM cooler. Data on the temperature, porosity and number of revolutions can be obtained from the console.
I tried more or less to describe the online help available on the key -h.
Legs please do not kick as programmer from me bad:D :D :D


Display in RPi-Monitor


Link to post
Share on other sites

Yes you need another power source.
But if you use the power supply via pin
You can put the StepUp power converter from 5V to 12V ;)

it is not difficult :D 


In my circuit you can use any voltage for the cooler. Just drop in the transistor is 0.6V.

When you use this cooler 5V -  12% loss.

When you use this cooler 12V -  5% loss.

The difference is visible!

The loss of voltage is the loss speed fan.


KT815 - transistor n-p-n structure

analogs BD135, BD137, BD139, TIP29A

Link to post
Share on other sites

Photos do not get it. My board in the project.

On the board, heatsink and the cooler was installed.

it seems it was a video playing at the moment. :)


I remember that when you start the test

sysbench --test=cpu --num-threads=4 run

CPU temperature was about 55°C-57°C.

I think it is high.

Maybe because of the fact that I am not good placed cooler during the test. And I have a bad heatsink -

What do you think?

Link to post
Share on other sites

What do you think?


I think that a fan controller is a nice thing to play with. But when you use Armbian with H3 devices there's really no need for a fan, since a quality heatsink is enough (you don't even a heatsink if you are able to accept that throttling will happen earlier, you only loose performance but that's it -- your H3 is always save). Please read through post #2 here:


Apart from that I've looked a lot into how consumption with H3 boards can be minimized the last weeks. Less consumption is also less temperatures. To me it seems absurd to add components that waste additional energy to only lower cosmetically the temperatures of other components especially since they're made for high temperatures. H3 is not an animal or a human being that gets hurt by temperatures exceeding 40°C. It's a chip rated for up to 125°C :)

Link to post
Share on other sites

Yes, I totally agree with you!

Armbian cares about saving CPU. It is very cool!!! :)

My project was written before I see ArmBian. I worked on the assembly release Loboris...


But there is a question - I understand that Armbian saves CPU. But they relate to high temperature components other boards? I think it is not good. Do you have information on this subject?

Or, I should not think about this?

Fan cooling whole board ;)

Link to post
Share on other sites

Or, I should not think about this?

Fan cooling whole board ;)


Well, many SBC use copper layers inside the PCB to spread heat away from some components (like eg the SoC). This means that Ethernet and USB jacks and SD card slot and so on get warm, sometimes even hot. And now people touch the surface of these components, are surprised and think: that feels to hot for me. But hey, these are electronic components. If we touch them and it feels warm then their temperature obviously exceeds 37°C, if it feels hot or even hurts then it's obviously a few degrees more.


I made some tests with NanoPI NEO the last days. SoC temperature reported as 80°C (so in reality maybe even 95°C -- that's still 30°C less than max temp by specs!) while being tortured with cpuminer for 48 hours. Whole board felt hot and touching the SoC was a little painful. But hey, look at 'commercial temperature range': that's up to 70°C and all the onboard components should have no problem to operate at these temperatures.


If I would fear such temperatures (which I do not) then I would try to allow airflow, add a good heatsink to the SoC to spread heat away more into the air than PCB and avoid tiny enclosures -- it's that easy. And never use a fan unless it's a large one that is totally silent (I have one of these rated for 12V but working with 5V too -- overkill for a single board but is able to cool down SBC clusters running at the highest clockspeed)


BTW: Since you mentioned loboris' settings. They're the perfect example how bad settings (dvfs table overvolting the SoC and containing only 2 bad entries) might not only lead to stability issues, raise temperatures and consumption but also decrease performance: post #9 here.


TL;DR: With Armbian running on H3 devices no fan is needed. If you want to run the board constantly under full load apply a good heatsink and allow some airflow.

Link to post
Share on other sites

I run some stress test and dodgy things in my Orange Pi One without cooling, with heat sink and finally heatsink with fan cooling the whole board all the time at full speed (not GPIO controlled or something like this). The performance not change a lot but with this configuration you have a stable 38º or 40º C. I live in Spain and summers can be real warm.

Link to post
Share on other sites

Today I made a cooling radiator for Orange Pi One.

I used a heat sink on the motherboard.

I used the thermal paste GD900 and a little glue. One drop at angles.






Now idle temperature of 26 °С

In load mode:

root@orangepione:~# sysbench --num-threads=4 --test=cpu --cpu-max-prime=20000 run

temperature of  42-43 °С

I think this is a great result !!!

Link to post
Share on other sites

This topic is now closed to further replies.

1 1