How to Control LED Strips With Arduino – Part 2: RGB LED Strips
by dziubym in Circuits > Arduino
366 Views, 5 Favorites, 0 Comments
How to Control LED Strips With Arduino – Part 2: RGB LED Strips

In Part 1, we learned how to control single-color LED strips using Arduino, MOSFETs, buttons, and potentiometers. Now in Part 2, we’re diving into RGB LED strips — how they work, how to wire them, and how to use Arduino to create vibrant, full-color lighting effects.
We’ll start with a single RGB LED segment directly powered by the Arduino and finish with a full-length RGB strip controlled via MOSFETs and external power, including smooth color transitions and PWM-based brightness control.
If you'd rather watch a step-by-step walkthrough, I've also made a video tutorial you can follow here:
Supplies
- Arduino Uno or Nano
- RGB LED strip (5V or 12V, common anode)
- 3 × N-channel MOSFETs (e.g., IRLZ44N)
- 3 × 220Ω resistors
- 3 × 10kΩ resistors
- Breadboard
- Jumper wires
- Potentiometer
- External power supply (5V or 12V depending on your strip)
- DC barrel jack adapter (female)
- Screw terminal block (optional)
Understanding RGB LED Strip Segments

Just like single-color strips, RGB LED strips are divided into cuttable segments. Each segment appears to contain one LED, but that “LED” is actually three tiny LEDs in one package: red, green, and blue.
Each channel (R, G, B) has its own resistor, which limits the current. The strip operates using common anode logic:
- 5V pad is shared positive
- Color channels are lit by connecting GND (LOW) to the R, G, or B pads
So to light red, you connect the R pad to GND while keeping G and B HIGH.
Wiring a Single RGB LED Segment to the Arduino


To begin, we’ll power just one segment of the RGB LED strip directly from the Arduino. This works because each channel only draws ~20mA, which is safe for a single pin.
🔌 Connections:
- 5V pad → Arduino 5V
- R pad → Arduino D6
- G pad → Arduino D9
- B pad → Arduino D3
🧠 Be aware: pad labels may be incorrect on cheaper strips. If color channels don’t behave as expected, swap pin assignments in code to match reality.
Simple Code to Cycle Primary Colors



We'll now cycle through red, green, and blue, one at a time.
🔍Code Highlights:
- Common anode strip means HIGH = off, LOW = on
- Colors are created by pulling just one pin LOW at a time
- Each color displays for 1 second
Mixing Colors Using PWM and AnalogWrite()


To create colors like yellow, magenta, cyan, or orange, we combine PWM signals on each channel.
🔧 Understanding PWM:
- analogWrite(pin, value) sets PWM signal
- value = 255 → fully off for common anode
- value = 0 → fully on
- Intermediate values control brightness
🎨 Example: Displaying Orange
Orange is made by mixing:
- Red = 255
- Green = 160
- Blue = 16
Invert for common anode:
- Red = 0
- Green = 95
- Blue = 239
With this approach, you can generate millions of colors using different combinations!
Now that you understand how PWM works and how we use it to mix brightness and color on common anode RGB LED strips, here’s a sketch that puts it all into practice.
What This Code Does:
- Defines 3 PWM pins for Red, Green, and Blue
- Stores 9 predefined RGB color values in a 2D array
- Uses a helper function setColorPWM() to:
- Invert values for common anode logic
- Apply the color using analogWrite()
- Loops through the entire color table, changing colors every 2 seconds
⚠️ Note: This code also takes into account the mislabeled color pads found on some cheaper RGB strips. In your case, the green and blue labels were swapped, so the GREEN_PIN and BLUE_PIN assignments reflect that correction. Always test your strip and adjust pin assignments as needed.
Controlling Longer RGB Strips With MOSFETs and External Power


