LED RGB light effects with PIC12F629

This project represents a small schematic for controlling a group of RGB LEDs with common anode or grouped single color LEDs (as the ones used in this case) using a PWM controller. And for the schematic to be very simple a minimal amount of components is used and also a low end microcontroller by Microchip. That’s why I think this schematic could be built even by a beginner. In addition there is no hard to find components used.

This project is based on the idea that usually the simplest things are the best. The microcontroller which controls the LEDs is PIC12F629. It is 8-pin low end microcontroller and has low price respectively (0.70$ at Microchip’s web site). Single button is used for changing the lighting mode. The microcontroller functions as a PWM (Pulse Width Modulation) regulator, which makes the LEDs look like their intensity is varying smoothly. As low end means low number of built in peripheral devices, this controller does not have hardware PWM module. so a software one is implemented. In addition no external generator or resonator is used which limits the clock to 4MHz or 1 million operations per second. Taking in mind the small  amount of program memory and all the things already mentioned, some restrictions are set. The most important are low PWM frequency (approximately 400Hz) and lack of manual duty ratio adjustments for all three generators (one for each color).

The drawings below one can see the schematics for the control module and the LED module.

led-rgb-pic12f629-control

The schematic functions as follows. After applying the power supply the microcontroller initializes its internal registers and peripheral devices and loads the last memorized lighting mode. Pins 5, 6, and 7 send signals to transistors Q1, Q2 and Q3 which drive the LED groups. The need of using transistors arises by the low output current of the microcontroller’s pins which is up to 25mA (better not go above 20mA) and that is enough for a single LED only. The power supply should have two power lines: 5V and 12V with common ground line. One could also use 12V power source and put a voltage regulator for providing 5V for the PIC. Button SW1 is used for switching all the lighting modes, which will be listed later. Using the internal pull up capability of the microcontroller there is no need of connecting external pull up resistor. The base resistors R1, R2 and R3 are chosen to be 1kΩ but it is recommended to use bigger value like 10kΩ to limit the current flowing through the transistors in case of failure or overloading. The transistors chosen are BC547C, which have β=500 (also known as h21). This means higher energy efficiency. A 12V power source is used for the LED module for the same reason. As one can see at the lower schematic, a single color LEDs are used. They are connected at 4 blocks of 3 groups by 3 LEDs. Otherwise said one can build 4 PCBs containing 3 LEDs of each color or total of 9 for each board. The resistors in the LED module are used to limit the current through the LEDs and their values are tentative only. The values depend on the LEDs used (voltage drop over a diode and its nominal current rating). In case one decides to build this schematic on should calculate the resistor values for himself or find them by measurements. The red LEDs are manufactured by semiconductor with low voltage drop over the PN-junction and that is why these LED start producing light at lower voltage. That is the reason for choosing higher value resistors for these LEDs.

The transistors used for this project have 100mA current rating and 0.5W power dissipation. One should measure the current flowing through the LED blocks which he plans to connect to the controller in order to prevent overload. The transistor can be changed with more powerful ones of course but it is very important to check the base current or otherwise the microcontroller’s pins can be overloaded. To prevent this one can use MOSFETs which can be driven by TTL signals at their gates. These also have higher price (up to 10 times and sometimes even more). MOSFETs are not chosen for that reason.

Bill of materials is not presented because the schematic contain small amount of components whose values can be taken directly from the schematic. There are no components with specific characteristics also.

In general the control module offers the following functions:

  • 14 lighting modes
  • memorization of a chosen lighting mode and loading it automatically at start up (hold the button for at least 2 seconds while the chosen mode is active)
  • 3 open collector type outputs with 100mA current rating and Vce up to 45V

Lighting modes list:

  1. All LEDs turned off
  2. All LEDs turned on (white)
  3. Red LEDs constantly on
  4. Green LEDs constantly on
  5. Blue LEDs constantly on
  6. Red and green LEDs constantly on
  7. Red and blue LEDs constantly on
  8. Green and blue LEDs constantly on
  9. Smooth color change with gradation between the three primary colors
  10. Smooth color change between the three primary colors (no gradation)
  11. Smooth pulsing of the red LEDs (minimum to maximum to minimum to …)
  12. Smooth pulsing of the green LEDs (minimum to maximum to minimum to …)
  13. Smooth pulsing of the blue LEDs (minimum to maximum to minimum to …)
  14. Smooth color change between the three primary colors with gradation followed by smooth change between color couples finishing with white

