Hi friends, In this post I'm going to control some common anode RGB LEDs by addressing them individually without using any multiplexer IC or something like that.
What Is RGB LED?
RGB LED is made using three LEDs Red, Green and Blue and make a pin of each led as a common pin and rest three pins as controlling pins. These three LEDs are compact with a single cover and act as a one unit. Therefore these typs of led has four pins. One common pin and another three pins coms from each colour LED. You can understand this clearly by referring below images.
There are two types of RGB LEDs Common Cathode and Common Anode types are them.
Overview
In this case we have limited number of IO pins in Arduino UNO. We have 20 IO pins on it. So, How can we address maximum RGB LEDs using this 20 IO pins...
Here I have used a special method for this. I wired the RGB LEDs as a matrix. This matrix is 3 X 17. You can see it in this wiring diagram below.
Part List
Arduino UNO with Data Cable (buy for $5.99 with free shipping worldwide)
17 X Common Anode RGB LEDs
3 X 220Ohm Resistors
Breadboard & Jumper Wires
Wiring Diagram
You can see we can connect maximum 17 of RGB LEDs according to this method with Arduino UNO. Here is how i connect everything together.I used Arduino D3, D5 and D6 to connect R, G and B pins of the matrix. These pins are PWM pins which we can fade each line. In another words, we can use analogWrite() function for these pins which is great! I also used another IO pins to connect the anodes of RGB LEDs. I also used 3 resistors for limit the current to each R, G, B lines. I used 220Ohm resistors for this.
Note: I only used 8 X RGB LEDs because I didn't have to find more jumper wires to wire rest of LEDs...
Arduino Code
first one is led_colour_change(led_index, r_value, g_value, b_value)
this function update the r,g,b values of the selected led and help to drive that led with correct colour.
parameters:
led_index : this can be 1 to 17
r_value, g_value, b_value : can be values between 0 - 255, 0 is minimum colour, 255 is maximum colour.
second function which i made is drive_led()
this function is for continuously scan all leds and update the RGB values as they can output the relevant colour.
this function doesn't have any parameters.
Please see the Arduino Code to understand this better.
You can download the arduino code HERE.
Note: Sometimes the code will not upload to your arduino because we have blocked Arduino default serial communication pins which are D0 and D1. Just disconnect the jumper wires which we connected to this pins and re connect them after uploading the code.
Your Idea Is Useful For Me...
I think this post is useful for you. Please comment below your idea about this tutorial. Thank You.My Services For You...
You can Contact me on Fiverr which is the best market place in the internet. If you have any project relate Arduino programming and need an assistance, Then I can do your project for a reasonable price. (for small projects, i only charge $5) You can view my gigs HERE.
Comments
Post a Comment