When you're ready to move beyond a single RGB segment, powering a longer strip directly from Arduino pins is no longer safe. Each additional LED segment increases current demand, and Arduino’s I/O pins can only safely supply ~20 mA per pin — not nearly enough for a full RGB strip.
To solve this, we’ll use MOSFETs to switch higher currents from an external 5V or 12V power supply, while still using Arduino to control color and brightness with PWM.
🔧 How It Works
Each RGB channel (Red, Green, Blue) gets its own N-channel logic-level MOSFET, which switches that color's negative line (the R, G, or B pad) to GND. The Arduino sends a PWM signal to the gate of each MOSFET to control brightness.
🛠️ Wiring Overview:
🔌 Power:
- Power Supply +V → RGB strip 5V (or 12V) pad
- Power Supply GND → MOSFET source pins and Arduino GND
🟢 Red Channel (example):
- MOSFET Drain → R pad on LED strip
- MOSFET Source → GND
- Gate → Arduino pin 6 via 220Ω resistor
- Gate also → GND via 10kΩ pull-down resistor
Repeat the same structure for:
- Green → Arduino pin 3
- Blue → Arduino pin 9
🧠 This time, we are not inverting the PWM signal, because the MOSFET turns the strip’s color pads on/off with a HIGH signal, not LOW like before with direct control.
🎛️ Add a Potentiometer for Brightness Control
- Connect potentiometer center pin to A0 (analog input)
- Connect sides to 5V and GND
- We’ll read this value to scale the brightness dynamically in the next code step
✅ Benefits of This Setup:
- Power-hungry LED strips draw current from a dedicated supply, not your Arduino
- You can safely control dozens or even hundreds of RGB LEDs
- Full PWM color control remains, now with safe power handling
Next, I’ll walk you through the code for smooth color transitions and potentiometer-based brightness scaling. Ready to continue?
Smooth Color Transitions With Potentiometer Dimming

Now that your RGB strip is controlled via MOSFETs and external power, we can take full advantage of Arduino’s PWM features. The following code creates smooth color fades and lets you adjust brightness in real time using a potentiometer.
This is a big visual upgrade over basic color cycling — the transitions are smooth, subtle, and fully responsive to your input.
💻 Code
🔍 What This Code Does
- Cycles through a list of vibrant RGB colors
- Smoothly fades between each color using fadeToColor()
- Reads a potentiometer to control brightness live
- Uses analogWrite() to dim each channel based on scaled brightness
- Works with common cathode logic (no inversion) since we’re using MOSFETs to switch GND
⚠️ Note: This sketch accounts for a common hardware issue: the green and blue pads on some RGB strips are mislabeled. The GREEN_PIN and BLUE_PIN assignments are swapped to match actual behavior.
💡 Also important: Since we are now using MOSFETs to switch the color pads, we are driving the LEDs with a HIGH signal — not LOW as we did with the directly connected common anode setup. That means we no longer need to invert the PWM signals in the code. Just use the actual RGB values directly, as this sketch does.
Switching to a 12V RGB Strip (No Circuit Changes Needed!)


One of the best things about this MOSFET-based design is that it scales beautifully — including with 12V RGB strips. If you're ready to upgrade from 5V to 12V LEDs for longer runs, higher brightness, or simply because you have 12V strips on hand, you'll be happy to know that you don’t need to change the circuit at all.
🔧 What Stays the Same:
- The Arduino wiring and PWM control pins (D6, D3, D9)
- The MOSFET gate, drain, and source wiring
- The use of a common GND between Arduino and external power
- The potentiometer connection for brightness control
🔄 What You Do Need to Change:
- Swap the 5V power adapter for a 12V one
- Connect the 12V positive line to the RGB strip’s +V pad
- Power the Arduino through the VIN pin, not the 5V pin:
- The VIN pin uses Arduino’s onboard voltage regulator to safely drop 12V down to 5V
- Do not connect 12V directly to the Arduino’s 5V pin — it will destroy the board
- Keep the potentiometer powered by 5V, not 12V. It still connects to Arduino’s regulated 5V line.
🧠 Why This Works:
The strip’s internal resistors already account for the 12V supply. The color pads still work the same way — sinking current through MOSFETs connected to ground. You’re simply feeding the strip higher voltage and letting the internal circuit handle it.
Project Recap + Real Circuit + Support


Let’s close this project with a look at the actual working circuit and a quick summary of what you’ve accomplished.
What You Built
- Learned how RGB LED strips are structured
- Controlled a single segment directly from the Arduino
- Scaled up safely using MOSFETs and external power
- Wrote code for:
- Solid color display
- Color cycling using a table
- Smooth transitions with brightness control
- Easily upgraded from 5V to 12V strips with no circuit changes
You now have a solid, modular setup you can reuse in all sorts of Arduino lighting projects — from ambient room lights to smart home installations.
☕ Support My Work
If you enjoyed this project and want to support more tutorials like it, consider buying me a coffee over at Ko-fi.
👉 https://ko-fi.com/mariosideas
Your support helps keep these deep-dive, no-fluff Arduino tutorials coming.
📺 Coming Up Next…
This was Part 2 of my 3-part LED strip series. In Part 3, we’ll explore individually addressable RGB LEDs (like WS2812 or NeoPixels) — unlocking the ability to animate each LED independently with color effects, patterns, and more.
Follow or bookmark the LED Strip Series Playlist and stay tuned!