How to Control RGB LED Using Arduino Uno
by Okami Innovations in Circuits > LEDs
592 Views, 0 Favorites, 0 Comments
How to Control RGB LED Using Arduino Uno
Hello all Electronic enthusiast's!, in this project I will explain how an RGB LED (6pin 3watt) works and how to controll it using Arduino Uno board. The 3 watt RGB LED consumes 1 watt per chanel hence to switch this higher power LED we need an TIP122 transistor.
The RGB LED has three LED's embedded in it with separate cathodes and anodes. Each of them has to be connected to the arduino through three TIP122 transistors. Since it is a 3 watt LED it needs an heat sink to dissipate the heat generated by the led. Warning: do not look directly into this led for more than 5 second's.
In this project, a tactile button is used to change into different mode's of the LED. There are totally five mode's in this project, they are;
Red mode, Green mode, Blue mode, Blink mode and OFF mode.
Now, let's see how to do this project step by step at a time.
Supplies
Hardware's required:
- 3 watt 6 pin RGB led x 1
- Arduino Uno Board x 1
- TIP122 transistor x 3
- 1Kohm Resistor x 3
- 2.2Kohm Resistor x 1
- Tactile Switch x 1
- Bread Board x 1
- Heat Sink x 1
- Single stranded wires(less than a meter).
- Heat Sink Compund(100gm).
- Jumper wires - Male to Female.
Circuit Connection
Connect the components on bread board as shown in the schematic diagram. Solder the LED with colourful single stranded wires so that it can be connected on the bread board. Be careful when connecting components on bread board, sometimes the holes on the bread board confuses due to parallax error, which might lead to short circuiting the microcontroller.
Fixing the LED to Heat Sink
Since it is an 3 watt LED, it starts to get hot very soon, hence we use heat sink to dissipate the heat generated by the LED. First add a drop of heat sink paste on the heat sink, then take the LED and place it on the paste and press gently and let it dry for some time. Now the LED is ready with the heat sink to dissipate the heat.
Setup the Arduino Board With IDE
Once the connections are done connect, the arduino board through the usb cable. Arduino IDE must be installed on the PC to which the board wil be connected. Arduino IDE can be downloaded from the official website of Arduino, to know further information on how to download and which version to download click here. When connected for the first time, go to tools in Arduino IDE and check the port to select the com to which the board is connected. The code and the programming guide is given in the step 4. When ready with the code click on the "Upload" button in the IDE to upload it to the board. When the upload is complete the IDE gives an indication as "Done uploading".
Programming
//Global pin and variable declaration's const int Button = 2; int count= 0; int Redoutput = 10; int Blueoutput = 11; int Greenoutput = 12; void setup() { //setting the pin modes pinMode(Redoutput, OUTPUT); pinMode(Blueoutput, OUTPUT); pinMode(Greenoutput, OUTPUT); pinMode(Button, INPUT); Serial.begin(9600); } void loop() { count1(); if (count==0) { digitalWrite(Redoutput, HIGH); Serial.println("red"); }else{ digitalWrite(Redoutput, LOW); } if (count==1) { digitalWrite(Blueoutput, HIGH); Serial.println("blue"); }else{ digitalWrite(Blueoutput, LOW); } if (count==2) { digitalWrite(Greenoutput, HIGH); Serial.println("green"); }else{ digitalWrite(Greenoutput, LOW); } while(count==3){ unsigned int rgbColour[3]; rgbColour[0] = 255; rgbColour[1] = 0; rgbColour[2] = 0; for (int decColour = 0; decColour < 3; decColour += 1) { count1();if(count!=3){ break; } int incColour = decColour == 2 ? 0 : decColour + 1; for(int i = 0; i < 255; i += 1) { count1();if(count!=3){ break; } rgbColour[decColour] -= 1; rgbColour[incColour] += 1; setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]); delay(5); } } } } /*function defined to output rgb*/ void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) { analogWrite(Redoutput, red); analogWrite(Greenoutput, green); analogWrite(Blueoutput, blue); } /*function defined to read button press and increment the count*/ void count1(){ int Button1 = digitalRead(Button); if (Button1==HIGH){ count++; delay(200); if (count>=5){ count=0; } Serial.println(count); } }
Output
The video shows the detailed steps of the project visually and also its working. Each time when the button is pressed the LED changes it's mode.You can also make an outer box to the prototype and add an glass to dim the brightness of the LED. Hang it any where on the wall or use it in any lightning crafts.
I hope you have enjoyed doing this project !. If there are any doubts or confusions feel free to comment in the comment section.