Open Source Microchip LED / PWM Driver Project




Introduction: Open Source Microchip LED / PWM Driver Project

About: Founder of Powerhouse Electronics. For more info goto:

This instructable fully describes building a PWM driver to control four LEDs from one small Microchip 12F609 board.

The original design was called the "Kemper LED Lamp" and I sold a few lamps to several brave folks through my web site. However, I've come to discover selling small quantities to a few folks is a major pain in the backside. Hand soldering these together and then selling them at $4 bucks each is no way to make money.

So, I'm going Open Source baby. I'm hoping that more people can enjoy these wonderful little lamp drivers. I've put in way too much work for these little gems to sit idle on the shelf and not get used.

With the information I'm providing here, you should be able to program your own Microchip 12F609 micro, connect a couple LEDs, and have your PC command some LED action. 

For reference, here are links to my prior Kemper LED instructables:

Those two links have a bunch of information that cover the lamp design in detail. There are even a couple video demos in those instructables that, I think at least, are cool too.

Note, if anything new comes up you can always check my web site at:


Step 1: Hardware Design

The hardware is painfully simple. The micro drives four outputs and receives / sends commands on the fifth. Couldn't get much simpler.

Eventually, I ended up with a board design that is 20mm x 15mm. To keep the cost down I used CAMtastic to array the lamp boards onto a larger board. I arrayed the lamp boards using a grid of 8 x 8 with a 0.055" gutter between each lamp. The gutter makes it easy to cut the lamps apart with my cheap-o bandsaw.

Step 2: Software Design

Programming the 12F609 separates the men from the boys. While the hardware may be super simple, the software is not. I spent weeks (OK, maybe two) pouring over this stuff. The code below has been highly optimized just for this application. There is practically no RAM or ROM leftover to spare. In fact, I ran out of RAM many many times and had to ether drop functionality or look for more optimizations.

The 12F609 does not have a UART. So, receiving new commands while maintaining the PWM channels became my nightmare. The PWM channels must be maintained even while a new character is being received. The human eye is just so good at seeing the smallest blip emanating from an LED.

Receiving a new character using software is no big deal. But, receiving characters while updating PWM outputs is. The trick is to update the LED output channels while waiting for the next bit on the comm link. In effect, it's multitasking, and getting it all working was a major hassle. Simply impossible without a LSA (logic state analyzer). I used one output pin as a debug pin. I'd toggle the pin on certain events and watch for it on my LSA. Using this trick, I could watch each bit being received by my code.

OK, OK, enough already. Below you can find the source files that do all the magic. I'm publishing them in the hopes that others can learn from my efforts. There really is some good code in there.

Instead of describing all the software in detail, the comments in the code should explain most stuff. Remember, when in doubt "Use the force - view the source." I added a bunch more comments to the code in an attempt to make it more readable. I hope you'll agree that it is, indeed, readable.


Update: May 16th, 2012

Below is a Zip attachment which has 32 hex files within.  Each hex file is the same except for the hard-coded node number.  So, to flash node #1 use file "1.hex" to program the micro. 

This should help folks who do not have access to the CCS C Compiler.

Step 3: Datasheet

Attached to this step is the datasheet that goes along with the project. The datasheet does a good job of documenting each protocol command.

