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.
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
1 - ATMega168 (DIP28 through-hole package)
1 - MAX232 or equivalent (DIP16 through-hole package)
1 - DIP28 socket
1 - DIP16 socket
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:
5 - 1.0 uF capacitors, I just used some little blue ones, they're either ceramic or similar, not electrolytic.
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)
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.
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.
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.
A laser printer to print the PCB design, just any old laser printer should work.
Step 3: Remove the original fan LED's.
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.
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
Step 6: Prototype the circuit (Optional)
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
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.
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.
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
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
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)
All serial frames follow this format:
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!