Introduction: Color Changing Digital PC Fan Controller

About: I finally graduated from Missouri University of Science and Technology (Missouri S&T, formerly University of Missouri Rolla) with a computer engineering degree. Originally from Belleville, IL (St. Louis area)…

We've all seen LED fans that you can put in your computer to make it look cool.  They usually come in blue, sometimes red or green and consist of a basic PC fan with 4 bright LED's mounted in the 4 corners.  They source their voltage from the fan's power input, so if you're using a fan controller (either the one built into your motherboard or otherwise) to slow the fan, the LED's get dim.

Well, I got a new case for my server and it took 120mm fans, so I had to buy new fans for it.  I got a nice blue LED fan for the front but one of the LED's was burned out and it didn't look good, plus the fan was loud and I was out of controllable channels on my motherboard.  I got a free replacement for the bad LED, but I already had my mind set on converting the fan with the bad LED into something much better using what I'd learned about microcontrollers last Fall.  The plan?  A self-contained, digital, full control fan controller based around an AVR microcontroller that could have fine control over the fan's speed, read back the RPM, and control not just the brightness of the LEDs but also the color.  Having seen a lot of cool projects using RGB (red-green-blue) LED's online, I figured it would be a good project.

Step 1: Find a Suitable Fan for Modification.

If you don't have an LED fan already, you can't just convert a plain fan.  The fan I am using cost $5 on NewEgg and they sent me a free replacement for one bad LED (yet they let me keep the "bad" one so I used it for this project).

Things you want:

Clear plastic.  Tinted plastic may give unwanted effects (but if you want to try, go ahead, it may produce a neat effect, I tried one RGB LED on a blue-tinted fan and it looked OK).  Black plastic won't give you the same effect, though I've seen LED fans that have black plastic and they do give the LED lines when spinning.

3rd wire (RPM sensor wire).  This wire (usually yellow or white) is what fan controllers use to count RPM.  It pulls low (connects to ground) twice per revolution of the fan, so you count falling edges per minute and divide by 2 (or count falling edges per second, divide by 2, and then multiply by 60).

3-pin connector.  The 3-pin connector is a PC fan standard, it's the connector that motherboards use and it's the connector I designed my controller to use.  Some newer fans that use 4 pin connectors won't work for this project.  It may have a 4-pin Molex (power supply) connector, I just cut it off and used that connector to connect the fan controller to my computer's power supply.

Step 2: Parts List

This is going to be fun...

IC's:
1 - ATMega168 (DIP28 through-hole package)
1 - MAX232  or equivalent (DIP16 through-hole package)

IC sockets:
1 - DIP28 socket
1 - DIP16 socket

Transistors:
1 - PNP, I used D1616 (NPN) and B1116 (PNP) transistors, they're capable of 1A current
1 - NPN  If you use any other transistors, they MUST BE ECB (where base is on the end, not the middle).  This is different from most other transistors I've seen and didn't notice until I tested them after I ordered them.  They were cheap though so w/e.

Here is where I ordered them:
http://www.mouser.com/ProductDetail/Fairchild-Semiconductor/KSD1616YBU/?qs=sGAEpiMZZMuCl5o%252b%2fAuPoF6bPDHyecV%252bopNRXL9NXYU%3d
http://www.mouser.com/ProductDetail/Fairchild-Semiconductor/KSB1116AGBU/?qs=sGAEpiMZZMuCl5o%252b%2fAuPoF6bPDHyecV%252bD5J9z1SsUW0%3d

Capacitors:
5 - 1.0 uF capacitors, I just used some little blue ones, they're either ceramic or similar, not electrolytic.

Resistors:
3 - 1KOhm, 1/4 watt (though you could get by with 1/8 watt easily)
2 - 10KOhm, 1/4 watt (also could use 1/8 watt)
12 - 300 Ohm, 1/4 watt (might be able to use 1/8 watt, these handle the LED current)

LED's:
4 - 5mm, Common Cathode RGB LED's - I used clear (not diffused) ones and diffused them with sandpaper.  I think regular diffused ones would probably be "too diffused" and be a bit dim.  I got a 50 pack of these RGB LED's on eBay from China, was only $15 shipped, compare to Mouser's $2.00 per single LED before shipping.

Connectors:
I used 0.1" (2.54mm) breakaway pin headers for all my connections.  To connect to them, I got a 32-pin rectangular connector that fits 0.1" pin headers and then cut it into pieces.  I got one that was through hole so it had pins that were easy to solder to.

PCB:
Copper-clad, single sided PCB that is at least probably 4"x2".  I used a 6x6" and there's room to make at least 2 more.

