RGB Mood Light – Arduino Project

I like shiny things. Shiny things are nice, pretty, and super mesmerizing. Last summer, before playing around with my Carrotlights, I had my first go at playing around with LEDs. I set out to make a RGB Mood Light, a simple project supposedly for beginners: three LEDs would each fade in and out, shifting the color of the moodlight gradually and beautifully. With the help of friends and instructables, my project began!

I. Hello, Arduino!

I don’t have any programming experience whatsoever – I once tried to sign up for an intro programming class at school, but class conflicts forced me to drop it. Any programming language is just as foreign to me as Swahili or German. Nevertheless, Dan convinced me that programming an Arduino wouldn’t be as impossible as I imagined it to be. So, I gave it a shot.

File>examples>basics>blink

These were my first couple of clicks on arduino.exe. Clicking a green arrow to upload the simple program onto my arduino, hooked onto a breadboard and an LED, was absolutely the coolest thing ever. Straightaway the LED was blinking red like a cylon. I messed around for a while, trying out a bunch of different example programs. In the end, ‘blink’ and ‘fade’ became my templates.

I made three programs total for my to-be mood light: “RGB_fade,” “RGB_strobe,” and “heartbeat”

The first two names speak for their functions, I think. The last one with the horribly cheesy name was based off ‘blink’. It used only the red LED which, first blinks slow, then faster and faster and faster like an excited heart :) It was the simplest of the three, but I had fun with it – when recording the video, I cut out a little paper heart and put it on the diffuser, so ‘heartbeat’ actually had a heart outline. Here’s my program:

>> Here, I used ‘volatile’ since I was going to change around the tempo of the beats later on. I set the initial delays to emulate what a real heartbeat might look like – the ratios are really inexact, but when tested with the LED, the timing looked convincing enough!

>> Here comes the infinite loop of heartbeats, trying to mimic systoles. Since the rhythm of heartbeats is STRONGweak, I set the first and third blinks to high and the other two to low. The delays were as defined above.

>>After going round the loop once, the minus equals took care of the artificial heart getting excited. delayTwo and delayThree would be shortened little by little until they each reach their min. delays, 100 and 500, respectively.

RGB_Strobe

Nothin like a makeshift diffuser from paper towels!

Once this cute little job with anxious, nervous, love-struck hearts was over, I got onto strobe-mode. ‘RGB_Strobe’ was also based off ‘blink’, the handy dandy example program. My goal in this one was to get a steady light that changed color at each blink.

>>I experimented a bunch here, trying different combinations of the three LEDs in HIGH or LOW brightness, each followed by the same delay time. Turning on a green, then a blue made aquamarine, and then turning off the green gave me blue, adding red gave me purple, so on and so forth.

RGB_Fade

This was my actual mission from the beginning – beautiful everchanging shiny lights that draw you in for hours and hours and hours… Looking at it now, the program is easier to understand, but trying to digest and define so many new functions in my head at once was the most baffling thing. But the result was so satisfying :)

#define green 11#define blue 10 #define red 9#define delayTime 25

void setRGB(int, int, int);

int greenState = 127; int blueState = 255;int redState = 0;

>> Three LEDs again. Initially, Blue is at max brightness, red is at min. Green is intermediate.

boolean greenUp = true; boolean blueUp = false; boolean redUp = true;

>> So naturally, blue’s brightness will have to go down while the other two go up. Thus, true, false, true for green, blue, and red, respectively.

void loop () { if(greenUp) { if(greenState >= 255) {greenUp = false;} else {greenState++;} } else { if(greenState <= 0) {greenUp = true;} else {greenState–;} }
>>Loop again! I used if and else directions within if and else directions to guide the lights. The one right above says that if green is currently getting brighter, and its brightness hasn’t reached max(255) yet, then keep increasing(++). And if green is at min(0), then make the brightness increase. If it isn’t at 0, then keep decreasing brightness.

>>This is repeated for blue and red, but the three LEDs are all out of sync since their starting points were different. The result? Pretty lights!

II. Arduino + Breadboard = Magic!

III. Making the Circuit Board

Now that I had all of the programming I needed, I could get onto making an actual mood light that is not on a bread board. I used EAGLE to design the board.

Schematic

The hardest part was probably making the schematic – unfamiliar abbreviations, so many pins on the atmega, wires criss-crossing everywhere.. Once the schematic was done though, I had fun routing paths on the board since it was like puzzles. Connecting here and there making sure there aren’t overlaps in the paths, rat’s nest. More connections, rat’s nest. Rat’s nest, rat’s nest, rat’s nest. It was so exciting to see that my board was starting to look neat like an actual circuit board!

Tadaaaa. There it was: a beautiful, geometric circuit board of green, blue, and black. I printed it at MITers, stuck it in some ferric chloride, then began soldering. I’m still very new to soldering, and I’m awfully slow at it, but I like shiny things and solder is shiny, so naturally we got along. (I ended up soldering almost the entire board to make it look nice >_> )

IV. Fixing

When I was done soldering everything, my friend and I wanted to get the program in it right away, but for some reason, the board wasn’t letting us. It turns out, my first go at eagling wasn’t so perfect, after all. Two traces were overlapping on my shiny board :(

I hope it’s not too hard to tell, but the thin blue trace overlaps with the second pin from the right. Should’ve DRC’d! The design rule check gave me a bunch of clearance errors(which I don’t care too much for) and one overlap right there. Here’s the fixed one.

You can see that now, the trace goes smack in between the ATmega8 pins instead of on them. This would’ve fixed the board.

But since I didn’t want to make a new board after all the soldering and the drill pressing, we added just a jumper to replace one of the bad traces.

Less shiny, more functiony!

Voila! Problem solved.

V. AVR Studio

Only one thing remained to be done – I was done with all the hard stuff.

Using Atmel Studio, I programmed the ATmega8 with RGB_Fade. Couple of clicks later, the circuit board was behaving just like the breadboard :)

I found a switch, a battery, and a battery holder, and added them on – it doesn’t look elegant, but it works. Once I have time, I’m definitely going to try for a mood light that can plug into AC power plugs instead of using batteries.