Arduino RGB LED Lamp + 4bit LCD Display





Introduction: Arduino RGB LED Lamp + 4bit LCD Display

This is my first instructable !!! yay..

Before I continue. I do not go into details of how to cut the wood, or piece everything together. I freestyled the entire build process, whatever came to mind is what I reproduced. The point of this instructable is to be able to create the circuit, program the arduino, and create something of your own imagination.

Also this instructable is meant for people who are familiar with the ever so popular Arduino !!!
If you want to learn more about what the Arduino is all about please visit : Arduino Home Page

Alright now a little explanation what this exactly is. This is simply an arduino controlling an RGB LED to control lighting. There are 3 different modes. These modes can be selected by pressing a button. The Modes and values of the RGB are being displayed on a LCD screen.

Modes :

1) Hue Cycle : This cycles through the hue spectrum. You scroll the wheel (potentiometer) to control the speed at which the color changes from one to another.

2) Hue Selection : Scroll the wheel (potentiometer) to select the color you chose. IT remains at this color

3) Random Hue : The arduino randomly selects a target RGB color. It fades to that target RGB color. Then the process starts over again. You can select the speed at which the color fades from one to another

The following video is the creation of the Arduino controlled RGB LED Lamp from start to end.

Step 1: Materials

1) Arduino : decimila, freeduino, Rock Bottom Freeduino Kit (RBFK). (I used the RBFK because its cheaper and I was giving this away as a present.).

2) Potentiometer : Im using 120ohm but any will do in this particular application.

3) Push Button : Do not use a ON/OFF button. It must be a push button.

4) RGB LED : Make sure it is common cathode RGB LED's. Meaning 1 pin is GROUND and the other 3 pins R,G,B pins are POSITIVE.

5) HD44780-compatible LCD : From my best experience, all 16x2 LCD's I worked with are work with the 4bit library.

6) 5 x Resistors:
- 22ohm = LCD Contrast... *NOTE : Use a POT to determine best contrast for LCD.
- 2.2Kohm = PushButton
- 3 more resistors. You need to determine the values depending on your RGB LED. Details below.

Step 2: Circut Connections

General Info & Tips

- make sure LCD (RW / PIN5) is hooked to ground.
Theres a mistake in the diagram I made below, it shows LCD PIN 6 is attached to GROUND.... thats wrong, LCD PIN5 is supposed to be attached to ground

- When testing LCD use POT to figure out proper resistence for LCD CONTRAST. You may think LCD isn't working when in actuality the contrast is just to low and you cannot see anything.

- NOT ALL LCD's are made the same. Refer to your LCD specs (google model # of LCD) for pinouts. (DB0-DB7, RegisterSelect , ReadWrite, Enabled, etc)

- RGB PINs needs a proper resistors for each color. The resistor is determined by the amount of voltage each color requires.

R = 2.8 - 3.2 volts = 82ohm (recommended)
G = 3.2 - 3.5 volt = 68ohm (recommended)
B = 3.2 - 3.5 volt = 68ohm (recommended)

use following URL to determine resistance for each color. LED series/parallel array wizard

Component Info

Potentiometer (POT) = 120ohm
LCD Contrast resistor = 22 ohm
push button resistor = 2.2 Kohm

LCD Connections

Arduino (GND) = LCD (PIN 1) = Ground
Arduino (5V) = LCD (PIN 2) = Power Supply
Arduino (PIN 2) = LCD (PIN 6) = Enable Signal
Arduino (PIN 7) = LCD (PIN 11) = DB4
Arduino (PIN 8) = LCD (PIN 12) = DB5
Arduino (PIN 9) = LCD (PIN 13) = DB6
Arduino (PIN 10) = LCD (PIN 14) = DB7
Arduino (PIN 11) = LCD (PIN 4) = Register Select
Arduino (PIN 12) = LCD (PIN 5) = Read / Write

RGB LED Connections

