Same-day dispatch before 2 PM · Free delivery over ₹999 · GST invoices Get the appPrices incl. GST
Geekobot
Snap & SendNEWGeeko AIWhere's myOrder
Log in
Products
  • Projects
    • Component guidesHow parts work, with code you can run
    • Learning pathsFrom your first LED to your first robot
    • Workshops & eventsOnline sessions for makers and classes
    • ElectrolarkFree guided builds, simulator and certificates
    • Students & teachersStudent discount and classroom help
    • CommunityShare builds and ask other makers
    • CalculatorsOhm's law, LED resistor, 555 and 100+ more
    • Circuit builderWire parts and run the circuit, powered by Electrolark
    • Geeko AIAsk what to buy or how to wire it
    • Snap & SendPhotograph a part or list, we find it
    • Part finderAnswer a few questions, get the right part
    • Compatibility checkWill these two parts work together?
    • Compare partsSpecs side by side
    • Business & bulk ordersGST invoices, credit and volume prices
    • Request a quotationSend your list, get a quote
    • Classroom kitsPer-student kits and lab bundles
    • Gift cardsFor students, teams and events
  • Atal Tinkering Lab
BOM to cart
Geekobot

Components, kits and know-how for makers, students, engineers, labs and businesses across India.

Ask Geeko AIOrders, parts and projects, any timeEmail supportReply within 1 working dayGet the Geekobot appAdd it to your home screen, free

Follow us

Shop

  • Boards & SBCs
  • Sensors & Modules
  • IoT & Wireless
  • Drone & FPV
  • 3D Printing
  • Filaments & Resins
  • Motors & Drivers
  • Power & Batteries
  • Semiconductors
  • Passive
  • Displays & LEDs
  • Switches & Relays
  • Wires & Cables
  • Prototyping
  • Tools & Test
  • Robotics
  • STEM Kits
  • Atal Tinkering Lab
  • Mechanical Parts
  • Audio

Orders

  • Track your order
  • Help & support
  • Shipping and delivery
  • Refunds and cancellation
  • Contact us

Learn

  • Projects
  • Geeko AI project assistant
  • Learning paths
  • Guides
  • Calculators
  • Electrolark: free guided builds

Part tools

  • Part finder
  • Compare parts
  • Will it work with my board?

Institutions

  • Classroom kits
  • Atal Tinkering Lab
  • Students & teachers
  • Workshops & Events

Business

  • Business & education
  • Request a quotation
  • BOM bulk upload
  • Quick order by SKU

Company

  • About Geekobot
  • Community
  • Gift cards
  • Terms & conditions
  • Privacy policy
  • Product directory
  • Sitemap

© 2026 Geekobot, a trade name of OLatus Systems Private Limited. All rights reserved.

20, 1st Floor, Neeladri Complex, 10th Cross, Sampige Rd, 2nd Main, Malleshwaram, Bengaluru, Karnataka 560003 · GSTIN 29AACCO0462F1ZM

+91 91810 15607 · connect@geekobot.in · Monday to Saturday, 10 AM to 2 PM IST

UPI · CARDS · NETBANKING · GST INVOICES

ShopProjectsGeeko AIGuides
Compare 0 parts →
Log in

Shop by category

Shop all components
  • Boards & SBCs1,910 products
    • Alternative Single Board Computers
    • Arduino Ecosystem
    • FPGA & Logic Boards
    • Microcontroller & Wireless Boards
    View all
  • Sensors & Modules4,701 products
    • Biomedical & Heart Rate
    • Current, Voltage & Power
    • Force, Weight & Pressure
    • Gas, Weather & Environmental
    View all
  • IoT & Wireless2,314 products
    • RF Modules
    • RFID & NFC
    • Antennas & RF Accessories
    • Cameras & Smart Vision
    View all
  • Drone & FPV3,558 products
    • Flight Control & Navigation
    • FPV Video & Optics
    • Frames & Structural Parts
    • Motors & Propulsion
    View all
  • 3D Printing2,204 products
    • 3D Printers
    • 3D Scanners & Digitizers
    • Laser Engravers & Cutters
    • Material Management & Upgrades
    View all
  • Filaments & Resins1,472 products
    • Filaments
    • Photopolymer Resins
    View all
  • Motors & Drivers463 products
    • BLDC Motor Drivers
    • DC & Geared Motors
    • DC Motor Drivers
    • Linear Actuators & Solenoids
    View all
  • Power & Batteries557 products
    • Battery Holders & Connectors
    • Breadboard Power
    • Chargers & BMS
    • DC-DC Converters
    View all
  • Semiconductors295 products
    • Diodes & Rectifiers
    • Interface & RF Encoder ICs
    • Logic ICs (74xx)
    • Logic ICs (CD4000)
    View all
  • Passive67 products
    • Capacitors
    • Circuit Protection
    • Crystals & Oscillators
    • Inductors
    View all
  • Displays & LEDs572 products
    • 7-Segment & Dot Matrix
    • Addressable LEDs
    • Character LCDs
    • Graphic LCDs
    View all
  • Switches & Relays184 products
    • Keypads & Touch
    • Push Buttons & Tactile
    • Relay Modules
    • Relays
    View all
  • Wires & Cables233 products
    • Board-to-Wire Connectors
    • Crimp & Splice
    • Headers & Dupont
    • Heat Shrink & Sleeving
    View all
  • Prototyping101 products
    • Breadboards
    • Interface Modules
    • PCBs & Perfboards
    View all
  • Tools & Test717 products
    • Bench Power Supplies
    • Hand Tools
    • Measuring Tools
    • Meters & Testers
    View all
  • Robotics180 products
    • Humanoid & Legged Robots
    • Robot Chassis & Platforms
    • Robotic Arms & Grippers
    • Wheels & Casters
    View all
  • STEM Kits268 products
    • Arduino Learning Kits
    • Coding & IoT Kits
    • Early Coding (Ages 3-8)
    • Invention Kits
    View all
  • Atal Tinkering Lab196 products
    • Package 1: Electronics, Robotics, IoT and Sensors
    • Package 2: Rapid Prototyping Tools
    • Package 3: Mechanical, Electrical and Measurement Tools
    • Package 4: Power Supply, Accessories and Safety Equipment
    View all
  • Mechanical Parts212 products
    • Bearings
    • Brackets & Mounts
    • Couplers
    • Fasteners & Standoffs
    View all
  • Audio109 products
    • Amplifier Modules
    • Buzzers & Sirens
    • Speakers
    View all
  1. Home
  2. ›Guides
  3. ›Displays & LEDs
  4. ›RGB LEDs
