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.


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 =



11 thoughts on “LED RGB light effects with PIC12F629

    1. Please use English!
      I meant you need to copy the whole HEX code between the rows filled with =========, including the last empty row.

  1. 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

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

  2. 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.

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

  4. 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.

  5. hi, i can’s find the code for this project..could you give me a guide…Thank a lot

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 )

Connecting to %s

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