Introduction: Arduino RGB LED Lamp + 4bit LCD Display

Picture of 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

Picture of 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.



marios8543 (author)2013-12-12

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

ARR8 (author)2012-07-24
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.
silverbyte (author)ARR82012-07-25

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.

ARR8 (author)silverbyte2012-07-25

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

silverbyte (author)ARR82012-07-26

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.

ARR8 (author)silverbyte2012-07-26

I verified that it is, but I still get those errors.

silverbyte (author)ARR82012-07-26

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... 

ARR8 (author)silverbyte2012-07-26

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.

filthyPhil (author)2012-07-05

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.



silverbyte (author)filthyPhil2012-07-06

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.

filthyPhil (author)silverbyte2012-07-08

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.



silverbyte (author)filthyPhil2012-07-09

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.

filthyPhil (author)silverbyte2012-07-24

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?



silverbyte (author)filthyPhil2012-07-24

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. 

filthyPhil (author)silverbyte2012-07-24

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



silverbyte (author)filthyPhil2012-07-25


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...

filthyPhil (author)silverbyte2012-07-06

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.



Dekel Ziv (author)2012-07-15

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

millerboy220 (author)2012-05-22

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.

Build_it_Bob (author)2010-11-26

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

silverbyte (author)Build_it_Bob2010-11-27

Thanks. Id like to mention that the LCD library has come a long way since I developed this project. You may want to use the new library than the one I provide in this project. cheers

Build_it_Bob (author)silverbyte2010-12-04

LCD now working along with serial out !!!
The LCD contrast for my display ( UNIQe/Vision GC-1602I1 ) requires the contrast pin to be pulled to ground via resistor. I used a 1Kohm variable and found that 780 ohms gave the best visability.
This paves the way for many ideas ...THANK YOU Silverbyte and contributors !
Awesome project ...I have it running now and it looks great on the customized board I made for it.

silverbyte (author)Build_it_Bob2010-12-05

Thats awesome im glad your project turned out great. Cheers and happy holidays

Build_it_Bob (author)silverbyte2010-11-28

I hope to have a few hours tonight to try this out. I have an Amicus 18 as well as the Arduino Uno and I enjoy lights and lighting control. The Arduino has a lot more info and projects available, and yours has the right mix for control . I will post back with any progress , and once again great work .

handyman29 (author)2010-11-04

Can I use an Arduino Duemilanove? And also, is the LCD display nessesary or can I just hook up the LEDs and potentiometers to the Arduino? Thank you.

silverbyte (author)handyman292010-11-05

No you don't need the LCD. The LCD is just there to show the 3 different modes and its RGB values. It will still work without an LCD screen.

Yes you can just use a 1RGB led + Arduino Duemilanove. Any Arduino compatible board will work. Although I have extra code to select the different modes with a pushbutton and select its values with the potentiometers

You can remove alot of uneeded code (for the pushbutton and the LCD) , or you can refer to the following link

which is the main function which controls the RGB values.
If your a beginner and new to programming, this is where i'd start.

If your a good programmer then you can attack my code. You'll notice my code needs some cleaning up (project was done within timeframe so i scrambled through everything) but you can tackle it pretty easily.


raikoug (author)2010-06-04

Hi, i use this lcd but I really can't see anything write on... maybe is a bit different couse of white on black... i'm a bit new.. (I use an arduino 2009, the leds with pot and bott work fine) can you hlp me please? thanks

raikoug (author)raikoug2010-06-04

nono... now work... but I don't have clear writes... it give me strange signs: "?" "/" "o" arrows and a think a jap letter... what is going on? :D thanks

silverbyte (author)raikoug2010-06-05

- if you can't see text on screen it can be because of 2 things a) you need to add a resistor or potentiometer on the contrast pins b) You must tie the LCD's R/W pin to ground ( check LCD datasheet) c) check page 6 on the LCD datasheet, - if you get garbage this should be simple. a) change your BAUD rate to a lower rate (to start try 9600) b) reset arduino whenever you change pins on powered unit c) double check all your connectiong. Make sure all your pins are correct. All LCD's are made differently so maybe you pins are mixed up.. Check page 5 in the LCD datasheet Im glad your getting along with your project your almost there... when i first did this project i spent 3 days trying to get my LCD to work. Hope this helps cheers Joe

raikoug (author)silverbyte2010-06-05