Step 2 of 17 in Displays and lightsPart of a learning path.
Next

How-to · Beginner · 3 min read

RGB LEDs

Common Anode vs Common Cathode, Resistors and Colour Mixing

By Geekobot Learning Team · Updated 24 Oct 2026

I'm using
Wiring, code and the Run it panels follow your board.
On this page
Short answerCommon anode or common cathode? How to tellChoosing resistor valuesArduino code for colour mixingESP32 and Pico notesPlain RGB LED or WS2812 addressable LED?Try itCommon mistakesFAQsParts and next steps
Short answer

An RGB LED is three LEDs (red, green, blue) in one package with a shared fourth pin, the longest leg. On a common-cathode LED that pin goes to ground and you drive each colour HIGH; on a common-anode LED it goes to the supply and you drive each colour LOW. Give each colour its own resistor on a PWM pin, and mix any colour by setting the three duty cycles.

Key specs at a glance

Pins
4: R, common, G, B (longest leg is common)
Forward voltage
Red about 2.0 V; green and blue about 3.0 to 3.2 V
Current
20 mA per colour maximum for 5 mm LEDs; 5 to 10 mA is plenty
Resistors at 5 V
About 150 Ω red, 100 Ω green and blue for 20 mA; 220 to 330 Ω for 10 mA
Control
Three PWM pins
Common anode
Logic inverted: 0 = full on, 255 = off
01

Common anode or common cathode? How to tell

Look for the longest leg; it is the common pin. Connect it to GND, then touch one of the other legs to 3.3 V or 5 V through a 220 Ω resistor. If a colour lights, it is common cathode. If not, connect the long leg to the supply and touch the other legs to GND through the resistor: if it lights now, it is common anode. A multimeter's diode test does the same job.

02

Choosing resistor values

Each colour needs its own resistor because red has a lower forward voltage than green and blue. Using Ohm's law, R = (Vsupply - Vf) / I:

Red at 5 V, 10 mA

(5 - 2.0) / 0.010 = 300 Ω, so use 330 Ω.

Green or blue at 5 V, 10 mA

(5 - 3.1) / 0.010 = 190 Ω, so use 220 Ω.

At 3.3 V (ESP32, Pico)

blue and green have only about 0.2 V of headroom, so use 33 to 68 Ω and expect dimmer blue, or use a 5 V supply with transistors.

Many tutorials use 220 Ω on all three; it works, but the colours will not be balanced. Fine-tune white balance in code instead. The LED resistor calculator does the arithmetic.

03

Arduino code for colour mixing

Use three PWM pins (marked ~ on an Uno).

Set any colour on an RGB LED · Arduino C++Verify & upload in Electrolark
const int R = 9, G = 10, B = 11;
const bool COMMON_ANODE = false;   // set true for common-anode LEDs

void setColor(int r, int g, int b) {
  if (COMMON_ANODE) { r = 255 - r; g = 255 - g; b = 255 - b; }
  analogWrite(R, r);
  analogWrite(G, g);
  analogWrite(B, b);
}

void setup() {
  pinMode(R, OUTPUT); pinMode(G, OUTPUT); pinMode(B, OUTPUT);
}

void loop() {
  setColor(255, 0, 0);   delay(700);   // red
  setColor(0, 255, 0);   delay(700);   // green
  setColor(0, 0, 255);   delay(700);   // blue
  setColor(255, 120, 0); delay(700);   // orange
  setColor(128, 0, 255); delay(700);   // purple
}
04

ESP32 and Pico notes