In order to use the schematic one will also need the software for the microcontroller. One can use a precompiled HEX file published on the next page. Copy all the code. Open new Notepad window and paste the code in it. Save the file with a name of your choice and HEX extension. Use ANSI encoding. There must be one empty row at the end of the file. Start your preferred software for programming microcontrollers, choose PIC12F629 for programing and load the HEX file into it. Program the chip and it is ready to be used.

Compiled software for creating HEX file:

Copy everything between the rows filled with =

=========================================
:020000000B28CB
:10000800FF0003088312A4000A08A500432BDA01A5
:10001800DB01DC01DD01DE018316FF239000830193
:1000280015289123322885013228CE233228C2236D
:100038003228CA233228C6233228B6233228BA23C4
:100048003228BE2332283E2232289E213228D3224B
:1000580032280B2332289B2232285E205F08003A80
:1000680003191728013A03191928033A03191B28F9
:10007800013A03191D28073A03191F28013A0319E1
:100088002128033A03192328013A031925280F3A8E
:1000980003192728013A03192928033A03192B2899
:1000A800013A03192D28073A03192F28013A031991
:1000B80031283228013085000A30DA00DA080319BD
:1000C80071288230A100DD30A000A00B6928A10BA7
:1000D80069286E288312DA0B6528DE018A28043025
:1000E800DA00DA0803198A285E08DD00DC018628B0
:1000F800DD080319832885100514DD038528851478
:100108000510DC0A5C0F7C28DA037528DE0B7328DF
:10011800051085140A30DA00DA0803199F2882309E
:10012800A100DD30A000A00B9728A10B97289C28E0
:100138008312DA0B9328DE01B8280430DA00DA08D3
:100148000319B8285E08DD00DC01B428DD080319AE
:10015800B12805118514DD03B32805158510DC0ABF
:100168005C0FAA28DA03A328DE0BA1288510051541
:100178000A30DA00DA080319CD288230A100DD3010
:10018800A000A00BC528A10BC528CA288312DA0B2A
:10019800C128DE01E8280430DA00DA080319E82863
:1001A8005E08DD00DC01E428DD080319E02885107D
:1001B80005100515DD03E328851405140511DC0A6F
:1001C8005C0FD828DA03D128DE0BCF280511851457
:1001D80005140A30DA00DA080319FE288230A10073
:1001E800DD30A000A00BF628A10BF628FB2883120F
:1001F800DA0BF228DE0117290430DA00DA080319CD
:1002080017295E08DD00DC011329DD080319102910
:1002180005110514DD03122905150510DC0A5C0F0C
:100228000929DA030229DE0B0029051085140515B2
:100238000A30DA00DA0803192D298230A100DD30EE
:10024800A000A00B2529A10B25292A298312DA0B46
:100258002129DE0146290430DA00DA080319462983
:100268005E08DD00DC014229DD0803193F2905107D
:100278008514DD03412905148510DC0A5C0F382933
:10028800DA033129DE0B2F298510051405150A30EC
:10029800DA00DA0803195C298230A100DD30A000F9
:1002A800A00B5429A10B542959298312DA0B502980
:1002B800DE01DE03031975290430DA00DA080319B0
:1002C8005D295E08DD00DC017129DD0803196F294D
:1002D8008510DD0370298514DC0A5C0F6929DA03AF
:1002E800622985148230A100DD30A000A00B7A2994
:1002F800A10B7A297F298312DE0199290330DA00BC
:10030800DA08031999295E08DD00DC019529DD0862
:100318000319922905158514DD0394290511851003
:10032800DC0A5C0F8B29DA038429DE0B8229013071
:10033800850008008501DE01DE0BA329BA290430F7
:10034800DA00DA080319B8295E08DD00DC01B429EF
:10035800DD080319B2290510DD03B3290514DC0AE9
:100368005C0FAC29DA03A529DE0BA3290514DE01ED
:10037800D2290430DA00DA080319D2295E08DD0030
:10038800DC01CE29DD080319CC290514DD03CD29AC
:100398000510DC0A5C0FC629DA03BF29DE0BBD296C
:1003A8000510DE01EC290430DA00DA080319EC291B
:1003B8005E08DD00DC01E829DD080319E62985105F
:1003C800DD03E7298514DC0A5C0FE029DA03D92963
:1003D800DE0BD7298514DE01062A0430DA00DA0894
:1003E8000319062A5E08DD00DC01022ADD0803196C
:1003F800002A8514DD03012A8510DC0A5C0FFA291E
:10040800DA03F329DE0BF1298510DE01202A0430F6
:10041800DA00DA080319202A5E08DD00DC011C2A4C
:10042800DD0803191A2A0511DD031B2A0515DC0A44
:100438005C0F142ADA030D2ADE0B0B2A0515DE01E0
:100448003A2A0430DA00DA0803193A2A5E08DD008D
:10045800DC01362ADD080319342A0515DD03352A9F
:100468000511DC0A5C0F2E2ADA03272ADE0B252A5F
:1004780005110800051085100515DE01DE0B452A5B
:100488005E2A0430DA00DA0803195C2A5E08DD0007
:10049800DC01582ADD080319552A05100515DD0366
:1004A800572A05140511DC0A5C0F4E2ADA03472A7D
:1004B800DE0B452A05110514DE01792A0430DA001D
:1004C800DA080319792A5E08DD00DC01752ADD08DF
:1004D8000319722A85100514DD03742A8514051082
:1004E800DC0A5C0F6B2ADA03642ADE0B622A051029
:1004F8008514DE01962A0430DA00DA080319962AF0
:100508005E08DD00DC01922ADD0803198F2A051137
:100518008514DD03912A05158510DC0A5C0F882AED
:10052800DA03812ADE0B7F2A85100515080085016C
:10053800DE01DE0BA02AB72A0330DA00DA08031935
:10054800B52A5E08DD00DC01B12ADD080319AF2AEF
:100558000511DD03B02A0515DC0A5C0FA92ADA03A8
:10056800A22ADE0BA02A0515DE01CF2A0330DA0005
:10057800DA080319CF2A5E08DD00DC01CB2ADD0882
:100588000319C92A0515DD03CA2A0511DC0A5C0FFF
:10059800C32ADA03BC2ADE0BBA2A05110800850132
:1005A800DE01DE0BD82AEF2A0330DA00DA08031955
:1005B800ED2A5E08DD00DC01E92ADD080319E72AD7
:1005C8000510DD03E82A0514DC0A5C0FE12ADA03CA
:1005D800DA2ADE0BD82A0514DE01072B0330DA00ED
:1005E800DA080319072B5E08DD00DC01032BDD08A0
:1005F8000319012B0514DD03022B0510DC0A5C0F1F
:10060800FB2ADA03F42ADE0BF22A0510080085011A
:10061800DE01DE0B102B272B0330DA00DA08031972
:10062800252B5E08DD00DC01212BDD0803191F2BBB
:100638008510DD03202B8514DC0A5C0F192BDA03E7
:10064800122BDE0B102B8514DE013F2B0330DA0052
:10065800DA0803193F2B5E08DD00DC013B2BDD08BF
:100668000319392B8514DD033A2B8510DC0A5C0F3E
:10067800332BDA032C2BDE0B2A2B851008008B1367
:100688000B1C682B0B10851A682BDB01851A582B5D
:100698008230A300DD30A200A20B502BA30B502BFD
:1006A800552B8312DB0A4A2B14305B020318642B88
:1006B8000D305F020318622BDF0A682BDF01682BFD
:1006C8005F08A6000001712383128B1725088A0092
:1006D80024088300FF0E7F0E0900A70083169C18CC
:1006E800722B83122708831383169B008312260814
:1006F80083169A009C13031083128B1B03148B130D
:1007080083161C1555309D00AA309D009C141C11A1
:10071800031C080083128B170800383083168500E5
:10072800831285010730990083168113C83083121C
:100738008B00831696160001A9238312DF000E3062
:100748005F02031C0800DF0108008312A0009C1848
:10075800AB2B83122008831383169B009C131C1455
:100768001A08080085140514051108000515051454
:1007780085100800051585140510080005140511D5
:100788008510080005158510051008008514051149
:0E07980005100800FF308500080085010800EC
:02400E00843FED
:00000001FF

=========================================

9 thoughts on “LED RGB light effects with PIC12F629

  1. The code was written in C with Hi-Tech PIC C 9.50 if I remember correctly. It is not published like I wrote in the previous post.

  2. Whatever seriously encouraged u to create “LED RGB light
    effects with PIC12F629 � Home Made Electronics”? I actuallytruly adored the blog post!
    Thanks -Hannah

  3. This project is great shit!
    HEX file is not working!
    Works with someone???

    Этот проект является большим дерьмо!
    HEX файл не работает!
    Работает с кем-то???

    1. Many have successfully replicated the project so it is definitely working. To act rude without being absolutely sure you are right is not in your favor.

  4. Sorry!
    Everything works fine! The PIC was wrong! I replaced every Okay!
    Sorry for the harsh words found! Big thanks to the project!
    Hi Bela

    К сожалению!
    Все отлично работает! ПИК был неправ! Я заменил, все в порядке!
    К сожалению для суровых слов, найденных! Большое спасибо проекта!
    Привет Бела

Your comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s