I'm really happy of existence of people like you... thanks for all your work! than... I can see the words... but.. aren't the words i should see.. i see strange simbols.. I saw the datasheet at page 5 of my lcd and I found that all pins are the same (only but of 15 and 16 that I have to hookup, they'r the back ground... but that was really easy). now... the problem i that the db pins (the ones responsable of the word mixing I suppose) are exactly the sames as your... and not only... i tried to see the libraries manual.. i hooked them to see only the lcd.. and when I start it... it gives me this strange letters... I've a video: (made by a nokia) thanks for all!!

raikoug (author)raikoug2010-06-06

omg... I saw another wonderfull thing of my lcd (that i suppose to be broken...) I restart the arduino i load the program but nothing... everything work but the lcd.. for I don't know why in the world... I unplud the arduno 11 and 12 from the lcd... than I plug them (casually) to 3-4 ... and it starts writing nonsense characters... and the strangest thing is that If i unplug those 2 pins anfter all this... lcd still write the same things!!! I wish it isn't my poor arduino board...

raikoug (author)raikoug2010-06-06

it's not the lcd... I tried with another lcd and the same history.. strnag symbols... :( what the hell :(

silverbyte (author)raikoug2010-06-07

hmmm heres a hunch... I think you "ENABLE" pin is set to 3 and not 2 in the library. Open up the file : LCD4Bit.cpp :::: //-------------------------------------------------------- int _registerSelect = 12; int _readWrite = 11; int _enablePin1 = 2; int _enablePin2 = 3; int _dataBits[] = {7, 8, 9, 10}; int Enable = _enablePin1; //-------------------------------------------------------- In my library I set the Enable pin to pin 2 on the arduino. I think i may have changed this because im using the PWM on pin 3.... I think in your library its pin 3. Try this, see what results you get.

raikoug (author)silverbyte2010-06-07

i'll try as soon as possible! if it will works I will love you!! :P

raikoug (author)raikoug2010-06-08

nthing.. the pin was right. is there something wrong in the db positions... it's really strange.. :(

silverbyte (author)raikoug2010-06-09

It is strange, but i had the exact same result as you at one point. are you sure these pins are not mixed up Arduino (PIN 11) = LCD Register Select Arduino (PIN 12) = LCD Read / Write I would start a new Arduino sketch, and just plug the LCD and start debugging with that. Also go over to the Arduino webpage and checkout there LCD4Bit library section. Im certain you'll get it soon: Arduino (PIN) 7,8,9,10 = LCD(DB4,DB5,DB6,DB7) Arduino (PIN 2) = LCDenable pin Arduino (PIN 11) = LCD Register Select Arduino (PIN 12) = LCD Read / Write

raikoug (author)silverbyte2010-06-10

I've done it!!! finally, with a 3° lcd I made it!! IT WORKS!!! Thanks a lot for all help you gave me! you are a friend ;) See you soon ^^

silverbyte (author)raikoug2010-06-11

HAHAH!!! awesome... I NEW IT TOO!!! once you get it its pretty damn satisfying. I made 2 or 3 other LCD projects and sometimes i hit the same bump on the road, but patience and persistence is key. you should youtube a video of your project when completed, I'd like to see it. cheers, Joe

raikoug (author)silverbyte2010-06-11

I sure will!! ;) thanks a lot!

raikoug (author)silverbyte2010-06-09

Nothing... I tried but it is always the same, and I tried a lot of combinations!! (i tried the liquid cristal libraries with his connection... but I can't compile couse of and error (I used the examples codes..) so I can't test the connections :( )

silverbyte (author)raikoug2010-06-07

**note: the key line in the code is :::: int Enable = _enablePin1; which is pin 2 ::::: int Enable = _enablePin2 = pin 3 :::

silverbyte (author)raikoug2010-06-07

You'll get alot more out of life by being open source & sharing than if your with a closed mind. I share as much knowledge as I can with everyone about everything (not only computers) ... you'll see it brings you further in life, and it'll make your soul alot more happier.

jman 31 (author)2010-01-11

Silverbyte, this is a great piece of engineering. I have been studying your source code to see if I can use some of it in an unrelated project that I am doing. I loaded your sketch into processing and ran it just to see if it compiled and I got this error: unexpected char: 'i'      And the sketch stops at this line: "#include <LCD4Bit.h> . I have the LCD4Bit folder in the same folder as the sketch. Any clue as to why it's doing that?

Thanks for any advice!

silverbyte (author)jman 312010-01-11

Thanks for positive feedback.

I was at work when I read your email. I don't have Arduino IDE here at work so I decided to install the latest version here at work. I download my project on instructables and tested it out, and i found no problems what so ever with the program.

I have a hunch (almost 100% certain) that the library is not in the correct location. Do not install in "\lib" directory, this is not the library directory. The library should be installed under

(your drive letter):\ (path of arduino ide) \ hardware \ libraries \ LCD4Bit

example:  (using latest Arduino version 0017)

I ran and compiled it with no problems. Give it a go, it should work. If your on a Mac... I don't know how mac paths work bust it SHOULD be the same. (linux as well)

jman 31 (author)silverbyte2010-01-11

Yeah I think you are right. I will give that a try. Thanks for the quick and helpful response!


jman 31 (author)jman 312010-01-11

Yep, that was it! Thanks a lot Silverbyte!


Erik Lindemann (author)2009-12-07

I love it. Absolutely beautiful.
I wish I had access to a workshop like you do. The things I'd make....

Well theres a thing called HACKER SPACES.
Alot of people like you that do not have workspaces usually gather a group of people and rent our a huge lofts or garages or large spaces. they call it
"hacker spaces"

you can check if one exists in your area. Might be worth checking out !!!
(I did in my area, montreal quebec, fantastic hacker space where a group of 20 or so people shared a huge loft to build all sorts of thing, to collaborate, throw parties and become productive.)

Check if one exists in your area.

micha-uhl (author)2009-12-01

when I press the button, the power shorts! The red and yellow wire on the resistor are to change!

silverbyte (author)micha-uhl2009-12-01

I believe your right theres a mistake in the diagram above

This is how the button should be hooked up.

Thanks for noticing and reporting.

About This Instructable




More by silverbyte:Arduino RGB LED Lamp + 4bit LCD Display
Add instructable to: