{"id":445,"date":"2016-05-28T21:40:27","date_gmt":"2016-05-28T21:40:27","guid":{"rendered":"https:\/\/einhugur.com\/blog\/?page_id=445"},"modified":"2016-09-11T13:57:30","modified_gmt":"2016-09-11T13:57:30","slug":"build-fan-controller-for-orange-pi-pc","status":"publish","type":"page","link":"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/","title":{"rendered":"Build fan controller for Orange PI PC"},"content":{"rendered":"<h2>In this example we are going build fan controller for Orange PI PC.<\/h2>\n<p><em>By: Bj\u00f6rn Eir\u00edksson and H\u00f6r\u00f0ur Kristj\u00e1nsson.<\/em><\/p>\n<p><strong>Disclaimer:<\/strong><br \/>\nWe do not take any responsibility for possible errors in the guide or errors that you might do wiring it up. Incorrect wiring can result in damaged sensor or damaged Raspberry PI.<\/p>\n<p><strong>The project:<\/strong><br \/>\nThis started out as project where me and a guy name H\u00f6r\u00f0ur Kristj\u00e1nson (he is a great developer) were building Owncloud servers from cheap Orange PI PC machines. This guide will not handle installing or setting up the Owncloud, but more of dealing with heat problems that we encountered.<\/p>\n<p>On the first machine we set up then machine seemed to be running Owncloud stable at 49 &#8211; 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. Reason for the spike is known, generation of Previews on images was turned on. Even if turning that feature off which we did then there will always come peek times where the CPU needs to\u00a0be able to take load. This guide also applies for other Orange PI projects, basically if you are doing something that needs CPU load then the CPU on Orange PI will heat up really fast. Of course we already had heat sinks on the CPU and memory chips so it was clear that fans would be needed to ensure stability and performance.<\/p>\n<p><strong>Fans are loud!<br \/>\n<\/strong>Loud fans was not exactly something that we were prepared to swallow as those servers are being built as home servers where they need to be quiet. So after some thinking and discussion then this plan was made:<\/p>\n<p><em><strong>1.<\/strong> GPIO controlled fan. (We will be taking 3 GPIO pins for this though a slightly more complex\u00a0circuiut can do 3 speeds with just 2 GPIO pins)<br \/>\n<strong>2.<\/strong> C++\u00a0daemon\u00a0would be written that reads the CPU temp and turns on the fan, Slow at 60 C, faster at 65 C and full speed at 70 C.<br \/>\n<strong>3.<\/strong> Cut hole in the top of the boxes for the fan, and 3D print fan brackets that will also store the fan controller circuit. (We do not have the same Orange PI PC cases so we will try to make our fan bracket generic so it can work on both cases)<\/em><\/p>\n<p>So in short if the plan works then the<strong> Fan is supposed to be silent 99% of the time<\/strong>.<\/p>\n<hr \/>\n<p><strong>The circuit:<br \/>\n<\/strong>This is the circuit we came up with:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/04\/FanControllerCircuitScheme.png?ssl=1\"><img data-attachment-id=\"488\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/fancontrollercircuitscheme\/\" data-orig-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/04\/FanControllerCircuitScheme.png?fit=633%2C654&amp;ssl=1\" data-orig-size=\"633,654\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"FanControllerCircuitScheme\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/04\/FanControllerCircuitScheme.png?fit=290%2C300&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/04\/FanControllerCircuitScheme.png?fit=474%2C490&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-full wp-image-488\" src=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/04\/FanControllerCircuitScheme.png?resize=474%2C490&#038;ssl=1\" alt=\"FanControllerCircuitScheme\" width=\"474\" height=\"490\" srcset=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/04\/FanControllerCircuitScheme.png?w=633&amp;ssl=1 633w, https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/04\/FanControllerCircuitScheme.png?resize=290%2C300&amp;ssl=1 290w\" sizes=\"(max-width: 474px) 100vw, 474px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<hr \/>\n<p><strong>Selecting the components:<br \/>\n<\/strong>When looking for fans that are 5V and suitable for the task then it soon was clear that fan would take from about 145 mA to 200 mA.<\/p>\n<p>In the end we took <strong>5V fan, that takes 200 mA and is 5 x 5 cm<\/strong>.<\/p>\n<p>We thought we would be using resistors for R4 and R5 with higher values so were concerned about the wattage on them but the fan does not run at lower voltage than 3,6 V at all. So doing the math on R4 and R5:<\/p>\n<p style=\"padding-left: 30px;\">R4 and R5 values were selected based on what gave good speeds on the fan in actual tests, 8.2 Ohm drops the voltage on the fan to about 3,6 V (measured with multimeter) Then to verify the wattage for them:<\/p>\n<blockquote>\n<p style=\"padding-left: 30px;\">Original fan voltage: 5V<\/p>\n<p style=\"padding-left: 30px;\">Original fan current: 0.2A<\/p>\n<p style=\"padding-left: 30px;\">V=IR (Ohm&#8217;s Law), so 5 = 0.2R \u00a0 =&gt; \u00a0 R = 5 \/ 0.2 \u00a0 = \u00a0 25<\/p>\n<p style=\"padding-left: 30px;\">Fan resistance: 25 <em>\u03a9<\/em><\/p>\n<p style=\"padding-left: 30px;\">Target voltage: 3.6V<\/p>\n<p style=\"padding-left: 30px;\">V=IR (Ohm&#8217;s Law), so 3.6 = 25I\u00a0\u00a0 =&gt;\u00a0\u00a0 I = 3.6 \/ 25 \u00a0 =\u00a0 0.144<\/p>\n<p style=\"padding-left: 30px;\">Target current: 0.144A<\/p>\n<p style=\"padding-left: 30px;\">Voltage drop across resistor: 5V &#8211; 3.6V\u00a0 =\u00a0 1.4V<\/p>\n<p style=\"padding-left: 30px;\">V=IR (Ohm&#8217;s Law), so 1.4 = 0.144R\u00a0\u00a0\u00a0 =&gt;\u00a0\u00a0\u00a0 R = 1.4 \/ 0.144 \u00a0\u00a0 =\u00a0 9.722<\/p>\n<p style=\"padding-left: 30px;\">Target resistance:\u00a0 9.722 <em>\u03a9<\/em><\/p>\n<p style=\"padding-left: 30px;\">Power dissipated by resistor:\u00a0 1.4V * 0.144A\u00a0 =\u00a0 0.202W<\/p>\n<\/blockquote>\n<p style=\"padding-left: 30px;\">The actual power dispatched is a little less than shown in the math above as\u00a0going through the transistor does not deliver 5V, <strong>So in the end 1\/4 W resistors were enough.<\/strong><\/p>\n<p>The hunt for transistor that would be able to take this amount of current and possible spikes started and we in the end decided on BC-337-25 (note the 25 variation) which is NPN transistor and has current rating of 0.8 A in the collector.<\/p>\n<p>For the current then we need to apply the following formula: I(B) = I(C) \/\u00a0\u03b2. \u00a0(The\u00a0\u03b2 will usually be marked as hfc in the transistors specs)\u00a0You google the spec for your transistor and find the Beta Value, it will have some range depending on current, it will be marked as On characteristics in the spec. Mine has the \u03b2 spec of 160 to 400 at 100 mA.\u00a0Since we are using 200 mA then we will choose\u00a0\u03b2 of 250.<br \/>\nWhich means I(B) will be: 0,2 \/ 250\u00a0=\u00a00,0008 A\u00a0(This is how little we will be taking from the GPIO pin)<\/p>\n<p>Now that we have the voltage and current then R1, R2 and R3 = 2,6 \/ 0,0008 A =\u00a03250\u00a0<em>\u03a9\u00a0<\/em><em>\u00a0<\/em><em>(2,6 since \u00a0base of the transistor wants 0.7 V)<\/em><\/p>\n<p><strong>Manual tweaking of the speed on the fan controller ended us then with 3,6k<em>\u03a9 on R1 and R3 and 4,7 k\u03a9 on R2.<\/em><\/strong><\/p>\n<hr \/>\n<p><strong>After tweaking and testing it on the breadboard for a while then it was time to put the circuit on final board:<\/strong><\/p>\n<p>Measured final values were:<\/p>\n<div class=\"table-responsive\"><table  style=\"width:500px; \"  class=\"easy-table easy-table-default \" >\n<caption>Measured voltage on the fan<\/caption>\n<thead>\r\n<tr><th  style=\"text-align:left\" >Pins active<\/th>\n<th  style=\"text-align:right\" > Voltage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\r\n<tr><td  style=\"text-align:left\" >No pin<\/td>\n<td  style=\"text-align:right\" >0 V<\/td>\n<\/tr>\n\r\n<tr><td  style=\"text-align:left\" >1<\/td>\n<td  style=\"text-align:right\" >3,64 V<\/td>\n<\/tr>\n\r\n<tr><td  style=\"text-align:left\" >2<\/td>\n<td  style=\"text-align:right\" >3,79 V<\/td>\n<\/tr>\n\r\n<tr><td  style=\"text-align:left\" >1 and 3<\/td>\n<td  style=\"text-align:right\" >3,89 V<\/td>\n<\/tr>\n\r\n<tr><td  style=\"text-align:left\" >1 and 2<\/td>\n<td  style=\"text-align:right\" >4\u0010,34 V<\/td>\n<\/tr>\n\r\n<tr><td  style=\"text-align:left\" >1,2 and 3<\/td>\n<td  style=\"text-align:right\" >4,56 V<\/td>\n<\/tr>\n<\/tbody><\/table><\/div>\n<p>The daemon will then be using those pin combinations to control the speed of the fan.<\/p>\n<figure id=\"attachment_496\" aria-describedby=\"caption-attachment-496\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/SolderedBoard.png?ssl=1\"><img data-attachment-id=\"496\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/solderedboard\/\" data-orig-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/SolderedBoard.png?fit=600%2C308&amp;ssl=1\" data-orig-size=\"600,308\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Fan controller soldered\" data-image-description=\"\" data-medium-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/SolderedBoard.png?fit=300%2C154&amp;ssl=1\" data-large-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/SolderedBoard.png?fit=474%2C243&amp;ssl=1\" loading=\"lazy\" class=\"size-full wp-image-496\" src=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/SolderedBoard.png?resize=474%2C243&#038;ssl=1\" alt=\"Fan controller soldered\" width=\"474\" height=\"243\" srcset=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/SolderedBoard.png?w=600&amp;ssl=1 600w, https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/SolderedBoard.png?resize=300%2C154&amp;ssl=1 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" data-recalc-dims=\"1\" \/><\/a><figcaption id=\"caption-attachment-496\" class=\"wp-caption-text\">Fan controller soldered<\/figcaption><\/figure>\n<p>We squeezed it a bit n the board to not let it take a lot of space once it would be put in the Orange PI PC machine.<\/p>\n<p>(See further down in the article how we printed a case for the controller and the fan to\u00a0mount on top of the Orange PI PC)<\/p>\n<p>Pins on the soldered board above are:<\/p>\n<p><em>V: Pin 1<\/em><br \/>\n<em>U: Pin 2<\/em><br \/>\n<em>T: \u00a0Pin 3<\/em><br \/>\n<em>Z: 5V<\/em><br \/>\n<em>1: GND (bottom right)<\/em><br \/>\n<em>5: Fan output GND<\/em><br \/>\n<em>6: Fan output VCC \u00a0(top right)<br \/>\n<\/em><\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<p><strong>&lt;&lt; Putting it all together:<\/strong><\/p>\n<p><strong>Making the daemon:<\/strong><\/p>\n<p>In order to control the fan automatically based on cpu temperature we had to make it run in the background. This meant creating a daemon, something that neither of us had any experience doing.<\/p>\n<p>We ended up writing a pretty basic c++ daemon that performs the following tasks:<\/p>\n<ul>\n<li>Monitors cpu temperature on a set interval<\/li>\n<li>Depending on the current cpu temperature the fan speed is set<\/li>\n<li>When the cpu temperature drops below the lowest temperature level, the fan keeps spinning for a set amount of time to keep cooling the cpu. This is done to prevent the fan from stopping for a short while and the spin right back up again.<\/li>\n<\/ul>\n<p>Another feature we wanted to add was to make it configurable. To this end we added some arguments so that you can configure the daemon settings on startup. The available parameters are:<\/p>\n<ul>\n<li>Setting the temperature levels. You can override the 5 temperature levels individually.<\/li>\n<li>Set the cpu temperature check interval. This controls how aggresively the daemon checks the cpu temperature.<\/li>\n<li>Set the fan shutdown time. This controls for how long the daemon waits until the fan is completely shut down after the temperature drops below the lowest temperature threshold.<\/li>\n<li>Set a flag con indicate wether this is an upstart daemon that forks or not. We&#8217;re not sure if forking is needed \u00a0but the tutorials used that so we decided not to change it up too much.<\/li>\n<\/ul>\n<p>The final code for the daemon can be seen below:<\/p>\n<pre lang=\"cpp\">\/\/ A simple daemon that monitors CPU temperature and controls a 5v fan\r\n\/\/ Based on code from http:\/\/shahmirj.com\/blog\/beginners-guide-to-creating-a-daemon-in-linux\r\n\r\n#include &lt;sys\/types.h&gt;\r\n#include &lt;sys\/stat.h&gt;\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nusing namespace std;\r\nusing namespace chrono;\r\n\r\n#define DAEMON_NAME \"pi-fan-controller\"\r\n\r\n\/\/ Fan state\r\n#define FAN_STOPPED 0\r\n#define FAN_STOPPING 1 \r\n#define FAN_SPEED_1 2\r\n#define FAN_SPEED_2 3\r\n#define FAN_SPEED_3 4\r\n#define FAN_SPEED_4 5\r\n#define FAN_SPEED_5 6\r\n\r\nchar* message;\r\n\r\n\/\/ GPIO pins to use\r\n\/\/ Current implementation uses BCM numbers\r\nint _pin1 = 2;\r\nint _pin2 = 3;\r\nint _pin3 = 4;\r\n\r\n\/\/ Temperature thresholds\r\nint _temp1 = 55;\r\nint _temp2 = 60;\r\nint _temp3 = 65;\r\nint _temp4 = 70;\r\nint _temp5 = 75;\r\n\r\n\/\/ How often (in seconds) to check for cpu temp\r\nint _checkInterval = 5;\r\n\r\nint _logLevel = LOG_NOTICE;\r\n\r\nint _stopWaitTime = 120;\r\nsteady_clock::time_point _stopWaitTimeStart;\r\n\r\nint _currentState = FAN_STOPPED;\r\n\r\n\/\/ Indicates wether this program should only stop the fans. This needs to be set with the -stopfan flag\r\n\/\/ at startup which will stop the fan based on the given GPIO pin numbers\r\nbool _stopFanOnly = false;\r\n\r\n\/\/ Initializes the daemon settings based on the startup parameters given\r\nvoid init(int argc, char *argv[])\r\n{\r\n    for(int i = 1; i &lt; argc; i++) { if(i + 1 != argc) { \/\/ GPIO pins if(std::string(argv[i]) == \"-p1\") { _pin1 = atoi(argv[i + 1]); } else if (std::string(argv[i]) == \"-p2\") { _pin2 = atoi(argv[i + 1]); } else if (std::string(argv[i]) == \"-p3\") { _pin3 = atoi(argv[i +1]); } \/\/ Interval else if (std::string(argv[i]) == \"-i\") { _checkInterval = atoi(argv[i + 1]); } \/\/ Temperature thresholds else if (std::string(argv[i]) == \"-t1\") { _temp1 = atoi(argv[i + 1]); } else if (std::string(argv[i]) == \"-t2\") { _temp2 = atoi(argv[i + 1]); } else if (std::string(argv[i]) == \"-t3\") { _temp3 = atoi(argv[i + 1]); } else if (std::string(argv[i]) == \"-t4\") { _temp4 = atoi(argv[i + 1]); } else if (std::string(argv[i]) == \"-t5\") { _temp5 = atoi(argv[i + 1]); } else if (std::string(argv[i]) == \"-st\") { _stopWaitTime = atoi(argv[i + 1]); } else if (std::string(argv[i]) == \"-stopfan\") { _stopFanOnly = true; } else if (std::string(argv[i]) == \"-l\") { int logLevel = atoi(argv[i + 1]); if(logLevel &gt;= 0 &amp;&amp; logLevel &lt;= 7)\r\n                {\r\n                    _logLevel = logLevel;                \r\n                }\r\n                else\r\n                {\r\n                    _logLevel = LOG_NOTICE;\r\n                }\r\n            }\r\n        }\r\n    }    \r\n}\r\n\r\n\/\/ Toggles pin state based on the given state\r\nvoid togglePinState(int state)\r\n{\r\n    switch(state)\r\n    {\r\n        case FAN_STOPPED :\r\n            syslog (LOG_INFO, (\"Stoppin fan...\"));\r\n            digitalWrite(_pin1, LOW);\r\n            digitalWrite(_pin2, LOW);\r\n            digitalWrite(_pin3, LOW);        \r\n            break;\r\n\r\n        case FAN_SPEED_1 :\r\n            syslog (LOG_INFO, (\"Setting fan to speed 1...\"));\r\n            digitalWrite(_pin1, HIGH);\r\n            digitalWrite(_pin2, LOW);\r\n            digitalWrite(_pin3, LOW);\r\n            break;\r\n        \r\n        case FAN_SPEED_2 :\r\n            syslog (LOG_INFO, (\"Setting fan to speed 2...\"));\r\n            digitalWrite(_pin1, LOW);\r\n            digitalWrite(_pin2, HIGH);\r\n            digitalWrite(_pin3, LOW);\r\n            break;\r\n            \r\n        case FAN_SPEED_3 :\r\n            syslog (LOG_INFO, (\"Setting fan to speed 3...\"));\r\n            digitalWrite(_pin1, HIGH);\r\n            digitalWrite(_pin2, LOW);\r\n            digitalWrite(_pin3, HIGH);\r\n            break;\r\n        \r\n        case FAN_SPEED_4 :\r\n            syslog (LOG_INFO, (\"Setting fan to speed 4...\"));\r\n            digitalWrite(_pin1, HIGH);\r\n            digitalWrite(_pin2, HIGH);\r\n            digitalWrite(_pin3, LOW);\r\n            break;\r\n            \r\n        case FAN_SPEED_5 :\r\n            syslog (LOG_INFO, (\"Setting fan to speed 5...\"));\r\n            digitalWrite(_pin1, HIGH);\r\n            digitalWrite(_pin2, HIGH);\r\n            digitalWrite(_pin3, HIGH);\r\n            break;\r\n    }\r\n}\r\n\r\n\/\/ Executes a console command and returns the value\r\nstd::string exec(const char* cmd)\r\n{\r\n    std::shared_ptr pipe(popen(cmd, \"r\"), pclose);\r\n    if (!pipe)\r\n    {\r\n        return \"ERROR\";\r\n    }\r\n\r\n    char buffer[128];\r\n    std::string result = \"\";\r\n\r\n    while (!feof(pipe.get()))\r\n    {\r\n        if (fgets(buffer, 128, pipe.get()) != NULL)\r\n        {\r\n            result += buffer;\r\n        }\r\n    }\r\n    return result;\r\n}\r\n\r\n\/\/\r\nvoid process()\r\n{\r\n\r\n    syslog (LOG_DEBUG, (\"CPU temp: \" + exec(\"cat \/sys\/class\/thermal\/thermal_zone0\/temp\")).c_str());\r\n\r\n    const char* tempString = exec(\"cat \/sys\/class\/thermal\/thermal_zone0\/temp\").c_str();\r\n    int curTemp = atoi(tempString);\r\n\r\n    int nextState = _currentState;\r\n\r\n    \/\/ Turn off the fan\r\n    if(curTemp &lt; _temp1) { \/\/ Check if we are about to enter the waiting period or if we can simply turn off the fan if(_currentState &gt; FAN_STOPPING)\r\n        {\r\n            nextState = FAN_STOPPING;\r\n            _stopWaitTimeStart = steady_clock::now();\r\n            \r\n            \/\/ Set the speed to the lowest setting while winding down\r\n            togglePinState(FAN_SPEED_1);\r\n        }\r\n        else if(_currentState == FAN_STOPPING)\r\n        {\r\n            \/\/ Check if the wait period has expired            \r\n            duration time_span = duration_cast&lt;duration&gt;(steady_clock::now() - _stopWaitTimeStart);\r\n            \r\n            if(time_span.count() &gt;= _stopWaitTime)\r\n            {\r\n                nextState = FAN_STOPPED;\r\n            }\r\n        }\r\n        else\r\n        {\r\n            nextState = FAN_STOPPED;\r\n        }\r\n    }\r\n    else if (curTemp &gt;= _temp1 &amp;&amp; curTemp &lt; _temp2) { nextState = FAN_SPEED_1; } else if (curTemp &gt;= _temp2 &amp;&amp; curTemp &lt; _temp3) { nextState = FAN_SPEED_2; } else if (curTemp &gt;= _temp3 &amp;&amp; curTemp &lt; _temp4) { nextState = FAN_SPEED_3; } else if (curTemp &gt;= _temp4 &amp;&amp; curTemp &lt; _temp5) { nextState = FAN_SPEED_4; } else if (curTemp &gt;= _temp5)\r\n    {\r\n        nextState = FAN_SPEED_5;\r\n    }\r\n\r\n    \/\/ State changed so we need to change the GPIO pin output\r\n    if (nextState != _currentState)\r\n    {\r\n        _currentState = nextState;\r\n        \r\n        \/\/ No need to toggle fan if we are still waiting\r\n        if(_currentState != FAN_STOPPING)\r\n        {\r\n            togglePinState(_currentState);\r\n        }\r\n    }\r\n}\r\n\r\nint main(int argc, char *argv[])\r\n{\r\n\r\n    init(argc, argv);\r\n\r\n    \/\/Set our Logging Mask and open the Log    \r\n    setlogmask(LOG_UPTO(_logLevel));\r\n    openlog(DAEMON_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER);\r\n    \r\n    syslog(LOG_INFO, _stopFanOnly ? \"Shutting down the fan only\" : \"Entering Daemon\");\r\n    \r\n    \/\/----------------\r\n    \/\/Main Process\r\n    \/\/----------------\r\n    \r\n    \/\/ Use BCM numbering\r\n    wiringPiSetupGpio();\r\n    pinMode(_pin1, OUTPUT);\r\n    pinMode(_pin2, OUTPUT);\r\n    pinMode(_pin3, OUTPUT);\r\n    \r\n    \/\/ This will shut down the fan\r\n    togglePinState(_currentState);\r\n\r\n    if (!_stopFanOnly)\r\n    {\r\n        while(true)\r\n        {\r\n            process();\r\n            sleep(_checkInterval);\r\n        }\r\n    }\r\n    \/\/Close the log\r\n    closelog ();\r\n}\r\n\r\n<\/pre>\n<p><strong>Daemonizing the executable:<\/strong><\/p>\n<p>Because we started writing the daemon for upstart (which was totally not the correct init system) we decided to have two versions: one for upstart and one for systemd. \u00a0In practice they are not that different and they can use the same compiled executable daemon.<\/p>\n<p>We&#8217;ll go over both versions but we&#8217;ll only examine the systemd version in detail since that is the default init system on the current version of Armbian.<\/p>\n<p><strong>Upstart version:<\/strong><\/p>\n<p>For upstart we need to deploy our config file to \/etc\/init and the executable to \/usr\/bin. The config file was simply called pi-fan-controller.conf .<\/p>\n<p><strong>Systemd version:<\/strong><\/p>\n<p>The executable was again copied to \/usr\/bin. The unit file goes to \/etc\/systemd\/system and the environment file to \/etc.<\/p>\n<p>The unit file(\/etc\/systemd\/system\/pi-fan-controller.service):<\/p>\n<pre lang=\"ini\">[Unit]\r\nDescription=pi fan controller daemon\r\n\r\n[Service]\r\nType=simple\r\nRestart=always\r\nEnvironmentFile=\/etc\/pi-fan-controller.env\r\nExecStart=\/usr\/bin\/pi-fan-controller -i $INTERVAL -p1 $PIN1 -p2 $PIN2 -p3 $PIN3 -l $LOGLEVEL -st $STOPWAITTIME -t1 $TEMP1 -t2 $TEMP2 -t3 $TEMP3 -t4 $TEMP4 -t5 $TEMP5\r\nExecStopPost=\/usr\/bin\/pi-fan-controller -stopfan -p1 $PIN1 -p2 $PIN2 -p3 $PIN3 -l $LOGLEVEL\r\n\r\n[Install]\r\nWantedBy=multi-user.target\r\n<\/pre>\n<p>The environment file(\/etc\/pi-fan-controller.env):<\/p>\n<pre lang=\"ini\"># Which GPIO pins to use in BCM numbers\r\nPIN1=2\r\nPIN2=3\r\nPIN3=4\r\n\r\n# Set the CPU temperature thresholds\r\nTEMP1=55\r\nTEMP2=60\r\nTEMP3=65\r\nTEMP4=70\r\nTEMP5=75\r\n\r\n# Set the interval in seconds to read the CPU temperature\r\nINTERVAL=5\r\n\r\n# Default log level is LOG_NOTICE\r\n# 0 Emergency\r\n# 1 Alert\r\n# 2 Critical\r\n# 3 Error\r\n# 4 Warning\r\n# 5 Notice\r\n# 6 Informational\r\n# 7 Debug\r\nLOGLEVEL=6\r\n\r\n# Set the time in seconds for the fan stopping grace period. This means that the controller will wait \r\n# for the defined amount of time until it completely stops the fan.\r\nSTOPWAITTIME=120\r\n<\/pre>\n<p>You&#8217;ll notice that all of the settings that you can control are in the environment file, so you can control the daemon completely from there.<\/p>\n<p><strong>Installation guide for the pi-fan-controller daemon<\/strong><\/p>\n<ol>\n<li>Install and compile the WiringOP library: \u00a0<a href=\"https:\/\/github.com\/zhaolei\/WiringOP\">https:\/\/github.com\/zhaolei\/WiringOP<\/a><\/li>\n<li>Clone the pi-fan-controller repo: <a href=\"https:\/\/github.com\/Hoddikr\/pi-fan-controller.git\">\u00a0https:\/\/github.com\/Hoddikr\/pi-fan-controller.git<\/a><\/li>\n<li>Navigate into the pi-fan-controller directory and run the following commands:<\/li>\n<\/ol>\n<ul>\n<li>make<\/li>\n<li>sudo make install.systemd<\/li>\n<li><strong>or<\/strong><\/li>\n<li>sudo make install.upstart\u00a0<strong>depending on your init system.<\/strong><\/li>\n<\/ul>\n<p><strong>Example:<\/strong><\/p>\n<blockquote>\n<div>git clone\u00a0<a href=\"https:\/\/github.com\/Hoddikr\/pi-fan-controller.git\">https:\/\/github.com\/Hoddikr\/pi-fan-controller.git<\/a><\/div>\n<div>cd pi-fan-controller<\/div>\n<div>make<\/div>\n<div>sudo make install.systemd<\/div>\n<\/blockquote>\n<p>Now you should have the daemon up and running. For more information on the install\/configure\/uninstall process check out the readme on the pi-fan-controller github page.<\/p>\n<hr \/>\n<p><strong>From start then it was clear that we would need to put the circuit somewhere, and mount the fan on top of the boxes, and 5 cm fan is big for those boxes.\u00a0<\/strong><\/p>\n<p>We did not have the same cases, I had 3D printed case which I am not happy with do to design flaws in its model. And H\u00f6r\u00f0ur had a transparent bought case. So we set up with making generic design that can be mounted on top of either case and most cases.<\/p>\n<p><a href=\"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView1.png?ssl=1\"><img data-attachment-id=\"498\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/3ddesignview1\/\" data-orig-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView1.png?fit=700%2C524&amp;ssl=1\" data-orig-size=\"700,524\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"3DDesignView1\" data-image-description=\"\" data-medium-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView1.png?fit=300%2C225&amp;ssl=1\" data-large-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView1.png?fit=474%2C355&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-full wp-image-498\" src=\"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView1.png?resize=474%2C355&#038;ssl=1\" alt=\"3DDesignView1\" width=\"474\" height=\"355\" srcset=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView1.png?w=700&amp;ssl=1 700w, https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView1.png?resize=300%2C225&amp;ssl=1 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>So fan goes on left, and circuit in the box side by the fan. We did not put holes for the fan since, it may vary from fan to fan and drilling dow into the Orange PI box will be needed anyhow, so drilling through the print at same time should not be issue.<\/p>\n<p>Also we did not draw hole\u00a0from the fan to the circuit box for the fan wire so support material when printing would not be needed, so small hole will need to be drilled there.<\/p>\n<p><a href=\"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView2.png?ssl=1\"><img data-attachment-id=\"499\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/3ddesignview2\/\" data-orig-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView2.png?fit=700%2C499&amp;ssl=1\" data-orig-size=\"700,499\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"3DDesignView2\" data-image-description=\"\" data-medium-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView2.png?fit=300%2C214&amp;ssl=1\" data-large-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView2.png?fit=474%2C338&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-full wp-image-499\" src=\"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView2.png?resize=474%2C338&#038;ssl=1\" alt=\"3DDesignView2\" width=\"474\" height=\"338\" srcset=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView2.png?w=700&amp;ssl=1 700w, https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/3DDesignView2.png?resize=300%2C214&amp;ssl=1 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>But there is a hole for wires to take from the circuit box down to the Orange PI GPIO header.<\/p>\n<p>After this was done then we had a number of problems when assembling the cases and neither the bought case nor the printed case were going to work.<\/p>\n<p>Keeping the 3D design for the fan and the circuit then we proceeded in changing the printed case.<\/p>\n<p>Base of the case before mod comes from <a href=\"http:\/\/www.thingiverse.com\/thing:1277840\">here.<\/a><\/p>\n<p>This piece bellow is from the original case linked above where we have cut out rectangular hole at top. This was \u00a0the top piece in the original case but will now be the middle piece.<\/p>\n<p><a href=\"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Middle.png?ssl=1\"><img data-attachment-id=\"558\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/orangepi_pc_middle\/\" data-orig-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Middle.png?fit=500%2C376&amp;ssl=1\" data-orig-size=\"500,376\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"OrangePI_PC_Middle\" data-image-description=\"\" data-medium-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Middle.png?fit=300%2C226&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Middle.png?fit=474%2C356&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-full wp-image-558\" src=\"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Middle.png?resize=474%2C356&#038;ssl=1\" alt=\"OrangePI_PC_Middle\" width=\"474\" height=\"356\" srcset=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Middle.png?w=500&amp;ssl=1 500w, https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Middle.png?resize=300%2C226&amp;ssl=1 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>And this piece here bellow will be the new top piece of the main case, then the fan mount and circuit box will be mounted on top of it.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Top.png?ssl=1\"><img data-attachment-id=\"560\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/orangepi_pc_top\/\" data-orig-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Top.png?fit=500%2C246&amp;ssl=1\" data-orig-size=\"500,246\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"OrangePI_PC_Top\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Top.png?fit=300%2C148&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Top.png?fit=474%2C233&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-full wp-image-560\" src=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Top.png?resize=474%2C233&#038;ssl=1\" alt=\"OrangePI_PC_Top\" width=\"474\" height=\"233\" srcset=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Top.png?w=500&amp;ssl=1 500w, https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/OrangePI_PC_Top.png?resize=300%2C148&amp;ssl=1 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Bottom piece of the case is the original bottom piece from the the Thingverse page <a href=\"http:\/\/www.thingiverse.com\/thing:1277840\">here<\/a>:<\/p>\n<p>Note that we had some issues with the original design which is still in our mods. 1. Some plastic around the USB ports needed to be sanded down to get perfect fit, and 2. screws\u00a0don&#8217;t get good grip. So what I do is I drill through the screw holes and put screws with nuts all the way through all the three pieces. And then just put rubber pad under the box. Its even more important to put screws with such nuts when the box is in 3 pieces than when it was in 2 parts like the original design.<\/p>\n<p>One more piece was needed, a fan grill which we used this design <a href=\"http:\/\/www.thingiverse.com\/thing:28942\">here from Thingverse<\/a>. (Note flip it upside down before printing it gives far better results)<\/p>\n<p>And here bellow is the final printed result, with Orange PI own cloud server, case in 3 pieces, then on top of it the fan controller system printed in 3 more pieces. Note that we did put plastic nuts under the fan in case if it goes loose and falls down into the machine. The screws in the circuit box are just body screws at top and also body screws under going from the top piece of the case and down under into the circuit box.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/FinalCase.jpg?ssl=1\"><img data-attachment-id=\"562\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/finalcase\/\" data-orig-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FinalCase.jpg?fit=600%2C462&amp;ssl=1\" data-orig-size=\"600,462\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;2.2&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;iPhone 6&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1462316486&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;4.15&quot;,&quot;iso&quot;:&quot;400&quot;,&quot;shutter_speed&quot;:&quot;0.058823529411765&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;1&quot;}\" data-image-title=\"FinalCase\" data-image-description=\"\" data-medium-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FinalCase.jpg?fit=300%2C231&amp;ssl=1\" data-large-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FinalCase.jpg?fit=474%2C365&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-full wp-image-562\" src=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/FinalCase.jpg?resize=474%2C365&#038;ssl=1\" alt=\"FinalCase\" width=\"474\" height=\"365\" srcset=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FinalCase.jpg?w=600&amp;ssl=1 600w, https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FinalCase.jpg?resize=300%2C231&amp;ssl=1 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>We made accurate drilling scheme to help do the drilling:<\/p>\n<p><a href=\"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/DrillingSceme.png?ssl=1\"><img data-attachment-id=\"564\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/drillingsceme\/\" data-orig-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/DrillingSceme.png?fit=148%2C255&amp;ssl=1\" data-orig-size=\"148,255\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"DrillingSceme\" data-image-description=\"\" data-medium-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/DrillingSceme.png?fit=148%2C255&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/DrillingSceme.png?fit=148%2C255&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-full wp-image-564\" src=\"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/DrillingSceme.png?resize=148%2C255&#038;ssl=1\" alt=\"DrillingSceme\" width=\"148\" height=\"255\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Use the SVG file bellow to print the drilling scheme. Do not open the SVG in web browser and trust that the sizes are correct. We used free application on the Mac called EazyDraw. That gave accurate print of the drilling scheme.<\/p>\n<h3>The files<strong>:<\/strong><\/h3>\n<p><a class=\"mb-button mb-style-glass mb-size-small mb-corners-default mb-text-style-default \" style=\"background-color: #2b7dc4;\" href=\"http:\/\/www.thingiverse.com\/thing:1277840\">\u00a0<i class=\"fa fa-download\"><\/i>\u00a0 Base design of the case (from Thingverse)<\/a><\/p>\n<p><a class=\"mb-button mb-style-glass mb-size-small mb-corners-default mb-text-style-default \" style=\"background-color: #2b7dc4;\" href=\"http:\/\/www.einhugur.com\/Downloads\/FanController3DFiles.zip\">\u00a0<i class=\"fa fa-download\"><\/i>\u00a0 Middle part of the case, top part of the case and fan controller circuit box as well as drilling scheme<\/a><\/p>\n<p><a class=\"mb-button mb-style-glass mb-size-small mb-corners-default mb-text-style-default \" style=\"background-color: #2b7dc4;\" href=\"http:\/\/www.thingiverse.com\/thing:28942\">\u00a0<i class=\"fa fa-download\"><\/i>\u00a0 3D design for the fan grill (from Thingverse)<\/a><\/p>\n<hr \/>\n<p><span style=\"color: #808080;\">Update 11. Sep .2016:<\/span><\/p>\n<p>We have been working on making much smaller circuit with surface mounted components. \u00a0A PCB design has been made as shown bellow.<\/p>\n<p><a href=\"https:\/\/i2.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/FanControllerFabricated.png?ssl=1\"><img data-attachment-id=\"739\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/fancontrollerfabricated\/\" data-orig-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FanControllerFabricated.png?fit=536%2C408&amp;ssl=1\" data-orig-size=\"536,408\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"FanControllerFabricated\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FanControllerFabricated.png?fit=300%2C228&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FanControllerFabricated.png?fit=474%2C361&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-full wp-image-739\" src=\"https:\/\/i2.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/FanControllerFabricated.png?resize=474%2C361&#038;ssl=1\" alt=\"FanControllerFabricated\" width=\"474\" height=\"361\" srcset=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FanControllerFabricated.png?w=536&amp;ssl=1 536w, https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FanControllerFabricated.png?resize=300%2C228&amp;ssl=1 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>It is not as expensive as you might think to have such PCB fabricated. For 10 such board then expected cost is $10, so only $1 per board, and then some tiny shipping cost.<\/p>\n<p>The board came like this:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/FCFabricated.jpg?ssl=1\"><img data-attachment-id=\"772\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/fcfabricated\/\" data-orig-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FCFabricated.jpg?fit=300%2C238&amp;ssl=1\" data-orig-size=\"300,238\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;2.2&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;iPhone 6&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1473599585&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;4.15&quot;,&quot;iso&quot;:&quot;125&quot;,&quot;shutter_speed&quot;:&quot;0.03030303030303&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;1&quot;}\" data-image-title=\"fcfabricated\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FCFabricated.jpg?fit=300%2C238&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FCFabricated.jpg?fit=300%2C238&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-full wp-image-772\" src=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/FCFabricated.jpg?resize=300%2C238&#038;ssl=1\" alt=\"fcfabricated\" width=\"300\" height=\"238\" data-recalc-dims=\"1\" \/><\/a> <a href=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/FCFabricatedBottom.jpg?ssl=1\"><img data-attachment-id=\"773\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/fcfabricatedbottom\/\" data-orig-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FCFabricatedBottom.jpg?fit=300%2C241&amp;ssl=1\" data-orig-size=\"300,241\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;2.2&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;iPhone 6&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1473599600&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;4.15&quot;,&quot;iso&quot;:&quot;125&quot;,&quot;shutter_speed&quot;:&quot;0.03030303030303&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;1&quot;}\" data-image-title=\"fcfabricatedbottom\" data-image-description=\"\" data-medium-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FCFabricatedBottom.jpg?fit=300%2C241&amp;ssl=1\" data-large-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FCFabricatedBottom.jpg?fit=300%2C241&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-full wp-image-773\" src=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/FCFabricatedBottom.jpg?resize=300%2C241&#038;ssl=1\" alt=\"fcfabricatedbottom\" width=\"300\" height=\"241\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>After soldering the board was like this:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/FCSoldered.jpg?ssl=1\"><img data-attachment-id=\"771\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/fcsoldered\/\" data-orig-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FCSoldered.jpg?fit=248%2C350&amp;ssl=1\" data-orig-size=\"248,350\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;2.2&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;iPhone 6&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1473600411&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;4.15&quot;,&quot;iso&quot;:&quot;125&quot;,&quot;shutter_speed&quot;:&quot;0.03030303030303&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;1&quot;}\" data-image-title=\"fcsoldered\" data-image-description=\"\" data-medium-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FCSoldered.jpg?fit=213%2C300&amp;ssl=1\" data-large-file=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FCSoldered.jpg?fit=248%2C350&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-full wp-image-771\" src=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/FCSoldered.jpg?resize=248%2C350&#038;ssl=1\" alt=\"fcsoldered\" width=\"248\" height=\"350\" srcset=\"https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FCSoldered.jpg?w=248&amp;ssl=1 248w, https:\/\/i1.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2016\/05\/FCSoldered.jpg?resize=213%2C300&amp;ssl=1 213w\" sizes=\"(max-width: 248px) 100vw, 248px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>The board is small and intended to place inside some of the cases. Its only 25,9 mm x 19,9 mm.<\/p>\n<p>Surface mount called for different transistor, and different transistor called for recalculating good values for all the resistors. So here is component list for use with this surface mount board:<\/p>\n<p><strong>Transistors:<\/strong>\u00a0BC818 NPN SOT-23 (3x)<br \/>\n<strong>Resistors:<\/strong> R3 and R5: 1k\u03a9 (SMD 1206) (1\/4 W) <span style=\"color: #999999;\">&#8211; Note that for those then SMD 0805 (1\/8 W) is all right too.\u00a0<\/span><br \/>\n<strong>Resistor R4:<\/strong> 1,5k\u03a9\u00a0\u00a0(SMD 1206) (1\/4 W) <span style=\"color: #999999;\">&#8211; Note that for this one\u00a0then SMD 0805 (1\/8 W) is all right too.<br \/>\n<span style=\"color: #000000;\"><strong>Resistor R2:<\/strong> 4,7\u03a9 (SMD 1206) (1\/4W). This one has to be SMD 1206 to have enough wattage.<br \/>\n<strong>Resistor R1:<\/strong> 1\u03a9 (SMD 1206) (1\/4W). This one has to be SMD 1206 to have enough wattage.<\/span><\/span><\/p>\n<p><strong>Pins are as follows:<\/strong><br \/>\nF-: Fan ground<br \/>\nF+: Fan +<br \/>\nVCC: 5V<br \/>\nGND: Ground<br \/>\n1: Control pin 1 (See up top in the article)<br \/>\n2: Control pin 2\u00a0(See up top in the article)<br \/>\n3: Control pin 3\u00a0(See up top in the article)<\/p>\n<p><a class=\"mb-button mb-style-glass mb-size-small mb-corners-default mb-text-style-default \" style=\"background-color: #2b7dc4;\" href=\"http:\/\/www.einhugur.com\/Downloads\/GPIO\/FCGerberExport.zip\">\u00a0<i class=\"fa fa-download\"><\/i>\u00a0 Gerber files to fabricate copy of the Fan Controller board<\/a><\/p>\n<p>The boards were fabricated at AllPCB, if you use the link bellow to sign up there then both you and Einhugur should get discount. (Which of course would help support our effort here)<\/p>\n<p><a href=\"http:\/\/www.allpcb.com\/setinvite.aspx?inviteid=17891\">All PCB<\/a><\/p>\n<hr \/>\n<p>If not wanting to use 3 GPIO pins then its perfectly valid to connect just pin 1 or just pin 2 and configure the daemon to use that pin as pin number 1 for speed step 1.<\/p>\n<hr \/>\n<p>That it for now, but\u00a0we are working on testing building it from much smaller surface mounted components where the idea is to see if we can fit it into normal Orange\u00a0PI box.<\/p>\n<p>Note that this guide will almost certainly work with all Orange PI machines and almost certainly will work with Raspberry PI as well. (of course the 3D models need to be changed depending on machine though)<\/p>\n<hr \/>\n<p><a href=\"http:\/\/s.click.aliexpress.com\/e\/3JmyzZR7Y\" target=\"_parent\"><img src=\"https:\/\/i2.wp.com\/g03.a.alicdn.com\/kf\/HTB1_wanJFXXXXc5aXXXq6xXFXXXK\/Multimetro-HoldPeak-HP-770D-Auto-Range-font-b-Digital-b-font-font-b-Multimeter-b-font.jpg_220x220.jpg?w=474\" data-recalc-dims=\"1\" \/><span style=\"display: block;\">AliExpress.com Product &#8211; HoldPeak HP-770D Multimeter<\/span><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this example we are going build fan controller for Orange PI PC. By: Bj\u00f6rn Eir\u00edksson and H\u00f6r\u00f0ur Kristj\u00e1nsson. Disclaimer: We do not take any responsibility for possible errors in the guide or errors that you might do wiring it up. Incorrect wiring can result in damaged sensor or damaged Raspberry PI. The project: This &hellip; <a href=\"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/build-fan-controller-for-orange-pi-pc\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Build fan controller for Orange PI PC<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":666,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"spay_email":""},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/Pd75nk-7b","jetpack-related-posts":[{"id":666,"url":"https:\/\/einhugur.net\/blog\/index.php\/big-projects\/","url_meta":{"origin":445,"position":0},"title":"Big projects","date":"May 28, 2016","format":false,"excerpt":"Bigger GPIO projects \u00a0Build Fan Controller for Orange PI PC. (New\u00a028. May 2016) \u00a0 AliExpress.com Product - 2016 New Raspberry Pi 3 Model B 1GB RAM Quad Core 1.2GHz 64bit CPU WiFi & Bluetooth Third Generation Raspberry Pi Free Shipping AliExpress.com Product - HoldPeak HP-770D Multimeter \u00a0","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":288,"url":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/connecting-max7219_led_matrix-with-spi-bus\/","url_meta":{"origin":445,"position":1},"title":"Connecting MAX7219_LED_MATRIX with SPI bus","date":"October 21, 2015","format":false,"excerpt":"In this example we going to connect a\u00a0MAX7219_LED_MATRIX and control it with the SPI bus on the Raspberry PI. 8. Nov 2015 Important !! When I was working on next step in this to daisy chain more than one on same bus then I measured some extreme power usage at\u2026","rel":"","context":"Similar post","img":{"alt_text":"MAX7219_LED_MATRIX","src":"https:\/\/i2.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/10\/MAX7219_LED_MATRIX-e1445384705632.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":137,"url":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/ir-infrared-obstacle-reflection-photoelectric-sensor\/","url_meta":{"origin":445,"position":2},"title":"IR Infrared Obstacle Reflection Photoelectric Sensor","date":"September 20, 2015","format":false,"excerpt":"In this example we are going to connect to infrared obstacle reflection photoelectric sensor motion detection sensor. I am not going to deny it, I find this sensor to be awful rubbish. Without reading the data you can hook it up and see it when the 2nd green lights goes\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/IRSensor-e1442754741492-225x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":108,"url":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/f85-vibration-sensor\/","url_meta":{"origin":445,"position":3},"title":"F85 Vibration sensor","date":"September 19, 2015","format":false,"excerpt":"In this example we are going to connect to\u00a0vibration sensor. This example is super easy after doing the infrared motion detection with the HC-SR501 in a previous example, since basically same code will work. I found this sensor to be excellent, it gives readings when I expect it to and\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/Sensor-connection-e1442664059628-225x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":113,"url":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/flame-sensor\/","url_meta":{"origin":445,"position":4},"title":"Flame sensor","date":"September 19, 2015","format":false,"excerpt":"In this example we are going to connect to flame\u00a0sensor. Programming for this sensor works on exactly the same principle as the\u00a0HC-SR501 infrared sensor and the F85 vibration sensor except the signal from this sensor comes inverted. As in it will send 1 when everything is all right and zero\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/FlameSensor-e1442681877884-225x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":128,"url":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/dht11-and-dht22-humidity-temperature-sensors-3-pin-version\/","url_meta":{"origin":445,"position":5},"title":"DHT11 and DHT22 humidity & temperature sensors (3 pin version)","date":"September 20, 2015","format":false,"excerpt":"In this example we are going to connect\u00a0to DHT11 and or DHT22 humidity & temperature sensor. This sensor reads both the humidity and temperature. (This guide was updated on 24. Oct 2015, greatly improving the DHT11 device driver code and added DHT22 device driver code and wiring pictures for the\u2026","rel":"","context":"Similar post","img":{"alt_text":"DHT22 sensor","src":"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/DHT22.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/pages\/445"}],"collection":[{"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=445"}],"version-history":[{"count":0,"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/pages\/445\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/pages\/666"}],"wp:attachment":[{"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}