Printer:
A laser printer to print the PCB design, just any old laser printer should work.

Step 3: Remove the Original Fan LED's.

To start out, you need to modify the fan so it has RGB LED's in it.  The hardest part is removing the old LED's as they're probably glued in pretty well.  I just took a small screwdriver and pushed them out from the front (be careful around the fan blades, don't break them!).  After pushing them out, I desoldered the blue LED's and put them in my parts bin (they still work, so they'll be useful later).  I then taped up the LED wires with clear tape so it wouldn't short out.

After this, plug the fan back in and make sure it spins without the LED's.





Step 4: Solder Wires to the RGB LED's.

I used flat ribbon cable for this.  You need 4-wire cable that is thin enough to wrap around the fan without too much work.  Ribbon cable (not the really flat stuff, but like IDE cord type wire) is very good for this as you can tape it to the outside of the fan.  Use pliers to bend the leads from the LED at a 90 degree angle.  Keep the bend close to the base of the LED so that it won't stick out of the fan or obstruct the fan mounting holes.

After bending, carefully solder the 4 wires to the 4 pins of the LED.  Don't leave the soldering iron touching the LED for a long time as LED's are sensitive to heat and you could burn out one or all of the colors, rendering that LED useless.  In case this does happen, try "zapping" the non-functioning LED with 5 volts (no resistor).  I had the blue LED on one of mine not work, but after hitting it with straight 5V for like 5 seconds, it started working and works fine now.

Clip the excess leads and put tape or glue around the connections to protect them.

Repeat until you have 4 RGB LED's that have wires coming off of them.  Make sure you know which wire goes to which (test them with a battery, the longest pin on the LED is the ground [cathode] and the others are red, green, and blue, find out what is what with a battery and remember it or write it down).  Test to make sure all the colors light up when connected as well.

Step 5: Install the RGB LED's in the Fan

This is a pretty easy step.  Look where the motor wire comes out of the fan.  This is where we want the LED wires to come out as well.  Start with the two LED's closest to it.  Angle them so that the cable coming off the LED is going towards the motor wire and push the LED's into place.  You don't have to glue them in unless they don't fit very well otherwise.  Use transparent tape (I used the cheap Walmart stuff that is truly clear) to tape the LED cables tight against the fan.  Then put in the other two LED's also with their cables wrapping around on top of the other LED cables, tape them down and then tape the 4 cables together (you should have a clean looking square bundle of wires and then tape this bundle to the motor wire.  Your RGB fan is almost complete, now for something to control it with.

Step 6: Prototype the Circuit (Optional)

If you like using a breadboard to test things before making the PCB, now is your chance.  Stick your Mega168 and MAX232 in a breadboard, put the 2 1uF capacitors on the MAX232, hook the MAX232 to a serial port and the microcontroller's Tx/Rx pins, hook up a 5V regulator and power the two chips, and then follow the LED wiring pinout below to hook the AVR to the LED's:

Pin 14 (PB0):  Red 1
Pin 15 (PB1):  Green 1
Pin 16 (PB2):  Blue 1

Pin 17 (PB3):  Red 2
Pin 18 (PB4):  Green 2
Pin 19 (PB5):  Blue 2

Pin 23 (PC0):  Red 3
Pin 24 (PC1):  Green 3
Pin 25 (PC2):  Blue 3

Pin 26 (PC3):  Red 4
Pin 27 (PC4):  Green 4
Pin 28 (PC5):  Blue 4

Hook each connection through a 300 ohm resistor, and connect the 4 LED ground pins to ground.

