How To Connect RGB LED To Arduino

Table of contents:

How To Connect RGB LED To Arduino
How To Connect RGB LED To Arduino

Video: How To Connect RGB LED To Arduino

Video: How To Connect RGB LED To Arduino
Video: Arduino Tutorial: How to use an RGB LED with Arduino. 2024, November
Anonim

RGB LED is three LEDs of different colors (Red - red, Green - green, Blue - blue), enclosed in one housing. Let's see how to connect RGB LED to Arduino.

RGB LED
RGB LED

It is necessary

  • - Arduino;
  • - RGB LED;
  • - 3 resistors for 220 Ohm;
  • - connecting wires;
  • - bread board;
  • - a computer.

Instructions

Step 1

RGB LEDs are of two types: with a common anode ("plus") and a common cathode ("minus"). The figure shows the schematic diagrams of these two types of LEDs. The long leg of the LED is always the common power lead. The red LED lead (R) is located separately, green (G) and blue (B) are located on the other side of the anode, as shown in the figure. In this article, we will look at connecting an RGB LED with both a common anode and a common cathode.

RGB LEDs with common cathode and common anode
RGB LEDs with common cathode and common anode

Step 2

The connection diagram for an RGB LED with a common anode is shown in the figure. We connect the anode to "+5 V" on the Arduino board, the other three pins to arbitrary digital pins.

Please note that we are connecting each of the LEDs through its own resistor, and not using one common one. It is advisable to do just that, because each of the LEDs has its own efficiency. And if you connect them all through one resistor, the LEDs will glow with different brightness.

Wiring diagram for RGB LED with common anode to Arduino
Wiring diagram for RGB LED with common anode to Arduino

Step 3

Let's rewrite the classic "blink" sketch. We will enable and disable each of the three colors in turn. Note that the LED will light up when we apply LOW to the corresponding pin of the Arduino.

RGB LED flashing sketch
RGB LED flashing sketch

Step 4

Let's see the flashing RGB LEDs in action. The LED turns on in turn red, green and blue. Each color lights up for 1 second, then goes out for 2 seconds, and the next one turns on.

You can light each channel separately, you can all at the same time, then the color of the glow will change.

Flashing RGB LED in action
Flashing RGB LED in action

Step 5

If you are using a common cathode RGB LED, then connect the long lead of the LED to the GND of the Arduino board, and the R, G and B channels to the digital ports of the Arduino. It should be remembered that the LEDs light up when a high level (HIGH) is applied to channels R, G, B, in contrast to the LED with a common anode.

If you do not change the above sketch, then each LED color in this case will be on for 2 seconds, and the pause between them will be 1 second.

Recommended: