32768 colour remote controlled light

Download PIC source code

Since blue LEDs became available I've been interested in building a controller for red, green and blue LEDs to produce arbitrary colours. I also had an old infra-red remote control unit that I used to enable the parametes of a number of lamp patterns to be controlled.

Block diagram

The circuit is based around the PIC16F84 microcontroller. This can directly control LEDs up to 25mA and so was very easy to construct. The only other components are an infra-red receiver module and a piezo speaker.

PWM controller

The brightness of each LED is controlled by varying the time the LED is switched on. The refresh rate of the LEDs must be sufficient that there is no perceptable flickering while still giving a smooth transition between brightness levels. In order to get a fast refresh rate and a good intensity resolution a clock speed of 10MHz was chosen. This gave 32 brightness steps. A diagram of the PWM waveform for bright and dim settings is shown below.

The PWM code is driven from the PIC timer interrerupt and so runs in the 'background' and is unaffected by the variable execution time of the pattern control code. This is important because any variance in the execution speed of the PWM code will result in visible flickering of the LEDs.

IR decoder

The IR control was added after the main lamp control code as a convenient way of controlling several lamp pattern modes through a single PIC pin. The IR output of the control was captured using a photodetector connected to the PC soundcard and displayed in an audio editor. The waveform of the 'STOP' command is shown below:

This consists of a long high period followed by a low. Then come 32 bits of command data with a '1' encoded as a high pulse followed by a short pause and a '0' encoded as a high pulse followed by a long pause. There are always an equal number of 0's and 1's in a command which results in all the commands taking the same time to transmit. The decoded commands are in the following format:
11111111 00000000 00001111 11110000
The even bytes are the complement of the preceding odd byte. The first two bytes are the same for all commands from this controller and so this was hard-coded into the IR decode routine. The last odd byte is unique to each command and so a list of these was determined by looking at each command waveform.

The IR sensor is connected to the external interrupt pin of the PIC to ensure no IR command is missed. However this may delay a PWM interrupt and give rise to a visible flickering of the lamps. In practice this seldom occurs and actually provides feedback that an IR command has been sucessfully received.

Upon sucessful reception of an IR command the speaker beeps momentarily.


Once the PWM controller and IR decoder were implemented then a number of simple pattern effects were created. The functions of the remote control are given below as a guide to understanding the code:

1FADE_MODE Fade between colours. Vary speed with the 'VOL+' and 'VOL-' buttons
2MULTICOLOUR_MODE - Cycle through red,green,blue,yellow,cyan,magenta,white. Vary speed with the 'VOL+' and 'VOL-' buttons
3KIRAKIRA_MODE - Flash red,green,blue,yellow,cyan,magenta,white. Vary speed with the 'VOL+' and 'VOL-' buttons
4Custom colour mode - Choose red, green or blue with the 'SHARP', 'TUNE' or 'FLAT' button, vary brightness with the 'VOL+' and 'VOL-' buttons
5Steady red
6Steady green
7Steady blue
8Steady magenta
9Steady cyan
0Steady yellow
STOPTurn LEDs off, put PIC into SLEEP mode