Well, that's it. Hope you find some good uses for the Kemper LED Lamp.



    • Water Contest

      Water Contest
    • Tiny Home Contest

      Tiny Home Contest
    • Fix It! Contest

      Fix It! Contest

    29 Discussions

    Is possible to publish or receive the file .hex?
    Which program has been utilized for compilation?
    What should be connected to connectors P1 and P2, under Comm?
    By chance the PWM Driver Project, must be connected to an Arduino?
    Is possible to use it independently, without connecting all'Arduino (which I have)?
    Thank you.

    5 replies

    Yes, have a look at step #2 - I just updated the step with the new hex files. I've added a zip attachment which has 32 hex files within. Each hex file is the same except for the hard-coded node number. So, to flash node #1 use file "1.hex" to program the micro. In other words, the hex filename indicates what node number is hard-coded inside the file.

    I used a C compiler from CCS to compile the code. I used PCM C Compiler version 4.087.

    For connecting P1 and P2, have a look at the schematic in Step #1. The connectors are designed so that power and communications passes through. If you look at the circuit traces on the bottom of the circuit board it becomes very clear that the signals just pass through. Pin #1 is +5Vdc, Pin #2 is ground, and Pin #3 is TTL communications (9600 baud / 8 bits / no parity). You can use either P1, P2, or both.

    Yes, the nodes must be connected to an Arduino. Each node is a slave and won't do anything without being commanded to do something. Without any master commands nothing happens.

    Yes, you could replace the Arduino with a regular laptop or PC. Just make sure to use a 5 volt TTL serial port. These can be found at Sparkfun for under $10 bucks.

    Good luck,

    Thanks for giving me the answer and good explanation.
    So your circuit, you can use it both with the Arduino and the computer, in the absence of the Arduino, right?
    Is possible to use the file .hex for 12F629 and 12F675 pic (because right now I have no pic 12F609)?
    As a USB-TTL, I have an inexpensive adapter CP2102 (already tried with other PIC and AVR).
    What is the program to handle the RGB controller from Windows?
    Hello and thank you.

    Have a look at my web site where I have a bunch more information:

    At my web site, I have a Visual Basic application that can be used to send commands to the nodes. It's good for testing new nodes. The source code is available too. However, I find Python a better tool for testing. Let me know if you want some Python code examples.

    I would guess that the hex code would work with the other chips. If does not work you can just erase the chip - no harm done. It's worth a try as a test.


    Thanks for the replies.
    When I can, I try if it works first on the 12F629 and 12F675, 12F609 then when I have, I try this, too.
    Python, would only work under Ubuntu Linux?
    Why at this time, the laptop I have Windows Vista, so not sure there is a version of the Python for Windows.
    I'll know when I can.

    The best part of Python is that it runs on almost anything. For sure, you can run Python on Windows Vista. I've run Python on both WinXP and Win7 without any problems. But yes, I think Python works best on Linux. Everything works better on Ubuntu / Linux!

    Good Luck,

    I got all the part for this project and some 4pin RGB Leds and now wonted to try it out and I realized that diodes in the schematic use a common anode, and 4pin RGB Leds use a common cathode :( .
    If you ever decide to rework the design with the new micro it would be great if the polarity for powering led is inverted. Any way great job keep it up !!!

    2 replies

    I bet you could find some common anode RBG LEDs somewhere. After all, we have the internet!

    Have a look at step one where the PCB layout is shown.

    On the top side of the board, the feed trace for the LEDs could be cut and re-routed to ground instead. This would enable you to use your common cathode LEDs instead. No change to the micro or software required.

    Also, have a look over at Hack-A-Day, I saw a post recently where someone was creating something almost identical. Maybe there is an active project going over there.

    Hope this helps,

    waweru john,

    Thanks for the comments.  This design is getting a bit dated since I originally started. Microchip now has a 80 cent micro that has a UART!  That would have made life sooo much easier.  I actually was tempted to rework everything with the new micro. 

    However, GE Lighting has introduced a new line of Christmas lights that are programmable.  Each GE bulb has an RGB LED. The string of bulbs can be hacked / controlled with an Arduino.

    Still, if you only want one or two bulbs the Microchip processor might still be the way to go. 

    Anyway, I'm still posting lots of stuff on my web site. You can find the latest at

    Thanks again,

    I've always imagined that I could use an Arduino to control glowy LEDs on my motorcycle, but haven't the stuff to imagine how. I'd like a solid on, as well as a "breathe" mode where the lights brighten and dim. Seems simple enough, but how?

    Do you reckon this could accomplish that? Can it drive a couple hundred LEDs, and be vibration resistant?

    6 replies

    Yep, you sure could use an Arduino to control a couple of LEDs.

    There are a couple of tricks to making that happen.

    The biggest trick is driving all those LEDs. Each pin on the Arduino can drive only a single 20mA LED. With a big monster transistor that problem goes away.

    The other trick is generating a smooth pulse width modulated (PWM) signal out of the Arduino. Looks like "maybe" the new Arduino Uno has the ability to generate PWM signals right out hardware. That would be sweet - simply setup some timers and the PWM signal starts. In that way, doing other things with the Arduino won't goof the PWM output. The human eye is really good at seeing the smallest little glitch in a PWM signal.

    Anyway, to answer your question, yes, a new Arduino Uno with a big butt transistor and your in business.

    Good luck,

    I have been playing with PICS for a while and when I wanted to control many LED's with multiple intensities it was a pain to code it and not to mention bulky add on drivers. In my quest for finding a solution I came across some chips listed below that kind of do the same function with built in drivers etc..
    I like the ones with programmable intensity so dont have to bother with coding for independent LED intensity control.

    CAT4016VS-T2 from On Semi
    TLC5928DBQ From TI
    STP16CP05MTR From ST
    PCA9632TK2,118 from NXP

    This is just a sample there is a huge variation of options including the number of LED, current, communication etc etc.
    for a similar function listed here one can pick the 4 led version. This is a great project with many other pros.




    Thanks for the pointers to other parts.

    One thing to note, the "itch" that I was trying to solve was different than these driver chips can solve. Typical driver chips have no brains. They won't, on their own, slowly ramp a LED. To perform ramps, the master must send each new intensity level over the serial comm bus. This becomes a real pain with lots and lots of LEDs.

    My design adds the brains in the 12F609 chip. Each 65 cent part has 2 MIPS of brain power. So, you can send the lamp one command that might take up to 4 seconds to complete. While the ramp is happening, the lamp will accept commands to perform a different kind of ramp for another LED channel on the same lamp.

    Bottom line, these lamps have intelligence to complete tasks. There not just SPI LED driver chips. This is a big difference.

    But again, you application my be different. These lamp are targeting applications where the master node can't send tons of SPI messages.

    This design tries to off-load the burden of keeping the PWM signal updating smoothly from one intensity to another. The one wire comm bus is also a nice feature when string long runs together.

    So it all depends on the application,

    Thanks for the reply. So you are saying I wouldn't need the daughter board?

    I apologize for my cluelessness, but I gotta think there is a cheaper and better way to light up my bike than with a $400 solution that has only on/off.

    Thanks again!



    I too must apologize - I'm not an Arduino guy. I don't know what a daughter card is.

    But, the Arduino is cheap fun. I just looked at Sparkfun and they have Arduino boards for under $30 bucks. I love cheap dev. boards like that. Cheaper than taking the wife, and kids, to dinner. Just don't tell them I said that!

    My suggestion is to get a $30 Arduino board and play with it. If you can get one LED to ramp & decay then adding a transistor to get a 100 to do the same should not be a big deal.

    Here is a link to inexpensive LEDs that I use:

    These are wide angle (120 degrees) 200+ mcd (milli candle) LEDs. A 100 of these throbbing on your bike would look cool. A 100 red LEDs will set you back $17 bucks.

    So, $30 bucks for an Arduino and $17 bucks in LEDs. I'll bet the transistor will only be a couple of bucks.

    But start slowly, get the Arduino working on the bench with one LED first. Then buy a bag of LEDs from Best Hong Kong. Get a bunch of them working on the bench with a transistor. Then, finally, start thinking about wiring the bike.

    Using the PWM signal from the Arduino you can make some really nice fading on / off effects. And not just simple on / off stuff.

    Also, there is a guy who writes articles in Nuts & Volts magazine. He writes a lot about the Arduino. Might be a good source to get started with.

    Good Luck,

    Until I find someone to manufacture the boards it's really not practical to hand assemble the boards for resell.

    However, as you can see in step 1 (forth picture) I still have a sheet of 64 boards. I can cut these apart and sell the individual blank lamp boards. The board will need the micro, one cap, and four resistors soldered down (and of coarse the LEDs).

    So, if your still interested, send me an email to: Jim . Kemp @ Ph-Elec . com

    Thanks for your interest,