We look at both analog and digital RGB LEDs, the differences between them, and how to use them.
While many makers are intimately familiar with RGB LEDs, others are new to the field of Making or are experienced Makers who have simply not used RGB LEDs before. For those approaching Making from a non-electronic background, Red/Green/Blue (RGB) LEDs can seem mystifying. We aim to take the mystery out by discussing the difference between analog and digital RGB LEDs, and the most common types within those categories.
To understand RGB LEDs effectively, it helps to revisit regular LEDs. Light Emitting Diodes are a semiconductor device in which a material that can be both insulator and conductor depending on the circumstances is treated to control its behaviour. Some of the material will be treated with doping chemicals, creating an area with an absence of electrons. The result is a region of P-type material and a region of N-type material, depending on how the material is doped. Despite the fact that silicon is the more familiar semiconductor material to us, LEDs are usually made from gallium arsenide (GaAs), gallium arsenide phosphide (GaAsP) and indium arsenide (InAs), with less common materials also around.
While early lab developments in semiconductors used separate materials joined at a point or face to create the PN junction (the area where P and N type materials meet), most production methods add chemicals to one semiconductor crystal substrate to create the PN junction. Most semiconductor devices we use in electronics are made this way and are formed from PN junctions: Transistors, signal diodes, rectifier diodes, and any devices based on them.
The exact way this occurs through energy bands and charge carriers like electrons and holes is an interesting topic, but contributes little to what needs to be understood for this article. The important point is that if the substrate and doping chemicals are chosen carefully, light is emitted while current flows through the PN junction. The wavelength (which is what gets interpreted by the brain as colour) of the emitted light depends on the substrate and doping chemicals. This means that one PN junction can only emit one colour of light. The reality is that it emits a narrow spectrum of light with a dominant peak wavelength.
There are exceptions to this general rule. A rare one is some PN junctions constructed in such a way that more than one wavelength is produced. We found examples of this from research laboratory situations, but none we found were commercial productions. The other main exception is the emission of white light. White LEDs generally use a phosphor coating on a blue or UltraViolet (UV) LED, with the high-energy blue or UV light stimulating phosphorescent light emission. Early versions of this emitted a very blue light, as the phosphor coating emitted a yellow light and so some blue light was allowed to be emitted to make the total light appear white.
Material science has come a long way, but the principle remains the same. White LEDs are still made with a phosphor coating, but now the combination of phosphor and its own doping chemicals means that all sorts of whites can be produced, from a nearly-red warm white, through pure white and sunlight, to a very blue white.
Notwithstanding the white version, LEDs are produced with a small ‘die’ of semiconductor material. One face of this is mounted directly to a metal frame for physical support and electrical connection, usually formed into a reflective cavity for through-hole devices and sometimes for Surface Mount Devices (SMDs). The other face is the radiant surface where the light comes from, and has a tiny fine wire attached. In an SMD, this is attached to one of the device pins, while the other pin is attached to the conductive mounting. In a through-hole device, the die is mounted to the ‘anvil’, the larger hand of the electrical connection, while the fine wire goes to the ‘post’, and the two together make up the ‘leadframe’ which is surrounded by a variety of resin package types.
The unfortunate side effect of the way LEDs are made to do what they do, is that they are quite fragile electrically. Because everything in them is low-resistance, relatively speaking, an LED will pass more current than it can handle, and far more than it needs to operate. Even if you precisely match the Forward Voltage (Vf) needed or even undersupply it, the current will destroy the LED. Many craft projects show LEDs used directly with coin cells, and this does work. With modern LEDs, the destruction is not instant. An LED run this way may last tens of hours, it may last hundreds. It could even last thousands of hours but the reality is that LEDs, if used properly, should last between fifty and one hundred thousand hours. In some projects, this sacrifice in lifespan is perfectly acceptable as a trade-off for simplicity.
Ultimately, there is no such thing as an RGB LED. Remembering that an LED is really the PN junction, and everything else is the physical package that provides mounting, electrical connection and physical protection. There is no PN junction (outside the laboratory) that emits three different colours on demand.
An RGB LED as we know it is one package with three LED dies mounted in it. This becomes plainly visible when viewing a 5050-sized surface mount RGB LED, as pictured. You can see the three dies for the three colours. Through-hole packages often have a common anode (+) or cathode (-) to save space, while many SMD versions have six pins. Each die has its anode and cathode accessible. However, when bought as a 'module' on a PCB, either all anodes or all cathodes are usually taken to a common pin, as in the image below. RGB LEDs, therefore, are usually available in the same packages as regular LEDs, they just have more pins.
The simplest form of RGB LED is that which was briefly touched on earlier: The analog RGB LED. In this form, three LED dies are applied to one package, with a connection for each die’s anode, and a common connection for the three cathodes. This is a ‘Common Cathode’ (CC) RGB LED. There are also ‘Common Anode’ (CA) versions, where the three cathodes are individually pinned and one anode supplies all three dies. Which one suits an application depends on a few factors.
The main difference is in how the LED dies are switched on or off. With a common cathode LED, the anode of each die is supplied with current from the control circuit. If the LED were connected to, say, an Arduino, with each anode connected to its own pin via the correct value of resistor, sending one pin high would activate the relevant die. For a common anode RGB LED, the anode supplies the current, and the cathodes must be connected to a control circuit which can sink (ground) current. An Arduino can do this, as the pins are grounded when low if set up that way, but not all control circuits can.
In addition, this may be a factor in transistor output circuits. Because most microcontrollers can only handle 20mA or even less, and discrete ICs like the 4017 only 10mA per output, transistor amplifiers are the norm. However, if an NPN transistor is used as the output stage, it should be used as a low-side switch (connected between the load and ground), which mandates a common anode RGB LED.
The reason for this is that in an NPN transistor, current flows across from the collector to the emitter when a smaller current flows between the base and the emitter (the b-e current here) to ground. If that b-e current is below a certain value, the transistor is not ‘fully saturated’ and is only conducting a proportion of the current it is capable of. That’s desirable in some cases, but by design, not by accident! When used as a high-side switch, the b-e current must flow through the load to ground. This adds to the resistance and therefore lowers the current flowing through b-e. This in turn can affect the operation of the transistor. NPN transistors work properly when connected on the low side so that the b-e current flows directly to ground.
There are times when a common cathode LED is the only option available in the package for desired LED characteristics, such as in a star-style high-power LED or a particular SMD shape or size. If this is the case, or if for another reason you need them, PNP transistors are the go. Less common as switchers in simple circuits, PNP transistors are nonetheless plentiful. They work when a small current can flow from the emitter, through the base, to ground. Note here that the terms ‘emitter’ and ‘collector’ are reversed from the NPN transistor, as they are defined by the base-emitter relationship and not where the load current flows.
This means that the base of the PNP transistor must be grounded for the transistor to pass current. In effect, it is an ‘active low’ device. In a microcontroller situation, sending the output connected to the transistor ‘high’ turns the transistor off, and sending it ‘low’ grounds the output, giving the base-emitter current somewhere to go and turning on the transistor. Because of this, PNP transistors should always be used as high-side switches, connected between the supply voltage and ground. This way, nothing can affect the current flowing from the emitter to the base, because all load factors are not in this path.
Of course, there may be times where you need to use a PNP transistor as a high-side switch for some reason, or you can only get the LED you want in a common-cathode configuration, but you still want an ‘active-high’ circuit where a high signal turns the LED on. In that case, an inverter circuit is needed. This requires an NPN transistor to control the ground path for the PNP base, and a resistor is used to tie the base to the supply rail so that it is held high, and therefore off, when the NPN transistor is not active.
Each LED die will need its own resistor. It’s tempting to just use one resistor on the common terminal, but each die has a different VF. If one resistor is used, brightness will not be the same between colours. How much so may be academic, as the measured brightness is not always the same as the perceived brightness when the brain interprets the signal. This is partly because over a certain brightness that varies between people, the brain just registers the signals from the optic nerves as ‘ouch that’s really bright’. It’s when a light’s brightness falls below this that visible differences occur.
There are other factors that affect the brightness of the individual colours in RGB LEDs, too. The main one is the efficiency of the LEDs. While the red die may have a VF of 2V at 20mA and produce 3000mcd, the blue chip may have a VF of 3V at 20mA, yet produce much more or much less light. It depends on the quality and specifics of the LED dies the manufacturer has used or produced. The cheaper the LED, the more chance there will be significant variation between dies, but there are exceptions at both ends of the scale. On top of the fact that the forward voltages vary, so do the operating currents between the dies.
Further to that, there is the optical brightness versus the perceived brightness. If a red die produces 2000mcd and a green die 2000mcd, the eye will see the green one as brighter. The human eye is most sensitive to green light. We covered some of this in our Classroom Issue 47, Making with Light. The summary, though, is that there is more to controlling the colour and brightness of an LED display than just the datasheet numbers.
DRIVING ANALOG LEDs
Analog RGB LEDs are completely passive, unlike the addressed digital versions discussed next. This means that each LED must be driven in parallel with any others, or separate I/O lines used. No one will ever be building an LED TV using analog RGB LEDs and an Arduino Uno, for example. However, there are certain advantages in some cases.
The easiest way to control multiple analog RGB LEDs is to use three high-current output circuits from your controller. This could be a bipolar transistor or a MOSFET output stage depending on the control circuit, but both work on the idea that three separate positive voltage (for common cathode) or ground (for common anode) rails are controlled, with all the RGB LEDs in parallel. This can get awkward quickly but has the advantages of requiring far less coding or maybe none) for those who aren’t strong in that regard, and of allowing genuine simultaneous control. This point is covered in more detail in the relevant section, but most protocols for digital LEDs address one LED after the other, and so at the end of a long string, sometimes a delay is noticeable. How much so is debatable and divisive, and probably depends on the application and code of choice.
The control circuit itself can vary, too. With MOSFETs as the output devices, Pulse Width Modulation (PWM) is the best way to control colour or brightness from a microcontroller. In a nutshell, PWM involves turning a signal on and off rapidly, and varying the amount of on time compared to the off time but keeping the frequency and overall time period the same. It’s easy to implement, thanks to pre-written libraries, and will vary the brightness from 0% to 100%. Arduinos have several pins that are designed to be capable of PWM, and by using three of them, you can mix and match brightnesses of the three colour chips to give nearly any colour. All LEDs in the parallel string will change at exactly the same time.
We published a circuit in Classroom Issue 32, March 2020, that was based on an Arduino Uno and three potentiometers. Each potentiometer was connected to an analogue pin, and the code used this value to set a PWM value for the relevant output. We used this to manually tune an analog RGB strip to the exact colour we wanted by eye, rather than knowing an RGB value, which we had no way of finding out. We were trying to match the colour on a printed sign. That article is available online if you want to read it or find the circuit.
That circuit was deliberately fairly basic, and didn’t use a MOSFET driver, so the MOSFET choice was very important. We used logic level MOSFETs so the devices were fully turned on by the 20mA 5V Arduino output. Have a look at that article for details of driving MOSFETs, including a discussion of the caveats of threshold voltages and gate capacitance. We expanded on this in Issue 43, February 2021, where we discussed MOSFET drivers. Both of these articles may be useful reading if you are going to construct a MOSFET dimming circuit, especially at higher PWM frequencies than the Arduino is natively capable of.
At the end of this article, however, we have a circuit that uses an Arduino to control the brightness of a bank of analog RGB LEDs from the code only. To keep it simple, there is no external control. Makers can choose blocks of code to use, then set and forget. Again, this circuit will use MOSFETs and PWM, in the same basic configuration as the earlier circuit. While MOSFET drivers will enable MOSFETs to operate at high speed efficiently, the frequency of Arduino’s PWM is low enough, and the gate current of the logic level MOSFETs low enough, that they’re not needed.
Of course, you can also control the brightness of analog RGB LEDs with a non-microcontroller circuit. It would be possible to build analog circuits to do things like colour change, fading, and so on, but it would be a lot of effort for no real gain besides the satisfaction of having done so. Generally, circuits like this are used in simple situations, such as fixed colour making, where dials will be set and forgotten. The disadvantage of the circuit shown is the heat and losses from the bipolar transistor.
WHY USE ANALOG RGB LEDs?
While the aforementioned issue of long strings of digital LEDs experiencing delays will affect few people, and the issues involved in building high-current rail drivers to run such a long string of LEDs are arguably more of a problem than the delays, there are other reasons to use analog RGB LEDs. Sometimes, that’s just what there is to work with. Some older coloured fitouts where an LED strip is glued into a sign, cabinet, or fixture used an analog RGB LED strip. They’re also often cheaper than the digitally-controlled strips.
The main reason to use analog RGB LEDs is availability. Most digital RGB LEDs are 5050-sized SMD devices on PCBs or strips. In some cases, a certain case or mounting style is only available, or at least only commonly available, on analog versions. If you want a 5mm through-hole RGB LED, it will most commonly be an analog variety. Pictured are both common anode and common cathode 5mm LEDs, and a superflux version, among others.
Sometimes, an analog RGB LED offers simplicity and versatility. In some situations, multiple panel indicators are required. An analogue RGB LED will take the same number of output pins as three separate LEDs, but only needs one position in the panel, and can provide red, green, blue, magenta, cyan, yellow-orange, and white indications with simple high-low IO control. There would be little value in using colours in between, as they need to be obviously different to be valid as an indicator. This means that those with even the most basic coding skills can write code which sends, say, pins 4 and 5 high to give a magenta indication, without needing to figure out the digital RGB commands. Those are simple to people who are natural with coding, but not to those who aren’t. Further, the same can be said of non-microcontroller digital circuits: If any combination of three switches or other inputs or outputs are on, the colour can tell you.
OTHER DRIVING OPTIONS
It is possible to multiplex analog RGB LEDs, and this has the advantage of having no delay, as would be the case if one long string of digitally addressed LEDs were used to build, say, a video screen. This is generally by some form of shift register, but it’s well outside the scope of this article. Maybe another time. However, it is worth knowing what is possible. Shift registers use either serial or parallel data, which is stored on the inputs, then transferred to the outputs on a single clock pulse. Being digital, the colour depth would be limited because each LED die would either be off or on. Multiplexing is just a system whereby an array has both negative and positive connections switched, so that fewer inputs can be used to control a given number of outputs such as LEDs. The image above shows a multiplexed matrix of LEDs without resistors for clarity.
DIGITAL RGB LEDs
The other form of RGB LED, and perhaps the more familiar and common, are digitally controlled RGB LEDs. These are actually the same LEDs as the analog version, with the addition of a tiny controller integrated circuit (IC) added into the package. The driver IC receives control information, and then uses PWM to adjust the brightness of each die within the package. The result is that one set of data (generally) can be sent to the group of LEDs, and each behaves the way it is asked to. Best of all, the resistors for each LED are usually built in!
This is achieved in different ways by different manufacturers. There are a variety of different protocols around, although several have become dominant. The two main variations are a single-wire interface or a two-wire interface. Of course, power still needs to be provided - single- or dual-wire interface refers only to control data. The control protocols and the code to go with them require too deep an explanation to fit here. They will be entire future articles. For now, a summary will suffice.
The vast majority of digital RGB LEDs are available in SMD versions, usually attached to a small PCB, or a strip. Most of the maker-friendly versions are in the 5050 package, with some strips available using smaller packages. It is rarer to find through-hole mount versions, but they do exist. Sparkfun has a 5mm version, among others, which is a 5mm regular LED T1 ¾ package with four legs rather than two. Adafruit has the individual 5050 devices as well, unmounted. Our friends at LEDsales also have quite economically-priced through-hole versions, and some others worth checking out.
SINGLE WIRE LEDs
The majority of single-wire RGB LEDs conform to a protocol called ‘WS2812’. More accurately, WS2811 is the name of the control IC, and WS2812 was the first evolution of that IC integrated into an LED package. However, it has become synonymous with the LEDs and the control system as a whole. The originator is the WorldSemi company, and many compatible versions now exist. WS2812B is the current version of a WS2811 IC integrated into an LED package. Prior to integration, WS2811 ICs were mounted separately, usually on the LED strip. These are largely redundant now and hard to find, but are easy to identify, thanks to the small black ICs between the LEDs. WS2812B LEDs have the tiny driver IC mounted on the middle of the LED dies.
Regardless of the physical format, WS2812 works by sending a string of serial data which must pass through every LED to the end. The first LED uses the first 24-bit packet, then conditions the rest and sends it out to the next LED, which uses the second packet, and so on. There is no data return to the microcontroller. The number of LEDs must be correctly entered into the set-up of the code in order for the system to work. Also set is the frequency of updates, which is important for displays and long runs. Although called a ‘single-wire’ system, there are always four pins on a WS2812-based LED: Ground, Positive Voltage, Data In, and Data Out. Data must pass through each LED, it is not a continuous bus system. It should be noted that some SMD 5050 packages have six pins, but these are usually double-ups of existing functions such as power, or non-connected legacies of the physical package design's use for other LED types. The original WS2812 LEDs used a six-pin connection.
The data sent contains the information for the colour and brightness of each die of each LED in the string. Each IC responds to the data for its position in the string. This means that every single LED can have a different setting to the one next to it, even if there are one thousand of them. This is why WS2812 has been so popular with makers, as effects like meteor, rainbow, colour-cycling, and many, many more can be generated. WS2812 libraries generally default to a frequency of 400 Hz, which is the standard for the IC refresh rate. However, many 800 Hz versions now exist, so check the datasheets for your particular LEDs or strip.
More recently, WS2813 has arrived. This responds to the same code as WS2812 and WS2812B, but has a much higher frequency of 2000 Hz, and two data wires. In standard WS2812, if anything goes wrong with a control IC (as usually happens when they are integrated into an LED that has experienced catastrophic failure or drastic overheating), every LED after that point no longer works. The wiring configuration for WS2813 means that two LEDs immediately next to each other have to fail for the rest of the string to stop working. A single failure will now result in the equivalent of a dead pixel.
The other main contender is APA Electronic Co’s APA102C protocol. These are also an LED packing with driver IC built in. We haven’t found the ICs for sale individually, and few makers want them that way anyway. The individual 5050 LEDs with APA102C driver are available, as is the more familiar LED strip. In any case, APA102C differs from single-wire interface in utilising hardware-based Serial Peripheral Interface (SPI). This has advantages in that many microcontrollers have dedicated SPI hardware that does not take up system resources, or have efficient systems to minimise resource drain when achieving SPI with non-dedicated hardware.
Outwardly, APA102C strips will look much like WS2812 versions, except for the number of pins. There will still be a Data In and Data Out (DI and DO) pin, but there will also be a Clock In and Clock Out (CI and CO). DI and DO are the Master Out Slave In (MOSI) and Master In Slave Out (MISO) connections from regular SPI communication, but are usually abbreviated to DI and DO on the strips for the sake of space. The LED packages themselves generally have eight pins - the two upper pins are Vcc, the two lower are GND. In the middle, CI and DI will be on the left, and CO and DO on the right. There are variations, particularly with clones.
SPI is simple in concept but a condensed explanation of how to implement it with Arduino or Raspberry Pi turned into an unintelligible exercise in futility, so that will be in the next installment as well. For now, if you are already familiar with SPI, APA102C is worth considering.
RBGW, RGBWW, AND WWA
Mainly in WS2812, but sometimes with APA102C as well, there are other versions beside the standard RGB. The most common involves the installation of a white LED in addition to the three colour dies. These LEDs are fairly easy to spot, as the white LEDs almost always feature a phosphor coating and are usually larger. RGBW is Red, Green, Blue, White; while RGBWW is usually Red, Green, Blue, Warm White. However, be careful and check the datasheets.
Sometimes, the RGBWW LEDs are actually Red, Green, Blue, White, and warm White, having a total of five dies, two of them white at different colour temperatures. Most of the current WS2812 libraries getting around are able to support the extra white chip, but challenges may be met while trying to use the two white chips. We also found some strips with separate white LEDs entirely, and we’re not sure how these are addressed.
In a similar vein, WWA stands for White, White, Amber. These feature a white die at the higher colour temperatures bordering on blue, one somewhere in the middle, and an amber die that is able to ‘warm up’ the colour temperature. In theory, they are controllable with standard WS2812 protocols, as the PWM value between 0 and 255 has no idea whether it’s really driving a red, blue, or green die - the number is just sent to die number one, then another number is sent to die number two, and the same for die three. We’re currently looking for a good source of this stuff, so watch this space when we come back for a full article on WS2812.
If there’s one thing modern makers can be sure of when it comes to standards, it’s that there aren’t any. In every case we can think of, there is a manufacturer who either thinks they have a better way of doing something, or could not be bothered paying for consistency. When it comes to digital RGB LEDs, things tend to be pretty consistent with known brands.
However, unbranded or lesser-known brands sometimes suffer from having the LED dies arranged differently. If the code is addressed expecting Red, Green, and Blue, but the dies are arranged or the IC connected to give Green, Blue, Red, then the response from the LED will be a completely different colour than expected. Nothing will break, except maybe your grand plans. If you are working with any batch of unknown LEDs, it pays to connect one, and address the colours one at a time to make sure the colour expected from the code is the colour seen.
The other main difference between manufacturers is brightness. If a manufacturer takes little care with die choice, brightness will vary between the colours in a way that is perceivable. Remember, the human eye does not respond to all colours equally, with green being the colour the eye is most sensitive to. Often, even among the better brands, the green chip is brighter when measured in candela.
This is a consideration if you want to achieve a certain light level with a certain colour, and will need to be considered when trying to achieve white light. It is unlikely that turning on all three dies at full brightness will create white light. With analog RGB LEDs, resistor values can be chosen to compensate for this to a reasonable degree. With Digital RGB LEDs, this compensation has to be in code.
Finally, the wavelength of the LED dies can vary. There is no one set standard baseline wavelength for the RGB standards, even when used in photography. Red, for example, extends from around 740nm for a dull brownish-red, to 620nm for a very orange red. A ‘red’ die may emit light anywhere on this spectrum, so consulting the datasheets of the catalogue listing does not specify the wavelength of each chip.
While WS2812 and APA102C are the two most common digital RGB LEDs, there are others. Many are variations of the same, but there are some that are completely different. SK6812 is a good example of the former: It behaves as a WS2812 LED in coding, but can cope with a 1200Hz refresh rate and has a white die by default, making it an RGBW LED. There are doubtless others, but if you examine them closely, they usually turn out to be based on one of the two major protocols.
The other kind of RGB LED you may come across in searches is the self-contained variety. This means that there is a pre-loaded controller built into the LED instead of a digital processor like a WS2812, or separate pins for analog. These LEDs usually only have two connections, for power, and a set program. Most commonly, they sequence between colours. Some fade slowly between colours, some switch abruptly between colours, and others fade to nothing between colour changes. Sometimes, you’ll even trip across one that has multiple functions, but they’re still preset and you cannot choose. These LEDs are great on their own, but cannot be massed. Even LEDs from the same batch will have slightly different timing and so cannot be synchronised even if powered on at the same time.
There is also one other variety of analog LED that needs to be mentioned. While many analog RGB LEDs on the domestic market are either common anode or common cathode, some have all pins of all dies accessible. They are three LEDs with their own anodes and cathodes accessible. We didn't spend any time on these because you would treat them just like three physically separate LEDs. You get to choose whether you drive the device from a high side transistor or low side transistor, a choice you do not have with common-terminal version.
The close-up photo of the SMD LED on the third page is actually an independent LED, but it is mounted on a PCB as an Arduino module with all the cathodes to one pin, meaning the module is treated as a common cathode LED. Of you look at the star type LED in the assortment photo, you can see that it has six separate pins, too.
Make sure you take note when buying RGB LEDs that you are getting something that will suit your needs. Sometimes the details are not obvious.
Please note that no supplier has paid to be mentioned here. For the record, suppliers don’t pay to have reviews, either. They send a product (or sometimes we just buy it because we want to!) and we review honestly.
The reason you rarely read negative reviews in DIYODE is that if a product doesn’t meet our expectations, we give the supplier a chance to fix it, then we choose not to acknowledge the existence of that product. The same goes for suppliers we use in our projects: If we list a supplier, they may not be the only ones, but we have dealt with them and been happy with them.
There are many ways you can buy RGB LEDs, but we very much like supporting genuine Australian businesses where we can. We have always tried to use supplies from over-the-counter national retailers where possible, because a maker can go down to their local store on a Sunday afternoon and walk away with the goods instead of waiting for a parcel. Unless, of course, if you’re in lockdown, as we were while this issue was being produced.
Core Electronics have often been in the mix, too, as they have an extensive range of products and rapid postage times. Again, lockdown has changed that with a heavy freight load stretching delivery times. Sometimes, however, online retailers can do things that chain retailers just cannot, because of scale versus demand.
Jaycar has a 5mm diffused common cathode analog RGB LED, plus several digital options either in strips or single PCB mountings. Altronics has a common anode 5mm LED plus a similar offering of digital versions. When it comes to digital versions, Pakronics and Core Electronics really dominate. There is a huge variety of strip, PCB, and individual digital LEDs and some analog options from both, in generic brands as well as Sparkfun, Adafruit, and SeeedStudio.
Very worth looking up is LEDsales, an independent small business that we buy from regularly. LEDsales have, in particular, a good range of analog RGB LEDs in both common cathode and common anode versions of the same LED, as well as a healthy digital offering. There are also a great many non-RGB products that you won’t find elsewhere without risking the unknown sellers from online marketplaces.
Hands-on: Analog RGB LED operation
|Parts Required:||Jaycar||Altronics||Core Electronics|
|2 x Solder Breadboard||HP9570||H0701 #||ADA1609|
|1 x Pack of Breadboard Wire Links||PB8850||P1014A||SS110990044|
|4 x 100Ω Resistors *||RR0548||R7534||DF-FIT0119|
|2 x 150Ω Resistor *||RR0552||R7538||DF-FIT0119|
|6 x 1kΩ Resistors *||RR0572||R7558||DF-FIT0119|
|3 x BC327 PNP Transistors or equivalent||ZT2110||Z1030||DF-FIT0322|
|3 x BC337 NPN Transistors or equivalent||ZT2115||Z1035||DF-FIT0322|
|2 x Common Anode 10mm RGB LED||LEDsales: RGB4PINCA10MM||-||-|
|2 x Common Cathode 10mm RGB LED||LEDsales: RGB4PINCC10MM||-||-|
|14 x PCB Pins *||HP1250||H0804A||-|
|5 x Plug-to-Socket Jumper Wires * #||WC6028||P1021||SS110990045|
|1 x Arduino Uno or Compatible #||XC4410||Z6280||ARD-A000066|
# Common to both boards, used alternately.
* Quantity shown, may be sold in packs.
This build is aimed mainly at demonstrating the analog RGB LED because they’re less common in the maker world, and we firmly believe they deserve their own niche. While we see their greatest use in applications that are way outside this project, it still demonstrates the different approach taken to driving them with code. It’s little more than a transistor output stage bright RGB 10mm LED which draws, in most cases, more than the 20mA we can guarantee from an Arduino.
While the latest datasheets do specify a 40mA per pin and 200mA total, this hasn’t always been the case, and we cannot be assured everyone has current or genuine hardware. Additionally, that’s a 40mA max and really should not be treated as standard operating conditions. Because some RGB LEDs can draw up to 60mA per die, we’ll play it safe and use transistors. Besides that, it’s just an Arduino Uno and some code. We have used BC327 and BC337 transistors, good for a maximum of 800mA, but check the datasheets because some versions and brands are only good for 500mA. If you need more current, try revisiting the MOSFET circuit from Issue 32’s Classroom, but we are only thinking of one to a few LEDs for this project.
We originally designed the circuit based on the diagrams presented earlier, driven by high-side PNP transistors and NPN inverters, for 5mm common cathode LEDs. These are the ones sold by Jaycar, who is the closest retailer to our office. However, Altronics sells a common anode version, and online retailers often have both. In the end, we decided to go with two simpler builds, one with common cathode LEDs with high-side switching, and another with common anode LEDs and NPN transistors. We use code to cope with the fact that the PNP transistors required for high-side switching need to have their bases grounded in order to conduct.
This means driving the output pins high when the LED is to be off, which we will do by reversing the PWM value: a value of 0 will be fully on, while a value of 255 will be fully off. This way, if you have a common anode LED that needs low-side switching, all you need to do is change the BC328 transistors for BC338s, and swap the numbers in the code. If we built the inverter circuit for high-side switching from a high control signal, hardware changes would be needed to convert to low-side switching.
Assembly is fairly simple and does not warrant step-by-step instructions. Just be careful to follow the wiring diagram. Because we have used solderable copies of the regular prototyping breadboards, there is no track cutting or fancy wire linking. Wire links present are just normal breadboard wire links.
Now, all that is left is to connect the jumpers to the Arduino, at pins 3, 9, and 10 (pins 5 and 6 have a different PWM rate so the test between colours may not be fair), and add 5V power. Also, our resistor values were calculated for our specific LED dies. Check the data for whatever device you buy, and your values may need to change.
The code is available to download from our website. As we’re doing more and more in Classroom, we’re not showing the code directly here, but rather using extensive comments within the code to explain its operation. This allows us to modify the code based on reader feedback, and our own continued experimentation, as well as fix mistakes, all without rendering this article obsolete. This only works for fairly simple code, but Classroom code usually is! You can get the code from our website.
Whether you use RGB LEDs in analog or digital form will depend on your needs and the criteria of the end use. Both formats are valid in different situations. While you’ll likely find a bigger variety of package styles in analog, this is changing and the field will likely be equal soon enough.
In a future issue of Classroom, we’ll unpack in more detail the ins and outs of WS2812 and APA102C operation, explaining each line of code, what parameter does what, and what effect it will have if you change it. We’ll also go through some of the common control functions and explain how they work, such as fading, rainbow, and theatre chase. So, watch this space.