Temperature control with PID on Arduino and PWM fans for DIY server/network rack cooling

A few weeks ago I needed to setup a rack with network devices and a few servers.

The rack is placed in a closed garage, so the temperature range between winter and summer is pretty high, and also dust could be a problem.

While browsing the Internet for cooling solutions, I found out that they're pretty expensive, in my place at least, being >100€ for 4 230V ceiling-mounted fans with a thermostat control. I didn't like the thermostat drive because it sucks in a lot of dust when powered, because of the fans going full power, and gives no ventilation at all when unpowered.

So, unsatisfied with these products, I decided to go the DIY way, building something that can smoothly mantain a certain temperature.

Step 1: How It Works

To make things a lot easier I went for DC fans: they're much less noisy than AC fans while baing a bit less powerful, but they're still more than enough for me.

The system uses a temperature sensor to control four fans that are driven by an Arduino controller. The Arduino throttles the fans using PID logic, and drives them through PWM.

The temperature and fan speed are reported through a 8-digit 7-segment display, fitted on a rack-mounted aluminium bar. Besides the display there are two buttons for tuning the target temperature.

Step 2: ​What I Used

Note: I tried to realize this project with things I had lying in the house, so not everything can be ideal. Budget was a concern.

Here are the components I used:

  • Hardware
    • One acrylic panel: used as the base (€ 1.50);
    • Four 3.6x1cm L shaped PVC profiles (€ 4.00);
    • One aluminum panel: cut at 19" in width (€ 3.00);
  • Electronics
    • Four 120mm PWM fans: I went for Arctic F12 PWM PST because of the ability to stack them in parallel (4x € 8.00);
    • One Pro Micro: Any ATMega 32u4 powered board should work fine with my code (€ 4.00);
    • One relay board: to switch off the fans when they're not needed (€ 1.50);
    • One 8 digit 7-segment MAX7219 display module (€ 2.00);
    • Three momentary push buttons, 1 is for reset (€ 2.00);
    • One 3A power switch (€ 1.50);
    • One LAN cable coupler: to easilly disconnect the main assembly to the display panel (€ 2.50);
    • One 5V and 12V dual output power supply: You can use 2 separated PSUs or a 12V with a step down converter to 5V (€ 15.00);

    • Cables, screws and other minor components (€ 5.00);

Total cost: € 74.00 (if I had to buy all the components on Ebay/Amazon).

Step 3: The Case

The case is made of 4 thin L-shaped plastic profiles glued and riveted to an acrylic board.

All the components of the box are glued with epoxy.

Four 120mm holes are cut in the acrylic to fit the fans. An additional hole is cut for letting the thermometer cables pass through.

The front panel has a power switch with an indicator light. On the left, two holes let the front panel cable and the USB cable go out. An additional reset button is added for easier programming (the Pro Micro doesn't have a reset button, and sometimes it's useful in order to upload a program onto it).

The box is held up by 4 screws passing through holes the acrylic base.

The front panel is made of a brushed aluminum panel, cut at 19" in width and with a height of ~4cm. The display hole was made with a Dremel and the other 4 holes for screws and buttons were made with a drill.

Step 4: Electronics

The control board is pretty simple and compact. During the making of the project, i found out that when I supply 0% PWM to the fans, they will run at full speed. To completely stop the fans from spinning, I added a relay that shuts off the fans when they're not needed.

The front panel is connected to the board through a network cable that, using a cable coupler, can be easilly detached from the main enclosure. The back of the panel is made of a 2.5x2.5 electrical conduit and fixed to the panel with double-sided tape. The display is also fixed to the panel with tape.

As you can see in the schematics, I've used some external pullup resistors. These provide a stronger pullup than the arduino's.

The Fritzing schematics can be found on my GitHub repo.

Step 5: The Code

Intel's specification for 4-pin fans suggests a 25KHz target PWM frequency and 21 kHz to 28 kHz acceptable range. The problem is that Arduino's default frequency is 488Hz or 976Hz, but the ATMega 32u4 is perfectly capable of delivering higher frequencies, so we only need to set it up correctly. I referred to this article about the Leonardo's PWM to clock the fourth timer to 23437Hz which is the closest it can get to 25KHz.

I used various libraries for the display, the temperature sensor and the PID logic.

A little note on LedControl library: to make it work with my code, you need to include this pull request #13 which simply extends the default character map of the library. This is only neccessary to display the startup screen and the "Set" word when setting the temperature, so it can be easily avoided.

The full updated code can be found on my GitHub repo.

Step 6: Conclusion

So here it is! I have to wait till this summer to actually see it in action, but I'm pretty confident it'll work fine.

I'm planning on making a program to see the temperature from the USB port that I connected to a Raspberry Pi.

I hope that everything was understandable, If not let me know and I will explain better.


<p>My son and I are building a box for the electronics for his CNC plasma table. I figure you can't have too much cooling. The air in the shop is anywhere from 30 to 95 degrees F. We are using a 13&quot;x2.75&quot; automotive air filter and two 120V 100 cfm fans. The fans are on all of the time when the box is powered up. I can see where you would save some energy only running the fans when cooling is needed, but with a 4 KVA air compressor and a 7 KVA plasma torch a couple of fans will not make much difference.</p>
i was just searching something like this couple of days ago lol, but wouldnt be cheaper if you used just regular 3 pin fan, and pwm control them on input pins? just like regular motors
Well, you will actually need a transistor to drive a 12v fan through PWM, And you will not be able to read the speed of the fan. Another solution is to drive the fan using a voltage regulator, but this adds complexity, inefficiency and cost.
<p>well transistor should be alot cheaper than pwm fans,and you wont have to use relay, since you can just set it to 0%, maybe you could use lcd to show duty cycle</p>
I just checked on Amazon, and the difference between PWM and non PWM fans is just 16cents, so yes, you would save about 1&euro; but you won't be able to see the actual RPM. Don't know if worth, but if you have 3-pin fans lying around the house it'll just work fine.
<p>Actually, a regular 3-pin fan will show you the RPM on the 3rd wire.</p><p>The 4-pin PWM fan has, Power (+12V), GND (0v), RPM monitor and PWM signal; a pulsed level to regulate the speed of the fan between 0-100% duty cycle, time based not voltage based.</p><p>The advantage is that it is still the full 12v that the fan see's, thus it can sustain much slower speeds than a 3-pin fan. As the 3-pin fan you regulate the voltage going to the power pin and fans will have a minimum turn on voltage.</p><p>Thanks for the idea's in this 'ible tho :)</p>
Il you drive the fan with PWM, the RPM reading will be wrong because you're basically switching the fan on and off. Some fans might still report a correct measure if the RPM reading works with the fan turned off, but it's not guaranteed. Happy that you enjoyed my instructable ?
thanks for an awesome tutorial, this is a great way to make an external laptop cooling platform

About This Instructable




More by Bonny97:Temperature control with Arduino and PWM fans Raspberry Pi Audio Player 
Add instructable to: