Red Green and Blue (RGB) colour is the basic colour to generate various colours by mixing. The introduction of new colour is done by merging or mixing of each colour in a particular proportion. This technique is used in TV’s, Mobiles…etc., similarly on web designing using HTML or any other language requires the HEX code of a particular colour to design. Presented here the circuit to know about the concept of colour generating and the HEX code of that colour.
CIRCUIT AND WORKING
The circuit diagram of the RGB colour code generator is shown in figure enclosed as an attachment. It is built around Arduino Uno board, 16×2 LCD, RGB LED and few other components. The Arduino board is the brain of the circuit which performs the colour generation by Pulse Width Modulation (PWM). Three potentiometers control the intensity of RGB LED. The 16×2 LCD wired in 4-bit mode and it displays the decimal value of the each colour in the first row and the HEX value in the second row.
The intensity of each colour is controlled by potentiometers VR1, VR2 and VR3. These potentiometers are connected to analog input A0, A1, and A2 of Arduino board. The program continuously scans the analog input of the board. The Analog to Digital Converter (ADC) of the Arduino converts the analog value into a 10-bit digital value. Since the resolution of the PWM module of the board is 8-bit, the 10-bit analog value is converted into 8-bit value by the program.
Fig. 1: Screenshot of Arduino Code for RGB Colour Code Generator
Thus the 8-bit value controls the duty cycle of the PWM, thereby it controls the intensity of the colour. The RGB LED emits light of a colour which is controlled by the potentiometer. Corresponding colour value is displayed in the first row as “R*** B*** G***”. The second line displays the HEX value of the colour as “HEX ******”. My prototype picture is shown below.
Fig. 2: Image of Character LCD displaying RGB Color Code
Note :
The Resistor values (R1, R2, and R3) are critical. They vary for each LED. Choose the R1, R2 and R3 values after calibration. For calibration, connect the RGB LED in series with a 1k potentiometer for each colour to 5V. Vary the potentiometer to low resistance side until the RGB LED emits slightly whitish colour. Now measure the resistance from the arm of the potentiometer to the anode leg of the LED. Fix that resistance for each color. Be careful while calibration. There is a chance of burn of potentiometer when the arm moves to very low resistance side due to more current passes through the arm. The Arduino board can be powered by an external 9V, 500mA adapter or USB cable.
Project Source Code
###
/* RGB COLOUR CODE GENERATOR BY A. SAMIUDDHIN */ #include <LiquidCrystal.h> // LCD library LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //LCD diplay pins on Arduino int Radj; int Gadj; int Badj; int Rval=0; int Gval=0; int Bval=0; int R = 9; int G = 10; int B = 11; void setup() { pinMode(R, OUTPUT); // Pin 9 declared as output pinMode(G, OUTPUT); // Pin 10 declared as output pinMode(B, OUTPUT); // Pin 11 declared as output lcd.begin(16,2); // Initialise LCD delay(1); lcd.setCursor(0,0); lcd.print("RGB COLOUR CODE"); lcd.setCursor(4,1); lcd.print("GENERATOR"); delay(2000); lcd.setCursor(0, 0); lcd.print(" R G B "); lcd.setCursor(3,1); lcd.print("HEX= "); } void loop() { Radj = analogRead(0); Gadj = analogRead(1); Badj = analogRead(2); Rval=Radj/4; // Convert the range from (0-1023) to (0-255) Gval=Gadj/4; // Convert the range from (0-1023) to (0-255) Bval=Badj/4; // Convert the range from (0-1023) to (0-255) lcd.setCursor(2,0); if (Rval<10) { lcd.setCursor(2,0); lcd.print("00"); lcd.print(Rval); } else if(Rval<100) { lcd.setCursor(2,0); lcd.print("0"); lcd.print(Rval); } else { lcd.setCursor(2,0); lcd.print(Rval); } lcd.setCursor(8,1); if (Rval<16) { lcd.print("0"); lcd.print(Rval, 16); } else { lcd.print(Rval, 16); } lcd.setCursor(7,0); if (Gval<10) { lcd.setCursor(7,0); lcd.print("00"); lcd.print(Gval); } else if(Gval<100) { lcd.setCursor(7,0); lcd.print("0"); lcd.print(Gval); } else { lcd.setCursor(7,0); lcd.print(Gval); } lcd.setCursor(10,1); if (Gval<16) { lcd.print("0"); lcd.print(Gval, 16); } else { lcd.print(Gval, 16); } lcd.setCursor(12,0); if (Bval<10) { lcd.setCursor(12,0); lcd.print("00"); lcd.print(Bval); } else if(Bval<100) { lcd.setCursor(12,0); lcd.print("0"); lcd.print(Bval); } else { lcd.setCursor(12,0); lcd.print(Bval); } lcd.setCursor(12,1); if (Bval<16) { lcd.print("0"); lcd.print(Bval, 16); } else { lcd.print(Bval, 16); } analogWrite(R, Rval); // PWM for Red colour analogWrite(G, Gval); // PWM for Green colour analogWrite(B, Bval); // PWM for Blue colour }
###
Circuit Diagrams
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.