You are on page 1of 4

Microcontroller

Programming
Project Overview
This project is a keypad-controlled RGB LED. It allows users to change the color of the RGB
LED by pressing a key on a 4x4 keypad. The project uses an Arduino board, a keypad, and an
RGB LED, I2C LCD Display

Hardware Components
Arduino Board
Keypad (4x4)
RGB LED
I2C LCD Display
Jumper Wires
Breadboard

Software Components
1. Arduino IDE
2. Keypad Library
3. LiquidCrystal_I2C Library
Circuit Diagram

Project Code
The project code uses the Keypad and LiquidCrystal_I2C libraries to read input from the
keypad and display it on an LCD screen. When the user presses a key, the code determines
which color to display on the RGB LED by setting the appropriate values for the red, green,
and blue pins. The LCD screen displays the key that was pressed.

#include <Keypad.h>

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

const byte ROWS = 4;

const byte COLS = 4;

char hexKeys[ROWS][COLS] = {

  {'1','2','3','A'},

  {'4','5','6','B'},

  {'7','8','9','C'},

  {'*','0','#','D'}

};
byte rowPins[ROWS] = {9, 8, 7, 6};

byte colPins[COLS] = {5, 4, 3, 2};

Keypad keypad = Keypad(makeKeymap(hexKeys), rowPins, colPins, ROWS, COLS);

int redPin = 11, greenPin = 10, bluePin = 12;

LiquidCrystal_I2C lcd(0x27,16,2);

void setup(){

  for (int i = 2; i <= 12; i++) pinMode(i, OUTPUT);

  lcd.init(); lcd.backlight();

void loop(){

  char key = keypad.getKey();

  if(key){

    int redValue = 0, greenValue = 0, blueValue = 0;

    switch(key){

      case '1': redValue = 255; break;

      case '2': greenValue = 255; break;

      case '3': blueValue = 255; break;

      case '4': redValue = 255; greenValue = 255; break;

      case '5': redValue = 255; blueValue = 255; break;

      case '6': greenValue = 255; blueValue = 255; break;

      case '7': redValue = 255; greenValue = 255; blueValue = 255; break;

      case '8': redValue = 128; break;

      case '9': greenValue = 128; break;

      case 'A': blueValue = 128; break;

      case 'B': redValue = 128; greenValue = 128; break;

      case 'C': redValue = 128; blueValue = 128; break;


      case 'D': greenValue = 128; blueValue = 128; break;

      case '*': redValue = 128; greenValue = 128; blueValue = 128; break;

      case '#': redValue = 64; greenValue = 64; blueValue = 64; break;

  }

    analogWrite(redPin, redValue);

    analogWrite(greenPin, greenValue);

    analogWrite(bluePin, blueValue);

    lcd.clear(); lcd.print(key);

 }

Operating Instructions
1. Connect the components according to the circuit diagram.
2. Upload the code to the Arduino board using the Arduino IDE.
3. Power on the circuit by connecting the Arduino to a power source.
4. Press keys on the keypad to create different colors on the RGB LED.
5. The LCD screen displays the key that was pressed.

Conclusion
The RGB LED color mixer is a fun and educational project that demonstrates the use of a
keypad and an RGB LED to create different colors. The project can be easily customized to
use different color combinations and can be expanded to include additional features. This
project is suitable for beginners and can be used as a starting point for more advanced
projects.

Thank you!

You might also like