On the ESP32 with Arduino core 3.x, analogWrite() works on most output pins; on older cores, use ledcAttach(pin, 5000, 8) and ledcWrite(pin, value). On the Pico, any GPIO can do PWM. Both are 3.3 V, so pick small resistors for green and blue (see above). For brighter or larger RGB LEDs and strips, switch each colour with a logic-level MOSFET; see transistors and MOSFETs and PWM.

05

Plain RGB LED or WS2812 addressable LED?

A plain RGB LED needs three PWM pins and three resistors per LED, so it suits one or two status lights. A WS2812B has a controller chip inside: hundreds can be chained on one data pin, each set to any colour. For anything more than two or three colour LEDs, addressable LEDs are simpler.

06

Try it: LED resistor calculator

Change the values and the diagram and results update as you type.

07

Common mistakes to avoid

  • !Using one shared resistor on the common pin, so colours change brightness as others turn on.
  • !Forgetting to invert values for common-anode LEDs.
  • !Using non-PWM pins and getting only on or off.
  • !Driving green and blue at 3.3 V with 220 Ω and wondering why they are dim.
  • !Looking straight into a bright LED at full current.
08

Frequently asked questions

How do I know if my RGB LED is common anode or common cathode?

Connect the longest leg to ground and touch another leg to 5 V through a 220 Ω resistor. If it lights, it is common cathode; if not, it is probably common anode.

What resistor should I use for an RGB LED?

At 5 V, about 330 Ω for red and 220 Ω for green and blue gives roughly 10 mA each. Use one resistor per colour.

How do I make white with an RGB LED?

Turn all three colours on. Because the colours have different brightness, you may need to reduce red or green in code to get a neutral white.

Can I connect an RGB LED without resistors?

No. Without resistors the current is limited only by the pin, which can damage both the LED and the microcontroller.

Why does my RGB LED show the wrong colours?

The pin order differs between makers. Check which leg is which colour by testing each one, then change the pin numbers in code.

Parts for this guide

  • Through-Hole LED Pack (Pack of 10)
    ₹15View
  • Resistor Assortment Kit (30 Values)
    ₹33View
  • WS2812 RGB LED Ring
    ₹233View
  • Solderless Breadboard
    ₹68View
Shop LEDs & IndicatorsShop Addressable LEDs

Calculators

LED resistor calculatorPWM duty cycle calculator

Terms in this guide

Common anodeA 7-segment or RGB LED where all anodes share one pin connected to the supply, and each segment is lit by pulling its cathode LOW.Common cathodeA 7-segment or RGB LED where all cathodes share one pin connected to ground, and each segment is lit by driving its anode HIGH.Forward voltageThe voltage a diode or LED drops when conducting: about 0.7 V for silicon diodes, 1.8 to 3.3 V for LEDs.PWMPulse-width modulation: switching a signal on and off quickly so its average sets brightness, speed or position.Duty cycleThe percentage of time a PWM signal is high. 50% duty is on half the time.Anode and cathodeThe anode is the positive terminal of a diode or LED and the cathode the negative. Current flows from anode to cathode.

Projects that use it

Put this into practice: 367 step-by-step builds in our project library use parts from this guide.

Beginner · 1 hourLPG gas leak alarmView projectBeginner · 45 minutesFlame detector fire alarmView projectBeginner · 1 hourPIR intruder alarmView project
Browse all 367 projects

Keep learning

Component guideBeginnerLEDs ExplainedAn LED (light-emitting diode) lights when current flows from its longer leg (anode, +) to its shorter leg (cathode, -).3 min read · Displays & LEDsHow-toIntermediateWS2812B Addressable LEDs (NeoPixel)WS2812B LEDs (often called NeoPixels) contain a red, green and blue LED plus a tiny controller, so each LED on a strip can be set to any colour from one data pin.3 min read · Displays & LEDsConcept explainerBeginnerPWM ExplainedPWM (pulse-width modulation) switches a pin fully on and off very quickly; the share of time it is on, the duty cycle, sets the average power.3 min read · Electronics FundamentalsHow-toBeginner7-Segment DisplaysA 7-segment display is seven LEDs (plus a decimal point) arranged as a figure 8.3 min read · Displays & LEDs

Sources

  • Typical 5 mm RGB LED datasheets (forward voltage and current ratings)
  • Arduino analogWrite and ESP32 LEDC documentation

Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

On this page
Short answerCommon anode or common cathode? How to tellChoosing resistor valuesArduino code for colour mixingESP32 and Pico notesPlain RGB LED or WS2812 addressable LED?Try itCommon mistakesFAQsParts and next steps
Need a hand?Ask Geeko AI which part fits your project, or talk to the Geekobot team.Ask Geeko AIHelp & support

Parts for this guide4 items · ₹349

Through-Hole LED Pack (Pack of 10) · Resistor Assortment Kit (30 Values) · WS2812 RGB LED Ring · Solderless Breadboard

Run itChange the inputs and watch the output
setColor red 255,0,0
255 / 0 / 0Pins 9 / 10 / 11

A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.

Ask the Community

Ask a question