This project uses a common anode RGB LED to produce colours of the visible light spectrum. This will allow you to explore the connection between digital (the Arduino) and analogue (the LED).
TheoryAn RGB LED is comprised of 3 individual LEDs on a single package; a red LED, a green LED, and a blue LED. These three primary colours can be added together in varying combinations to produce a wide array of colours.
Pulse Width Modulation (PWM) is a method of reducing the average power of an electrical signal. The duty cycle is the proportion of time the signal is on. A duty cycle of 100% describes a full power signal. A duty cycle of 50% describes a signal that is on half the time and off the other half, which corresponds to half power. Therefore, each colour of LED can be varied in brightness by using the PWM pins of the Arduino to achieve various colour combinations. analogueWrite() is used to vary the duty cycle of the PWM pins. With an 8-bit PWM output, this gives 2^8 = 256 possible values to vary the duty cycle. This is how different colours are produced.
As this project utilises a common anode LED, the ON state of the LED is active low meaning that for the LED to illuminate, the signal must be LOW. This is opposite to a common cathode LED. As a result, for a common anode LED to be ON a 0% PWM cycle is required using analogueWrite(0) and for a LED to be OFF, a 100% PWM cycle is required using analogueWrite(255).
MethodologyThis project uses an Arduino Leonardo clone (ProMicro), however can be recreated using other microcontrollers.
Pulse Width Modulation (PWM) is used to control the brightness of the LEDs. The PWM pins are shown by Figure 1. Pins 3, 5, and 6 are used for the red, green, and blue LEDs respectively. For other microcontrollers, refer to the respective board pin diagram.
The pins of a common anode RGB LED are shown by Figure 2. The positive pin of the RGB LED connects to the VCC pin of the Arduino to provide power. The red, green, and blue LEDs are then connected to pins 3, 5, and 6 using a 220Ω resistors in series to limit current, preventing the LEDs from being damaged.
Comments