Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Arduino Based RGB Colour Code Generator

By A. Sammuddin March 23, 2017

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.

Screenshot of Arduino Code for RGB Colour Code Generator

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.

Image of Character LCD displaying RGB Color Code

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

Circuit-Diagram-Arduino-Based-RGB-Colour-Code-Generator


Filed Under: Electronic Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Finding past posts on edaboard?
  • I think i have devised a new type of "super_transformer" for the Electricity grid?
  • Industrial Relay Board Design for Motorcycle Use
  • sequence detector FSM design
  • Need suggestions in task NI6363 retrigger (analog trigger)

RSS Electro-Tech-Online.com Discussions

  • Sump pit water alarm - Kicad 9
  • Pic18f25q10 osccon1 settings swordfish basic
  • Anyone jumped from Easyeda std to Easyeda pro?
  • turbo jet fan - feedback appreciated.
  • More fun with ws2812 this time XC8 and CLC

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe