Serial Port Controlled CPU Fan

[Christian] was running a Linux box as a home server but needed a way to quiet the noisy machine. Like many Linux servers, he’s using some pretty old hardware which doesn’t have an on-board header for the CPU fan which generates much of the unwanted sound. Those headers are nice because software can monitor the CPU and board temperature and adjust the fan accordingly.

[Christian’s] solution was to use the serial port for the task. He built a small circuit in which serial pin 3 drives the base of a transistor, pin 5 provides ground, and a floppy drive power cable supplies 5 volts. From there he wrote a RUBY program to monitor the CPU temperature and generate a PWM signal on the serial port, throttling the fan speed as needed.

[CC Photo Credit: Garrette via Flickr]

38 thoughts on “Serial Port Controlled CPU Fan

  1. And if the rubyscript hangs or the server reboots, the fan doesn’t work because of the lack of pwm-signal?

    I would either work with Jake’s thermistor-solution or program a small attiny-µc to take commands per serial line, which works even if there is no input.

  2. I have bought 3 boards within the last 2 years and they all have legacy ports, just cause your name brand big box doesn’t …

    and Yea I would vote for an application that does not require software to be on to run it, I would feel much better with a hardware failsafe

  3. @Nick: You weren’t paying attention. “Like many Linux servers, he’s using some pretty old hardware …” I.e. if he had a new computer, he probably wouldn’t need to do this.

  4. @Jacek:

    He wired serial pin 3 to a transistor. not straight to the fan, which means that the fan -could- be triggered on the ground signal on the serial port, so the fan would be on full on startup, and then slow down while running the script. It depends on if it’s PNP or NPN.

    Honestly, this is a sweet and simple hack.

  5. varying the speed of a motor with a transistor usually results in poor speed control. You really need to PWM a motor to get smooth control. A more complicated circuit could vary the duty cycle of a 555 circuit or similar based on the thermistor, and it could all be done with analog circuits and no software.

    The only advantage that the thermistor/transistor combination would have is that since it would have negative feedback, and since the heatsink’s thermal mass provides enough low-pass filtering, it would become stable at some point. But I believe the fan would be spinning with less torque, and faster (more noise), than it would be if it were driven by PWM.

    A failsafe would of course be a good idea with either arrangement.

  6. im currently working on (taking longer than expected due to not backing up) usb controlled PC fans – using pic18f2550. best of both worlds – auto control based on external temp etc, then can override it with c# app when wanna quiet it down.

    extra advantage with microcontroller is scalable, and can run it from usb, rs232 or lpt port. have to be using some fairly unique hardware when none of the options are available.

    I mean i will continue work on it, as my pic is currently plugging into a ps3

  7. Well if you want a more fault tolerant you could use a simple micro and hook it up to the i2c bus on the PC or a bit banged SPI off the printer port or a serial connection.

    But honestly for a fun home hack using old hardware this is a pretty cleaver setup.
    The script hanging? I guess it could happen but the script is pretty simple. I would put that as a low risk. Everything can fail after all including the motor on the fan!

  8. Nice hack considering that tons of P1 P2 P3s getting recycled every day. You could get them for basically free with fancontrol so I could say why bother hacking one.

    Of course its a good hax. I never know that fan actually controlled by a frequency signal on the 3rd wire. I always thought that a certain current between the yellow and black wire determines the fan speed.

    Also I don’t get why new newbie programmers start with RUBY instead of the good old perl or C.
    But good hack anyways.

  9. @ Thermistor v/s CPU temp:
    I’m sensing a lot of misunderstandings here – you really don’t want to use the CPU temp as an indicator when to turn on the heatsink fan.

    Why? a lot of CPU work is bursty – perhaps even long-lasting enough to increase the core temperature, but not long-lasting enough to overcome the heat capacity of the heatsink. At that point, having the fan running faster doesn’t help a bit.

    You do want to use the CPU temp for monitoring – preferably in conjunction with the heatsink temperature – it would make it a lot easier to diagnose the overheating problems, if you have any.

  10. @Iratas Because perl is a hideous mutant abortion of a language that nobody should ever allow to pollute their mind, whereas Ruby is quite elegant and has a future as well as employment potential?

  11. Of course the usual solution to this problem is to use a bigger fan. (And/or a bigger heatsink.)

    Then you run fan at a constant low speed without fear of overheating. But interesting idea anyway.

  12. This will be my first negative comment on hackaday… What a waste of a serial port, this _actually_ needs more arduino. Serial ports are hard to come by now without wasting a pci slot for an IO card and those USB serial adapters, with the exception of FTDI devices, are mostly junk. Nice idea, but I can think of plenty of better things to do with my serial ports.

  13. @steaky

    I disagree. The goal of this project was to maintain a low fan speed without letting it overheat. If the software stops responding, it overheats. This design would not be acceptable in a “real-world” situation.


    No – It doesn’t need ANY “arduino”. You could use a microcontroller if you really wanted, but that’s some major overkill. Using an “arduino” would be even worse, you’d have this huge MCU board with all sorts of capabilities that would go to waste. I say, if you really want to, just pic a small microcontroller that fits the projects needs!

    1. An “arduino” is not overkill, it’s over estimated and over “quoted”, but certinally not overkill. Besides I was taking the piss anyway… Get a quiet microphone and speaker and cancel out the noise by reversing the phase of it.

  14. @Jake

    I dont know about you, but I enjoy doing these sorts of mini-projects.

    It seems like the purpose isnt just to have it quiet or just cold but to allow it to speed up if needed – as I very much doubt there would be the same CPU load all of the time.
    Whilst the serial port script is prone to failure, and an arduino is overkill he obviously didnt want to sit next to the box all the time tweaking pots. The thermistor would be good if he didnt care about the values, but it doesnt afford the same amount of control (ie script/arduino/pic can intuitively inrease fan speed based on CPU load as apposed to tackling the issue when heat has already build up).
    Obviously a simple measure would just be quiet fans

  15. @vtl

    You should hear the fan in my old Shuttle X. Then you’d understand.


    Yeah, it’s fun, but wouldn’t a little analog circuit design be *more* fun? I mean, anyone can bang out some code to twiddle an I/O line the way they want it, but how many people are willing to do it the “old fashioned” (read: RELIABLE) way? :D


    Nono. The thermistor solution is definitely superior, that’s why it’s been used for so long…

    “Get a quiet microphone and speaker and cancel out the noise by reversing the phase of it.”
    HELL YES!!! Now YOU are speaking my language!!! Keep it simple, stupid. You don’t have to debug the code or worry about bugs in THAT circuit ;)

  16. Hm you guys didn’t read my article carefully enough – if the script hangs, there wouldn’t be a pwm signal. But this means the fan would run at full speed – NOT FULL STOP! That’s why you can use a 4 wire fan on a 3 wire port, too. Anyway thanks for your interest

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.