Connect the fan motor by putting a 1K Ohm resistor from Pin 5 (OC2B) to the base of the NPN transistor.  Connect the middle pin of the transistor to a 10K Ohm resistor which then connects to the base of the PNP transistor.  Connect the remaining pin of the NPN to ground, the middle of the PNP to the fan motor, and the remaining pin of the PNP to your 12V (or whatever you're using for a power supply, I breadboarded mine with a 9V because I had one lying around, still good enough for a test).  Connect the fan's ground to the breadboard ground, connect the yellow wire to a 10KOhm resistor and also to a 1KOhm resistor.  The 10KOhm goes to +5V while the 1KOhm goes to AVR pin 11 (T1).  Also put a 1uF between pin 11 and ground to smooth out the signal.

Hook up your programmer to the AVR and download the code onto it (the code is at the end of this Instructable).  See Step 11, you have to set the fuse bits on the AVR to disable the internal clock divider.  The clock/8 bit is turned on by default and needs to be disabled before the code will work.  After installing the AVR code onto the updated AVR, open up the client app and try turning on the fan.  It should light up and spin perfectly.  At this step you can either just shove your breadboard in your PC and call it done, or you can do it right and make a PCB.

Step 7: Create the PCB

I designed the PCB in Eagle CAD, but it's already done so you can just download the PDF and print it out.  I've included 4 of them in the PCB if you want extras.

The method I used is the "toner transfer method".  What you do is print the PCB design out on a laser printer.  It MUST be a laser printer, inkjet printers use liquid ink that will not transfer like toner does.  Then, cut the design out of the paper, leaving just a little white around it (just make it square, don't try to follow the lines).  Clean the copper surface of a blank copper clad board, then lay the paper (printed side down) against the PCB.  Notice that the printout is mirror imaged, this is on purpose as it will flip when transferred to the board.

Put the PCB blank side down against a heat resistant surface, with the paper face down on top of the copper.  Then get a hot clothes iron and press it down against the paper.  This will melt the toner, adhering it to the PCB.  Put a fair amount of pressure down on it to make sure every bit of it melts.  Lif the iron up, rotate it, and put it back down (don't drag it across the paper, you might smear the toner if it's hot).  Keep changing the orientation to cover every bit of the paper with full heat.  This may take a few tries to master the technique but it's an easy way to make nice boards on the cheap.

After heating, take the PCB and let it cool down (it will probably be too hot to pick up at first).  After it's cool enough to carry, take it and submerge it in soapy warm water.  VERY GENTLY start rubbing the back of the paper with your finger (not your fingernail, that will scratch the paper and could damage the transfer.  After the water has soaked in a bit, you can start to gently pick apart the paper starting at the outside.  You should be able to get at least the top layers of the paper to start to peel off without pulling up any of the toner.  After most of the paper is gone, gently rub the paper with a bit of pressure to break up the paper fibers that still may have toner attached to them.  Get as much of the paper as you can off without damaging the toner, you can etch around a bit of paper threads but once the toner is gone it is hard to fix.

If you mess up, you can use acetone (nail polish remover) to remove the toner and start over, you can also use a scouring pad to gently scrape it away, though a scouring pad may damage the copper layer if you use it too much.  Keep trying until you get one that is perfect or very close.  I had one pad fall off and a few minor breaks in mine.  I touched them up with a Sharpie marker but the etchant still ate through it.

After you've got your board ready, cut the part of the board you want out of any board you want to keep unused with a dremel.  Then take the board that you want to etch and stick it in some etchant solution (I used ferric chloride, but there are many things that will dissolve copper).

Wear rubber gloves when doing this, it will keep your hands from turning weird colors and staining things, also do this over some newspaper and I would recommend doing it in the garage or unfinished basement so you don't stain carpet or nice floors.

After etching, there should be no copper visible but under the black toner.  This means it's ready, take the board out and then use acetone (nail polish remover) to get rid of the black toner and expose the copper.  Now you're ready to solder, assuming there are no major missing parts (a little break isn't a big problem, you can bridge it with solder, a missing pad is harder to fix, but mine was close enough to the trace that it bridged easily.

After you get the toner off, use a tiny drill bit and a drill press to drill the holes.  I used a cheap $15 drill with a "drill stand", a holder that makes a cheap drill into a cheap drill press.  I used some tiny drill bits that were for model railroading to drill the tiny holes.  There are a lot of holes to drill, don't miss any, and drill starting at the copper side because it's easy to line up the hole right where it's marked on the board.  Take your time and it shouldn't be a problem.

After drilling the holes, go over the board and look for any spots where the copper didn't dissolve between two traces.  There were a few spots that I had to cut out with a knife, one was the SCK line shorted with the AVCC and wouldn't program but works great after I scraped out the tiny flake of copper bridging the traces.

Step 8: Start Inserting Components.

This is a pretty easy step if you're good with a soldering iron.  Just make sure you line everything up right and you'll be good.  Look at the circuit board diagram for lining up the chips.  Use the diagram below to see what goes where, I've labeled the entire thing.  Note that this is a top-down view, the copper layer is the bottom so look at the side where there isn't copper, that's what the diagram is.

Remember to solder in the IC sockets and not the IC's themselves, make sure you orient the sockets according to the diagram and then plug the IC's in the same direction.

For the jumpers, I just used the rest of the resistor leads that I clipped off after soldering in the resistors.  If you solder in the resistors first, save the clipped leads, they make good jumpers.  There are 3 jumpers on this board (the resistor right next to the ISP header is a mistake, it should be a jumper).

Step 9: Finish Inserting Components, Make Cables.

Once you've finished inserting components, you need to make the cables.  The board should have components in every spot.  You'll need to make 2 cables (Power and Data), attach a pin connector to the RGB LED's on the fan, and make sure the fan's 3-pin connector fits the 3-pin connector here.  Also, if you haven't done so already, insert the two IC's into their sockets making sure you get them in the correct orientation.

To make the power cable, take a 4-pin section of the rectangular connector and solder wires to each pin.  The two in the middle are ground, the one on the left (as according to the picture) is +12V, and the one on the right is +5V.  The other end is a standard 4-pin Molex connector that connects to your PC's power supply.

For the serial cable, one end is a 3-pin section from the rectangular connector.  I soldered a 3-pin ribbon cable on to it, the top-most pin according to the image below is ground, under that is Rx from the PC, and the front-most pin is Tx from the PC.  If your PC has an internal COM port (a 10-pin header on the motherboard near the rear COM port, usually has one corner pin removed), use a 5x2 rectangular connector (or 2 strips of 5 glued together, or just 3 individual ones since you only need 3 pins connected to that block) and solder them.  You may have to look up the exact pinout of the motherboard header.  Otherwise just solder a standard DB-9 female connector to it, run it out the back of your PC, and plug it into the rear port.

If you want to use USB, you can use a USB to serial adapter and modify it to connect to the serial port, or you can take the attached Eagle PCB file and modify it to use an FTDI chip instead of a MAX232, but that is beyond the scope of this Instructable.

Step 10: Attach a Pin Connector to the Fan LED's

The fan has 4 groups of 4 LED wires coming off of it.  Starting at the right on the PCB connector, it goes:

Ground, Red1, Green1, Blue1, Ground, Red2, Green2, Blue2, Ground, Red3, Green3, Blue3, Ground, Red4, Green4, Blue4

Take a 16-pin section of the rectangular connector and solder the LED's in that order (you do remember what order the LED's are in, right ;-) )

When you're done soldering it, use hot glue to glue a protective form around the soldered pins, there's a lot of tiny wires and hot glue will keep them from pulling apart.  It's only useful if you glue past the insulation break or the exposed metal will snap.  Then wrap the whole thing in tape to make sure.  Finish by grouping the fan wires with tape segments from the plug all the way to the fan until it is one single cord.  Tape the fan's power cord to this as well.  When it's done, it should look a lot like the picture below, and plugging it in (if you programmed the AVR in step 6) should cause all the lights to light up.  If there's a missing color, you know where to look (I had 2 LED's that didn't light up, turns out there were tiny breaks on their PCB traces, bridged them and it works great).

Step 11: Test and Install

Now it's time to see how it works.  Plug the serial port into the PC, plug the power cord into your power supply (make sure you orient it right on both ends, +12V goes on the LEFT looking at the board from the top), plug the fan in (so that the tabs face towards the center of the board) and plug in the fan LED's (so that the ground pin goes on the RIGHT).  Turn on the power.

You'll need your AVR programmer now.  The first thing you want to do is change the frequency of the internal oscillator.  By default, ATMega168's come with the clock/8 internal prescaler enabled.  This causes the chip to run too slow for this application and the LED's will just flash without glowing solid (or at least  appearing to using PWM).  You need to reprogram the fuse bits to turn off the prescaler.

Using AVRdude, this is accomplished by the options:

-U lfuse:w:0xe2:m-U hfuse:w:0xdf:m-U efuse:w:0xf9:m


After applying these, the lights should fade smoothly and serial communication at 19200 baudrate should work using the supplied Windows or Linux GUI program (download at the end of this Instructable).  If so, the board works fine and you can install it.  This depends on your case, so just install the fan as usual and mount the controller board however you can (I used tape, it's basic but it works).  Also remember to insulate the board so it doesn't short out against the case frame.

Step 12: The End (and Here's the Files)

The software provided is now almost complete!  I have RPM monitoring working and my Windows GUI is nearly complete.  I also added save-states so that the fan will turn on to its default speed along with the LED's when the PC first turns on.  The cross-fading also works, but I haven't documented the protcol entirely yet.

All serial frames follow this format:

0xAA  |  Command byte   |   Value byte   |  0xFF

Some commands don't take a value, but you must send a value byte to fill the 4-byte frame,
the value you send is ignored, 0x00 will do (so will anything else).

Some new commands:
0x03 = Save current state to EEPROM
0x04 = Load saved state from EEPROM
0x31 - 0x3C = Receive LED values
0x41 - 0x4C = Set crossfade buffer
0x51 - 0x5C = Receive crossfade buffer
0x61 = Start CrossFade (the value byte is microsecond delay in the fade loop, increase for slow fades)

All the files are now located on my Google Code Project!
http://code.google.com/p/rgbfan/