Arduino (PIN 3) = LED R = 2.8 - 3.2 volts = 82ohm (recommended)
Arduino (PIN 5) = LED G = 3.2 - 3.5 volts = 68ohm (recommended)
Arduino (PIN 6) = LED B = 3.2 - 3.5 volts = 68ohm (recommended)
Arduino (GND) = LED GND

Button & Pot Connections

Arduino (ANALOG PIN 2) = POT (wiper : usually in the middle, depends on pot)
Arduino (PIN 4) = PushButton (make sure to use 2.2Kohm or higher resistor)

Step 3: Arduino Source Code + Files

The Source Code, How to wire everything and LCD library are all contained in the Zip File.

Almost all the code was written by myself although I must add credit to the following code which I used.

Arduino Hue Function

select different Modes with push button

The hue function was extremly convienient, why reinvent the wheel.
As for the push button, you wouldn't believe how tricky this can be. This code was extremely helpful to use the pushbutton as I intended. (pressing pushbutton allows you to select different modes)

Step 4: Final Words

This project was created as a gift for a very good friend, and now I wish to offer this gift to the rest of the INSTRUCTABLES enthusiasts. This entire process was extremely an amazing experience and Im more than happy to share it with the world.




    • Water Contest

      Water Contest
    • Oil Contest

      Oil Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    111 Discussions

    Can you make the diagram on fritzing?? It's much easier to read. Thanks

    Hi, I recently tried this project, and gotup to where I compile the code. However, when I try to compile, I get a bunch of errors:

    <code>\arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:51:57: error: WConstants.h: No such file or directory
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp: In member function 'void LCD4Bit::pulseEnablePin()':
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:86: error: 'LOW' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:86: error: 'digitalWrite' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:87: error: 'delayMicroseconds' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:89: error: 'HIGH' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:92: error: 'delay' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp: In member function 'void LCD4Bit::pushNibble(int)':
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:101: error: 'digitalWrite' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp: In member function 'void LCD4Bit::commandWriteNibble(int)':
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:149: error: 'LOW' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:149: error: 'digitalWrite' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp: In member function 'void LCD4Bit::commandWrite(int)':
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:156: error: 'LOW' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:156: error: 'digitalWrite' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:159: error: 'delayMicroseconds' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp: In member function 'void LCD4Bit::print(int)':
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:166: error: 'HIGH' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:166: error: 'digitalWrite' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:167: error: 'LOW' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp: In member function 'void LCD4Bit::clear()':
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:186: error: 'delay' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp: In member function 'void LCD4Bit::init()':
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:192: error: 'OUTPUT' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:192: error: 'pinMode' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:200: error: 'delay' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:206: error: 'delayMicroseconds' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp: In member function 'void LCD4Bit::leftScroll(int, int)':
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:287: error: 'delay' was not declared in this scope
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp: In member function 'void LCD4Bit::rightScroll(int, int)':
    \arduino-1.0.1\libraries\LCD4Bit\LCD4Bit.cpp:296: error: 'delay' was not declared in this scope</code>

    How can I fix this?

    Thanks in advance.
    6 replies

    Its not finding the "LCD4Bit.cpp" library. "LCD4Bit.cpp" is in the Zip I believe. Copy it to to proper folder and restart arduino sketch.

    I copied the whole LCD4Bit folder into the libraries folder. Is that what I'm supposed to do?

    as long as this file: LCD4Bit.cpp
    is in this folder : \arduino-1.0.1\libraries\LCD4Bit\
    because thats what its looking for when compiling.

    hmmmm.... is it a PC or MAC?
    normally on pc you have the full path c:\arduino\libraries\lcd4bit\LCD4Bit.cpp

    I got the library off the arduino site.
    Perhaps (actually im pretty sure) they have a newer library for LCD screen.
    Alot has changed with arduino since 2009

    Check it out the following link:

    hope this helps... 

    It's a PC, but I cut off the beginning of the path (C:\Users...etc.)
    I'm going to try adapting the code for the LiquidCrystal library.

    This is a great project, I'm adapting the code for an art project I am currently doing and it's really helping me.

    I do seem to be getting some color flickering during certain colors. I'm trying to debug the code but may be asking for some advice.



    8 replies

    Color flickering can be caused by 2 things in my experience.

    1) Bad Led, try seeing if this happens with other LEDS. Check wiring and contacts as well.

    2) To much processing between loops. For LED's to fade nicely they need to turn on and off really quick. Any processing in between and you will lose fractions of seconds during the fading. Causing the flicker. There is a function that sets RGB values called h2rgb(). If you are doing something like code below, this will definitely cause flickering.

       //lines of code that 
       - any cpu instensive code
       - receiving serial data
       - sending serial data

    Also consider that this code was built on Arduino running at 16mhz (16,000 times per second) if your running a Arduino Nano 8mhz your running the loops at HALF the speed. The code itself may need to be optimized for slower clock cycles.

    Hope this helps you out.

    It looks like the flickering is the pot. I am printing the value of the pot and it's not stable. I'll try another pot or maybe I will do some kind of averaging in code.



    Glad you debugged the problem. I'd try to change the pot, no need to add extra code for averaging unless you really need it.

    I tried changing the pot and I get flickering on every pot I try.

    Even just doing this simple code:

    for (int i=0; i< 25 ; i++) potAvg += analogRead(potPin);
    potVal = potAvg / 25 ;

    Serial.println (potVal);

    To average the value, it still shows potVal to be inconstant, usually it fluctuates + or - 1 value but that is enough to cause a flicker on a static hue.

    any ideas?



    The values of the pot should be stable. Either 2 things could have gone wrong. 

    1) The pot is wired wrong, goto this link for quick reference:

    2) The pot is wired correctly, ALTHOUGH theres a short, or a "shared" pin that sux the voltage out of the pot. So if the voltage is fluctuating, then the values of the pot will fluctuate. 

    try reading voltage of the pot... is the voltage flucating? If so then theres a short or some wiring is done wrong... If your using the LCD, try testing without LCD hooked up. You should be able to control the LED easily with just pot plugged in. If that works, then try to debug if the LCD is causing the issue.

    Hope this helps. 

    Thanks silverbyte, the pot is wired correctly, I posted my issue on the Arduino forum and somebody said it sounded like noise. They suggested shifting from 10 bits to 8 which really helped.,115652.0.html




    When you mentioned you tried SEVERAL POTS I was like... hmmmm well can't be the POT since you tried several of them. I think you just have bad batch pots.

    if your POT fluctates just by a few integer values (+ or - 5) then using 8bit (0-255 instead of 0-1023) would definitely resolve that issue.

    Glad you have it all resolved! Isn't debugging problem FUN!!! :) haha...

    Thanks silverbyte, I believe the flickering was happening when I was on a solid color, not a fade. It is running on a Uno and is powering 30 feet of RGB LED strips.

    I will be looking at the code this weekend to see if I can reproduce the issue and see if I can debug it.



    it's much like my project, only that yours is a bit more complicated
    Thumbs Up!

    Man I got it, took a couple days, but she is working great, I cant wait to build the finished product now, thanks so much for the great indestructible. For proto newbie to like me, remember to check the LCD4Bit file completely, changing pin values as needed, as well as the sketch, and beware of the few mistakes on the fritz, first time I pressed the button, it reset the arduino and windows started installing drivers for god knows i cancelled that quick and redid the switch according to the arduino site, other than that, I used a slider pot and have a rgb lcd on the way to hopefully parallel to the other led for more effect, and add an on/off switch and reset if needed...I may do the same and give it as a present. Next I will learn to make a bare naked setup like yours to make it a neater device...again thanks a bunch from Big D.

    This looks awesome! I just purchased an Uno and am looking forward to trying this. Thanks for sharing!