{"id":52342,"date":"2026-11-01T10:50:59","date_gmt":"2026-11-01T10:50:59","guid":{"rendered":"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/"},"modified":"2026-11-01T10:50:59","modified_gmt":"2026-11-01T10:50:59","slug":"rgb-led","status":"publish","type":"siratek_tutorial","link":"https:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/","title":{"rendered":"Mixing Colours with an RGB LED"},"content":{"rendered":"<body><p><\/p>\n<h2>What it does<\/h2>\n<p>An RGB LED is three LEDs in one clear package, one red, one green, one blue, sharing a single common leg. Drive them at different brightnesses and the eye blends the result into one colour.<\/p>\n<p>It is the natural next step after a single LED, because it needs everything you already know applied three times, and it is the first part where PWM earns its place: without varying brightness you get seven fixed colours, and with it you get any of them.<\/p>\n<h2>Before you begin<\/h2>\n<h3>Required parts and tools<\/h3>\n<ul>\n<li>An Arduino Uno or compatible board.<\/li>\n<li>One 5 mm RGB LED with four legs.<\/li>\n<li>Three 220 ohm resistors. One per colour, not one for the lot.<\/li>\n<li>A breadboard and four jumper wires.<\/li>\n<\/ul>\n<h3>Four legs, and which is which<\/h3>\n<p>The <strong>longest leg is the common one<\/strong>, and it sits second from one end. The other three are red, green and blue, and on the usual arrangement the order is red, common, green, blue.<\/p>\n<p>Do not trust that order on a part you have not checked. Legs get trimmed, and suppliers differ.<\/p>\n<h3>Common anode or common cathode<\/h3>\n<p>This is the one thing that matters and the one thing a photograph cannot tell you. The two kinds look identical.<\/p>\n<ul>\n<li><strong>Common cathode:<\/strong> the shared leg goes to <code>GND<\/code>, and a pin set HIGH lights its colour.<\/li>\n<li><strong>Common anode:<\/strong> the shared leg goes to <code>5V<\/code>, and a pin set LOW lights its colour.<\/li>\n<\/ul>\n<p>Test it in ten seconds, with the board unplugged from nothing more than your patience:<\/p>\n<ol>\n<li>Put a 220 ohm resistor in series with a jumper from <code>5V<\/code>.<\/li>\n<li>Touch the common leg to <code>GND<\/code>, and touch the resistor lead to one of the other three.<\/li>\n<li>If it lights, you have a <strong>common cathode<\/strong>.<\/li>\n<li>If not, swap: common leg to <code>5V<\/code> through the resistor, other leg to <code>GND<\/code>. If it lights now, it is a <strong>common anode<\/strong>.<\/li>\n<\/ol>\n<p>The rest of this tutorial is written for a common cathode. If yours is a common anode, the wiring changes only in where the common leg goes, and the sketch needs every value inverted. Both are shown.<\/p>\n<h3>One resistor per colour<\/h3>\n<p>A single resistor on the common leg seems tidy and is wrong. The three colours have different forward voltages, so they would draw different currents through one shared resistor, and the brightness of each would change depending on which others were lit. Colours would shift as you mixed them.<\/p>\n<p>Three resistors, one in each colour leg, keeps each channel independent.<\/p>\n<h2>Pin reference<\/h2>\n<table>\n<thead>\n<tr>\n<th>Pin or label<\/th>\n<th>Connect to<\/th>\n<th>Purpose<\/th>\n<th>Notes<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Red leg<\/td>\n<td><code>D9<\/code> through 220 ohms<\/td>\n<td>Red channel<\/td>\n<td>PWM pin<\/td>\n<\/tr>\n<tr>\n<td>Common, the longest leg<\/td>\n<td><code>GND<\/code><\/td>\n<td>Shared return<\/td>\n<td><code>5V<\/code> instead, on a common anode<\/td>\n<\/tr>\n<tr>\n<td>Green leg<\/td>\n<td><code>D10<\/code> through 220 ohms<\/td>\n<td>Green channel<\/td>\n<td>PWM pin<\/td>\n<\/tr>\n<tr>\n<td>Blue leg<\/td>\n<td><code>D11<\/code> through 220 ohms<\/td>\n<td>Blue channel<\/td>\n<td>PWM pin<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>All three must be PWM pins, or you lose colour mixing and get only the eight on-off combinations. Pins 9, 10 and 11 are convenient and adjacent. Note that <code>tone()<\/code> would take 11 away, so a project with sound should use 3, 5 or 6 instead.<\/p>\n<figure class=\"siratek-tutorial-figure\"><img decoding=\"async\" src=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/rgb-led-wiring.svg\" alt=\"An RGB LED with each colour leg fed through its own 220 ohm resistor from pins 9, 10 and 11, and the common leg to ground\" loading=\"lazy\"><figcaption>One resistor per colour, not one on the common leg.<\/figcaption><\/figure>\n<h2>Wiring steps<\/h2>\n<ol>\n<li>Unplug the USB cable.<\/li>\n<li>Place the LED with each leg in its own row.<\/li>\n<li>Run the common leg to <code>GND<\/code>, or to <code>5V<\/code> if your part is a common anode.<\/li>\n<li>Put a 220 ohm resistor from the red leg\u2019s row to a free row, and wire that row to <code>D9<\/code>.<\/li>\n<li>Repeat for green to <code>D10<\/code> and blue to <code>D11<\/code>.<\/li>\n<li>Check that no two legs share a row.<\/li>\n<li>Plug the USB cable back in.<\/li>\n<\/ol>\n<h2>Software and libraries<\/h2>\n<p>No library is required.<\/p>\n<h2>Minimal working example<\/h2>\n<pre><code>\/\/ Siratek: mixing colours on an RGB LED.\n\/\/ Written for a common cathode. See the note below for a common anode.\n\nconst int redPin = 9;\nconst int greenPin = 10;\nconst int bluePin = 11;\n\nvoid setColour(int red, int green, int blue) {\n  analogWrite(redPin, red);\n  analogWrite(greenPin, green);\n  analogWrite(bluePin, blue);\n}\n\nvoid setup() {\n  pinMode(redPin, OUTPUT);\n  pinMode(greenPin, OUTPUT);\n  pinMode(bluePin, OUTPUT);\n\n  Serial.begin(9600);\n  Serial.println(\"Siratek: RGB LED starting.\");\n}\n\nvoid loop() {\n  Serial.println(\"red\");\n  setColour(255, 0, 0);\n  delay(1000);\n\n  Serial.println(\"green\");\n  setColour(0, 255, 0);\n  delay(1000);\n\n  Serial.println(\"blue\");\n  setColour(0, 0, 255);\n  delay(1000);\n\n  Serial.println(\"yellow\");\n  setColour(255, 255, 0);\n  delay(1000);\n\n  Serial.println(\"white\");\n  setColour(255, 255, 255);\n  delay(1000);\n\n  Serial.println(\"off\");\n  setColour(0, 0, 0);\n  delay(1000);\n}<\/code><\/pre>\n<h3>For a common anode<\/h3>\n<p>Everything inverts: 255 becomes off and 0 becomes full. Change one function and leave the rest of the sketch alone.<\/p>\n<pre><code>void setColour(int red, int green, int blue) {\n  analogWrite(redPin, 255 - red);\n  analogWrite(greenPin, 255 - green);\n  analogWrite(bluePin, 255 - blue);\n}<\/code><\/pre>\n<p>Writing it this way means the rest of your code still asks for the colour it wants, and only one place knows which kind of LED is fitted.<\/p>\n<h2>Expected result<\/h2>\n<p>Six states, a second each: red, green, blue, yellow, white, off.<\/p>\n<p>Two things are normal. The white will not be a clean white, because the three dies have different efficiencies and the eye is most sensitive to green; a believable white usually needs the red and green pulled back, something like <code>setColour(255, 180, 140)<\/code>, found by eye for your part.<\/p>\n<p>And the colours are mixed by your eye, not by the LED. Look closely and you can see the three separate dies inside the package.<\/p>\n<h2>Troubleshooting<\/h2>\n<table>\n<thead>\n<tr>\n<th>Symptom<\/th>\n<th>Likely cause<\/th>\n<th>Check or fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Nothing lights at all<\/td>\n<td>Common leg not connected<\/td>\n<td>Check it reaches <code>GND<\/code>, or <code>5V<\/code> for a common anode<\/td>\n<\/tr>\n<tr>\n<td>Colours are inverted<\/td>\n<td>Wrong type assumed<\/td>\n<td>Use the inverting <code>setColour()<\/code><\/td>\n<\/tr>\n<tr>\n<td>Lit when it should be off<\/td>\n<td>Common anode driven as common cathode<\/td>\n<td>Same fix as above<\/td>\n<\/tr>\n<tr>\n<td>Only one colour works<\/td>\n<td>Two legs sharing a breadboard row<\/td>\n<td>Give each its own row<\/td>\n<\/tr>\n<tr>\n<td>No mixing, only solid colours<\/td>\n<td>Not all three on PWM pins<\/td>\n<td>Use 3, 5, 6, 9, 10 or 11<\/td>\n<\/tr>\n<tr>\n<td>Brightness shifts as colours mix<\/td>\n<td>One resistor on the common leg<\/td>\n<td>Fit one resistor per colour<\/td>\n<\/tr>\n<tr>\n<td>Blue much dimmer than expected<\/td>\n<td>Higher forward voltage<\/td>\n<td>Expected; lower the red and green instead<\/td>\n<\/tr>\n<tr>\n<td>Blue stops working with sound<\/td>\n<td><code>tone()<\/code> has taken pin 11<\/td>\n<td>Move that channel to 3, 5 or 6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Next steps<\/h2>\n<ul>\n<li><strong>Easier first:<\/strong> <em>Your First Circuit, an LED and a Resistor<\/em>.<\/li>\n<li><strong>Related:<\/strong> <em>Dimming and Speed Control with PWM<\/em>, which explains what <code>analogWrite()<\/code> is doing.<\/li>\n<li><strong>Next project:<\/strong> drive the colour from a potentiometer, or use it as a status light that goes green, amber and red from a sensor reading.<\/li>\n<\/ul>\n<h2>Sources and attribution<\/h2>\n<p>All text, wiring guidance and code in this tutorial are original Siratek work.<\/p>\n<ul>\n<li>Arduino core documentation for <code>analogWrite()<\/code>.<\/li>\n<\/ul>\n<p>Leg order and the common-anode or common-cathode type vary between suppliers, so this tutorial gives a test rather than asserting either. No third-party tutorial text, diagrams, photographs or code has been reproduced here.<\/p>\n<p><\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>An RGB LED is three LEDs in one clear package, one red, one green, one blue, sharing a single common leg. Drive them at different brightnesses and the eye blends the result into one colour.<\/p>\n","protected":false},"featured_media":0,"template":"","siratek_tutorial_level":[],"class_list":["post-52342","siratek_tutorial","type-siratek_tutorial","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Mixing Colours with an RGB LED - siratek<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mixing Colours with an RGB LED - siratek\" \/>\n<meta property=\"og:description\" content=\"An RGB LED is three LEDs in one clear package, one red, one green, one blue, sharing a single common leg. Drive them at different brightnesses and the eye blends the result into one colour.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/\" \/>\n<meta property=\"og:site_name\" content=\"siratek\" \/>\n<meta property=\"og:image\" content=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/rgb-led-wiring.svg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/rgb-led\\\/\",\"url\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/rgb-led\\\/\",\"name\":\"Mixing Colours with an RGB LED - siratek\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/siratek.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/rgb-led\\\/#primaryimage\"},\"image\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/rgb-led\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/rgb-led-wiring.svg\",\"datePublished\":\"2026-11-01T10:50:59+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/rgb-led\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/rgb-led\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/rgb-led\\\/#primaryimage\",\"url\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/rgb-led-wiring.svg\",\"contentUrl\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/rgb-led-wiring.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/rgb-led\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/siratek.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials\",\"item\":\"https:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Mixing Colours with an RGB LED\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/siratek.net\\\/#website\",\"url\":\"https:\\\/\\\/siratek.net\\\/\",\"name\":\"siratek\",\"description\":\"Your Best Electronic Retail Shop\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/siratek.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mixing Colours with an RGB LED - siratek","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/","og_locale":"en_US","og_type":"article","og_title":"Mixing Colours with an RGB LED - siratek","og_description":"An RGB LED is three LEDs in one clear package, one red, one green, one blue, sharing a single common leg. Drive them at different brightnesses and the eye blends the result into one colour.","og_url":"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/","og_site_name":"siratek","og_image":[{"url":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/rgb-led-wiring.svg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/","url":"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/","name":"Mixing Colours with an RGB LED - siratek","isPartOf":{"@id":"https:\/\/siratek.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/#primaryimage"},"image":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/#primaryimage"},"thumbnailUrl":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/rgb-led-wiring.svg","datePublished":"2026-11-01T10:50:59+00:00","breadcrumb":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/#primaryimage","url":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/rgb-led-wiring.svg","contentUrl":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/rgb-led-wiring.svg"},{"@type":"BreadcrumbList","@id":"http:\/\/siratek.net\/index.php\/tutorials\/rgb-led\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/siratek.net\/"},{"@type":"ListItem","position":2,"name":"Tutorials","item":"https:\/\/siratek.net\/index.php\/tutorials\/"},{"@type":"ListItem","position":3,"name":"Mixing Colours with an RGB LED"}]},{"@type":"WebSite","@id":"https:\/\/siratek.net\/#website","url":"https:\/\/siratek.net\/","name":"siratek","description":"Your Best Electronic Retail Shop","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/siratek.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial\/52342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial"}],"about":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/types\/siratek_tutorial"}],"version-history":[{"count":0,"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial\/52342\/revisions"}],"wp:attachment":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/media?parent=52342"}],"wp:term":[{"taxonomy":"siratek_tutorial_level","embeddable":true,"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial_level?post=52342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}