Skip to main content

How to control RGB LED using Arduino Uno

RGB LED is the abbreviation of ‘’Red Green Blue Light Emitting Diode’’. RGB LED is the most amazing type of LED which has the ability to create millions of different shades of light colors using red, green, and blue colors.

How to control RGB LED using Arduino Uno


RGB LED is the abbreviation of ‘’Red Green Blue Light Emitting Diode’’. RGB LED is the most amazing type of LED which has the ability to create millions of different shades of light colors using red, green, and blue colors.
RGB LED looks just like a regular LED or we can say that an RGB LED actually had three LEDs (red, green, and blue colored LED) inside a single packaged LED with four legs. We can generate any color by adjusting the brightness of each of the three LEDs of the RGB LED.

 If you want to produce red color, you would set the red LED at the highest intensity along with the green and blue LED with minimal (zero) intensity. In a similar manner, if you need to generate white color, you would set all the three LEDs with the highest intensity. 

Common anode and common cathode type RGB LED:

There are two types of RGB LED one is a common anode type and the other one is a common cathode type. The RGB LED had four legs, the first one is for red-colored LED, the third one is for green colored LED, the fourth one is for blue colored LED and the second one is for common anode or common cathode.

You can identify the type of the RGB LED by using the multimeter in continuity mode or by reading the component data sheet provided by the manufacturing company.

Common Anode type:

In common anode type RGB LED all the three colored LEDs leg shares a (positive) anode connection. You can understand the structure of common anode type RGB LEDs using the image illustrated below.



Common cathode type:

In common cathode type RGB LED all the three colored LEDs leg shares a (negative) cathode connection. You can understand the structure of c RGB LED using the image illustrated below.



In this article, I will explain to you how an RGB LED can be operated using the Arduino Uno using two very basic examples for the same circuit connection. At the end of this article, you will be able to play with multiple colors generated by the RGB LED.

Required components:

  • 1 x Arduino Uno board........................................BUY
  • 1 x breadboard: ...................................................BUY
  • 1 x RGB LED common anode mode: .................BUY
  • 3 x 1 K ohm resistors: .........................................BUY
  • Few jumper wires: ...............................................BUY

Circuit diagram:




Circuit description:

As shown in the above circuit diagram, the first terminal of the RGB LED along with the 1 K ohm resistor is connected to the PWM pin 11 of the Arduino board. The second pin (common anode) of the RGB LED is connected with the 5-volt power supply pin of the Arduino board. The third pin of the RGB LED along with the 1 K ohm resistor is connected to the PWM pin 9 of the Arduino board. The last pin of the RGB LED is also connected with the PWM pin 6 of the Arduino board along with the 1 K ohm resistor. I have preferred this circuit connection for both the codes to make things easier for you to understand.

Code 1: Click Here

PWM or pulse width modulation is the technique that is used to control the brightness of the LED, speed, and direction of different types of motors. Arduino Uno has six pins (3, 5, 6, 9, 10, and 11) to generate PWM signals of the specific duty cycle. The duty cycle specifies the duration for which the pulse is HIGH. It measures in percentage and defines the voltage between 0 and 5 volt. analogWrite(pin, value) function is used to generate PWM signal of specific duty cycle where the value varies from 0 to 255 for 0 to 100% duty cycle (for example, 25% duty cycle: analogWrite(64), 100% duty cycle: analogWrite(255)).

According to this code, I have used the PWM pins 11, 9, and 6 for LED outputs. I have used the analogWrite() function to generate output which accepts values between 0 to 255.

In the “common anode” type if the value is 0 means LED has the highest brightness on the other side if the value is 255 means LED has the lowest brightness (off). As shown in the connection diagram I  used this common anode mode to generate output using RGB LED.

However, in “common cathode” type 0 values indicate the lowest brightness and the 255 value indicates the highest brightness.

According to the code in the output red, green, blue, and white-colored will be produced by the RGB LED. You can check the output according to the provided input values in the analogWrite() function.

Code 2: Click Here

In this example code, I have tried to produce four different colors by mixing the values of red, green, and blue pins. You can change these values and try to produce a new color. I had used the same circuit connection based on common anode mode for this code to generate output.

Output:


Important points:

  • In a common anode type, the second pin of the RGB LED is always connected with the 5-volt power supply pin.
  • In a common cathode type of mode, the second pin of the RGB LED is always connected with the GND pin.
  • In a common anode type, the analogWrite() function generates the highest brightness for the value 0 and the lowest brightness for the value 255.
  • In a common cathode type, the analogWrite() function generates the highest brightness for the value 255 and the lowest brightness for the value 0.






Comments

  1. You've shared some incredibly useful information about LED lights. This is frequently a terrific way for us to broaden our knowledge while remaining useful. Thank you for bringing this article to our attention.

    ReplyDelete
  2. You wrote this post Home Electrical Maintenance Service Provider very carefully. The amount of information is stunning and also a gainful article for us. Keep sharing this kind of articles, Thank you.

    ReplyDelete

Post a Comment

Popular posts from this blog

Smart Plant Watering System Using ARDUINO UNO

As we all know, plants play an important role in our life, there are countless benefits we get from plants but the most important is fresh air and the pleasant atmosphere on the earth. Hence,   It is not only our social duty as well as the responsibility that we should plant trees as much as we can and also take care of them. But  the biggest challenge we face, is, taking care of them,

How to use LCD with Arduino Uno

Liquid crystal Display 16x2 (LCD) is a widely used electronic device to establish communication between the real world and the electronics-based machine world.

How to operate soil moisture sensor with Arduino

The soil moisture sensor is the most amazing sensor used to measure the quantity of water present in the soil and defines the moisture level of the soil as the output. Because of its amazing operating principle, this sensor is used in applications such as automatic irrigation systems, agriculture research applications, landscape irrigation, indoor planting system, and lawns. I have also made an advanced level project  "Smart Plant Watering System" using a soil moisture sensor.

ad

ad