Introduction: Arduino Controlled RGB LED Nightlight

Needed a nightlight for my boys and wanted something more than the normal plug in. They wanted one they could pick the color of and one that wold change color.

Easy - An Arduino, RGB LED and some PWM!

Picking the color was the issue. I decided on the one button solution - a rotary encoder with push button switch.

It also needed to be rugged. I went with a die-cast enclosure and a wrinkle black finish. I love the look of wrinkle black and satin chrome - reminds me of my favorite vintage Starrett tools.

I decided against batteries in favor of a plug in. A bright LED and an Arduino would drain batteries faster than I wanted to buy or charge them.

Looking at some of the very cool LiPo tech on the market today I might go with that option. I'd need a slightly larger enclosure or make a custom board but charge in the day/glow in the night would be cool...

Step 1: The Hardware

I didn't want to use a Duemillenove or Uno due to the larger PCB size so I went with the fantastic Adruino compatible RBBB from Modern Device. I love the die cast enclosures from Bud Industries. I went with one of the smaller ones - part # CN-5701. Just big enough to shoehorn a RBBB with a bit of room to spare for the other components.
I had a wall wart, power jack and common cathode RGB LED in my parts bin so the only additional component needed was a rotary encoder.

After assembling the RBBB (instructions are easy to follow) there are only 3 parts to connect.

First - the LED. I soldered the appropriate resistor for a 5V supply to the the RGB anodes. Check the data sheet for your RGB LED. If you don't want to do the math there are dozens of online calculators that will tell you what size and wattage resistor to use for a given forward voltage, drop and current. After clipping the leads as short as I could and soldering them up I put heat shrink tubing over each resistor and lead. I was lucky and found some red, green and blue wire in my scrap bin. 2" of each is plenty.

Finally - power. and with the plug I had that had to wait for final assembly.

Step 2: The Software

Software is pretty plain vanilla -

First - define constants and initialize global variables

Setup - attach interrupts, set pin modes and turn on pull-ups.

Loop - calculate the next color in the fade and set PWM to make that color.

Interrupts - button press or encoder rotation.

I found some helpful code for smooth color fades on the Arduino Forum.
That with the encoder and interrupt tutorials got me all the parts I needed.

A couple hours of copy, paste and debug had things working.

Step 3: The Enclosure

Pretty straight forward stuff.
Locate and center punch the 2 holes on the lid - one for the LED and one for the encoder.
Same for the power connector on the side.
I spot drilled then step drilled the holes to size.
After drilling I de-burred the edges and sanded the exterior of the box with 400 grit wet dry sand paper and wiped it down lacquer thinner to remove all the residue.
I then painted with black wrinkle finish following the instructions on the can.
After the paint had cured I cleaned up the holes and countersinks with a countersink bit.
I also used a very sharp utility knife to trim the wrinkle the had gotten on the mating surfaces of the enclosure.

Step 4: The Assembly

It's a tight squeeze but it will all fit.
My first step was to cut a piece of plastic that fit the bottom of the enclosure. In the event that something on the board or other part touched the enclosure I didn't want a short.
After sanding off all the programming header traces and insulating that bit of the board with nail polish I placed the RBBB as far to one side as possible.
This barely leaves enough space for the encoder.
Attach the encoder to the lid, pop the LED into the panel mount bezel and use your tweezers to position wires as you close the lid.

As soon as the lid is withing 1/8" or so start the screws in the corners and then tighten each in turn to snug everything together.

Make sure you don't pinch a wire between the box and lid.

Step 5: And Done!

Power it up and you should be set!

Lots of possible firmware upgrades on the drawing board - all using the encoder to program nightlight behavior.
Upgrades include ability to set:
  Color Transition Speed
  LED Brightness
  Shut-Off Tmer.

Microcontroller Contest

Participated in the
Microcontroller Contest