Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Generating Different Colours from RGB LED using Arduino PWM

By Deepesh Verma February 14, 2021

 

Prototype of Arduino based RGB LED Controller

Fig. 1: Prototype of Arduino based RGB LED Controller

RGB-LED is widely used to generate different colour Lights in Interior Decoration, Electronic Appliances, Automobiles, etc.

This article deals with Arduino to get various colours with RGB LED and show the transition from one colour to another.

The PWM output of an Arduino, is an important tool to get the variety of colours, be it Pink, Cyan, Magenta, Orange, Purple, etc.

An RGB LED is a four terminal LED with one common pin (say cathode) and three other pins (anode) for Red, Green and Blue LEDs.

Pin Diagram and Internal Circuit of RGB LED

Fig. 2: Pin Diagram and Internal Circuit of RGB LED

The first step, getting and RGB LED and testing it. For this we need to connect 5V supply to bare LED through Resistors (330ohms).

Now that we have got RED, GREEN and BLUE colours individually, its time to get a mix of these three basic colours.

Get an Arduino (any basic board with at least 3 PWM outputs). I used an Atmega8 one.

Connect your Arduino, do proper connections, as shown in below circuit diagram.

Proceeding further, it’s now time to get the control over the LED. We’ll do this through Arduino-IDE.

Go to Arduino-IDE, select your board type, under the ‘Tools’ menu. Select COM port, under ‘Serial Port’ menu.

After this copy the below sketch and Upload it.

Working:

Now, let us understand how this works. The ‘analogWrite()’ function of Arduino makes this possible.

Each digital output pin of Arduino can provide a voltage of 0 or 5V, but the PWM pin has an add-on feature. It can give various voltage values between 0V-5V.

Say we write,

analogWrite(red_led,50);              //red_led refers to pin-9 (PWM pin)

This will provide a voltage = (5/255)*50 V = 0.98V on pin-9.

If we write:

analogWrite(blue_led,100);                   //blue_led refers to pin-10 (PWM pin)

This will provide a voltage = (5/255)*100 V = 1.96V on pin-10

In this experiment, what we do is create a for-loop to provide values between 0-255 at each LED pin with some delay (in milliseconds).

for(int i=0;i<=255;i+=3)

{

analogWrite(redPin,255-i);                     //writes (255-i) on redPin

analogWrite(greenPin, i);                       // writes I on greenPin

delay(100);                                      //wait for 100uS

}

Image showing RGB LED being controlled by Arduino

Fig. 3: Image showing RGB LED being controlled by Arduino

You may also like:


  • What are different types of industrial robots?

  • What are LoRa gateways and what types are available?

  • How does LoRa modulation enable long-range communication?

  • What are the different types of EV charging connectors?

  • What types of motors are used in electric vehicles?

  • What is the role of embedded software in electric vehicles?

Project Source Code

###



int redPin = 10;
int greenPin = 11;
int bluePin = 9;
void colourTransition();
void setup()
{
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(bluePin, OUTPUT);
}
void loop()
{
  colourTransition();
}
void colourTransition()
{
  for(int i=0;i<=255;i+=3)
  {
    analogWrite(redPin,255-i);
    analogWrite(greenPin, i);
    delay(100);
  }
  for(int i=0;i<=255;i+=3)
  {
    analogWrite(greenPin,255-i);
    analogWrite(bluePin, i);
    delay(100);
  }
  for(int i=0;i<=255;i+=3)
  {
    analogWrite(bluePin,255-i);
    analogWrite(redPin, i);
    delay(100);
  }
}

###

 


Circuit Diagrams

Circuit-Diagram-Arduino-Based-RGB-LED-Controller


Filed Under: Arduino Projects, Electronic Projects
Tagged With: Arduino, pwm, RGB LED
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

Log in to leave a comment:

Lost your password?

Don't have an account? Register here

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Sensors
In this Tech Toolbox, we cover some of those technologies driving the next generation of connected systems, including ultra-low-power sensing strategies that extend node battery life, and 60 GHz CMOS radar for contactless health and presence detection.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions.

  • Enhancing Boost Converter Efficiency: From Practical Limitations to a Series-Boost Differential Topology
  • Best Microcontroller for Low-Power IoT Applications with Real-Time Data Processing (robotic arm)
  • How to set OSCAL in a PIC 12F675
  • Measure or verify the total optical loss of the fiber link
  • Why is this metal PCB enclosure floating?

RSS Electro-Tech-Online.com Discussions

  • Boss Chromatic Tuner TU-3
  • industry specification standard for differential line
  • Assistance locating a 'trail' camera gadget, please ?
  • Mystery amp noise - ??
  • 220v to 5v

Featured Tutorials

Learn - VHDL Tutorials (22 Part)

  • VHDL Tutorial – 11: Designing half and full-subtractor circuits
    VHDL Tutorial – 11: Designing half and full-subtractor circuits
  • VHDL Tutorial – 12: Design a 8-bit parity generator and circuit checker
    VHDL Tutorial – 12: Design a 8-bit parity generator and circuit checker
  • VHDL tutorial 13: Design 3×8 decoder and 8×3 encoder using VHDL
    VHDL tutorial 13: Design 3×8 decoder and 8×3 encoder using VHDL
  • VHDL Tutorial 14: Design 1×8  demultiplexer and 8×1 multiplexer using VHDL
    VHDL Tutorial 14: Design 1×8  demultiplexer and 8×1 multiplexer using VHDL
  • VHDL Tutorial 17: Design a JK flip-flop (with preset and clear) using VHDL
    VHDL Tutorial 17: Design a JK flip-flop (with preset and clear) using VHDL
  • VHDL Tutorial 18: Design a T flip-flop (with enable and an active high reset input) using VHDL
    VHDL Tutorial 18: Design a T flip-flop (with enable and an active high reset input) using VHDL
More Tutorials >

Recent Articles

  • Smarter HVAC Climate Solutions by TE
  • Amphenol RF adds NEX10 jack for 1.37 mm cable
  • Samtec headers support 2 to 50 pins
  • Same Sky adds 2.54 mm rectangular connectors
  • Bourns adds high-power fuses up to 1000 VDC

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe