element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Arduino Tutorial #4: RGB LED
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: meera_hussien
  • Date Created: 12 Dec 2018 8:19 AM Date Created
  • Views 4264 views
  • Likes 3 likes
  • Comments 0 comments
  • diy
  • rgb
  • arduino
Related
Recommended

Arduino Tutorial #4: RGB LED

meera_hussien
meera_hussien
12 Dec 2018

Arduino Tutorial #4: RGB LED

 

                 In this tutorial, we will look into how to control the RGB LED. First, let us look at the theoretical of the RGB LED. But before that, I would like to demonstrate how it will look when you test the LED with Arduino.


image






You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image



Basically, an RGB LED is no difference from the normal LED, except that it has an addition of two more pins. And obviously, the internal structure is of difference from the common LED. Below is the image of the RGB LED.



image
RGB LED
Image extracted from Kingbright Datasheet. Credit to Kingbright.

Referring to the image above. we can see that there are 4 pins. Pin no 2 is the common cathode pin, Pin no 4 is for the GREEN, Pin 3 for BLUE and Pin 1 is for RED. These are the 3 main colours available from the RGB LED. We achieve or get other different colours by combining these 3 colours. The diagram below the colour combination.





image


As you can see the, when combining the colour you can get a different colour. We can achieve this by varying the brightness of each colour. The reason why we can see three different colour is that because our eyes have three types of light receptor. Our brain processes the amounts of red, green and blue and converts it into a colour of the spectrum.



Next, let us look into the Arduino sketch for controlling the RGB LED.

image




Looking into the code by section, the first part we define the pins. In our case, we connect them to the PWM pin, which is pin 9, pin 10 and pin 11.



image

And next is the to define the type of LED being used either common anode or common cathode. If we are using the common anode, we need to uncomment these line, whereas if we are using common cathode, we can leave it commented.


image


Following this line is the setup line. As we have seen in the previous tutorial, here will do the setting of the pins which we will use in this project. Basically, we will use these pin as the output.



image


Once this is done we will write the main program in the void_loop(). Below is the code which we will use




image


As we can see from the code, we have written the code to display 6 different colours. This has been illustrated in the demonstration video earlier. The first three colour is straightforward, meanwhile, the next three colour is achieved through the combination of two or three different colour. And the last portion of the code which we will look into is for controlling the brightness of each the three colour.



image



That's all for now. In our next tutorial, we will look into using the LED and push button.

Thank you.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube