Everyone loves LEDs, they are cheap, simple to use and you can easily learn all Arduino tricks with them. But here some an even cooler LED type, this one is different from the ordinary LED we have been using here. It’s called the RGB LED.
What is the RGB LED?
The RGB LED is a single LED that contains 3 LEDs: red, green and blue one.
It can shine in over 16 million colors and is as easy to use as normal LEDs.
We have two main types of RGB LEDs: the common cathode and the common anode.
If you have the common cathode, you should connect the longest leg of the LED to ground (GND) and the rest 3 legs to 3 of the Arduino pins. It shines at HIGH states of the pins.
If you have the common anode you have to connect the longest leg to VCC (5V) and the rest of them to the Arduino pins. It shines at LOW states of the pins.
Do not forget to put a resistor in series with each of the 3 pins between the Arduino and the LEDs pins
Here are two diagrams for connection purposes. The first one is for the common anode (I used it) and the second one is for the common cathode.
Whichever you use, make sure to connect the LED properly. The code does not change.
We need to connect 4 cables and 3 resistors. Here is how it looks like:
Now, we can upload the first program to the Arduino. The following code will light up the red, green and blue LED in a sequence. Not so fancy huh!
The previous code was used for the sake of showing you how it looks and works.
Now, we can build something more sophisticated.
Here, we uses a function random.
This function calls random([min_value], [max_value]); That make you get a random number within the range, min_value (the smallest value we can get is 0 and max value is 255 because those are the max value we can write to the analogWrite() function).
We have the following 3 values for each color and we randomly generate numbers for those colors.
When current_color_value is equal to random_color_value, we get a new random value.
The LED itself is just really bright and we are not able to notice it is color changing. We should somehow diffuse its color to make it look better.
You most probably have this type of foam somewhere in your house, it usually come in boxes to protect their content when shipped. It is just perfect for this. Just make a small hole for the LED to go in and we are set to go.
I hope you have just built your first RGB LED Arduino project. Just take a look on how cool this is.
You might also like:
- Arduino hx711 tutorial
- Arduino magnetic switch
- Best Arduino Kits
- gifts for engineering students
- gifts for engineers
- mpu6050 Arduino projects
- Current sensor Arduino
- Soil Moisture Sensor With Arduino
- Arduino Count up Timer Using the Nokia 5110 LCD
- Arduino Yun: Integrating or Juxtaposing Arduino with Linux
- Arduino Projects: Line Follower Robot
- Arduino RFID Project for Beginners
- Arduino MOSFET Project
- Which Arduino Should You Buy
- What Can You Do With Arduino Boards?
- Great Alternatives to the Arduino Microcontroller
- Arduino Projects: Color Sensor
- Arduino IDE Alternatives
- Arduino Mega vs. Uno
- Arduino Projects: Arduino LCD Display
- Read Arduino Rotary Encoders
- A Selection of the Best Arduino Simulators
- Arduino Projects: IR Receiver
- Arduino Light Sensor Project
- Arduino Projects: Arduino Decibel Meter
- Arduino Stopwatch Project
- Arduino Bluetooth RC Car Project
- Arduino Temperature Logger Project
- Arduino Projects: Arduino 7 Segment Display
- Arduino Projects: Clap ON Clap OFF Light
- Arduino Relay Project
- How to install Arduino Library
- Arduino Projects: Rainfall Detector
- Arduino Projects: RGB LED Arduino
- Arduino Stepper Motor Project
- Arduino Projects: Arduino DC Motor Control
- The Top Affordable Arduino Robot Kit
- Arduino 3D Printed Case
- Arduino Projects: Asynchronous LEDs Blink
- Arduino Projects: Ultrasonic Distance Sensor
- Arduino Projects: LED – 4X4X4 LED Cube
- Arduino Car Projects: Build an Obstacle Avoiding Robot With Less Than $30
- Arduino Projects: Servo Potentiometer Control
- Arduino LED Project: Knight Rider
- Arduino Projects: PIR Motion Sensor
- The Difference between Arduino and Raspberry Pi
- Top 9 Books Every Engineer Should Read
- Top Used Sensors for Arduino
- First Hand on the Arduino Uno Board