Thursday, November 19, 2020

How to use RGB Led with arduino to produce 16 million colours (Full detailed tutorial)

Hy everyone i'm your Manitesla.In this post you will learn how to work with RGB LED’s. This Post and my video shows you how to connect a Common Cathode RGB LED  to an Arduino uno. Below i have given code  for your reference, you try not to just copy and paste it. In order to really learn, you need to type it in for yourself, and then find and debug your mistakes. 
                                                       
RGB led

Using an RGB led we can generate any color by controlling the brightness of the individual Red, Green and Blue LEDs. The following image shows a few possible colors of light that can be generated using an RGB LED.

                             PWM Diagram
 An  important point is that you should  make sure that you connect the Red, Green and Blue Anodes of the RGB LED to three PWM supported pins of Arduino since we are using a common cathode rgb led

Circuit Diagram:

                                         RGB Colour wheel
Code:
Circuit diagram
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
int redPin=11;
int greenPin=10;
int bluePin=9;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
}
 
void loop() {

  // put your main code here, to run repeatedly:

//red
  analogWrite(redPin,255);
  analogWrite(greenPin,0);
  analogWrite(bluePin,0);
//green
  analogWrite(redPin,0);
  analogWrite(greenPin,255);
  analogWrite(bluePin,0);
//blue
  analogWrite(redPin,0);
  analogWrite(greenPin,0);
  analogWrite(bluePin,255);
//magenta
  analogWrite(redPin,255);
  analogWrite(greenPin,0);
  analogWrite(bluePin,255);
//yellow
  analogWrite(redPin,255);
  analogWrite(greenPin,255);
  analogWrite(bluePin,0);
//cyan
  analogWrite(redPin,0);
  analogWrite(greenPin,255);
  analogWrite(bluePin,255);
//white
  analogWrite(redPin,255);
  analogWrite(greenPin,255);
  analogWrite(bluePin,255);


}





ManiTesla.tech

Author & Editor

Innovator and Robotics enthusisast intrested in building robots and web development

0 comments:

Post a Comment

Ask Something