Introduction: Arduino-controlled RGB LED Infinity Mirror
Update 11/22/2013: Thanks to everyone who voted for this project in the Microcontroller Contest! It was one of three first-prize winners.
Update 9/17/2013: Thanks to everyone who voted for this project in the Arduino contest (I was one of ten "second prize" winners)! If you want to try this project with an addressable LED strip instead of an analog strip, check out the Rainbow Jar project (also an Arduino contest winner).
This is my take on a combination of two classic projects: RGB LED control with an Arduino, and an Infinity Mirror. It's an RGB LED infinity mirror that lets you toggle between an adjustable-speed color-fade mode and a direct-control mode where you individually set the red, green, and blue LED brightness levels. The primary inspiration for this particular project comes from this infinity mirror Instructable and Adafruit's RGB LED Strip tutorial, but there are many more quality resources out there on both projects.
I've done my best to gear this project towards newbies by providing an exact list of materials I used and the exact procedure that I followed. One recurring theme I've noticed in comment sections for other infinity mirrors is a lack of links to specific parts (e.g. exactly what type of LEDs or LED strips were used, what power supply, where to buy the mirrors, the enclosure...). Clearly, if you know what you're doing and want to spend more (or less) money to design a slightly different mirror, you can adjust your materials as needed, use a different Arduino board, etc. You can skip the Arduino entirely and make a pretty simple, cheap infinity mirror if you want (just search Instructables for "infinity mirror" and you'll find a few), or go crazy and spend hundreds if not thousands of dollars (search YouTube for "infinity mirror table" and you'll get the idea).
So, on to the materials list. Remember that this is an exact list of parts that I used, but I gradually cobbled together the supplies for this project over a long period of time. I didn't sit down, compare vendors (e.g. Adafruit vs. Sparkfun) and find the absolute cheapest way to build this. So, feel free to shop around to bring down the cost (and post links in the comments if you find a better/cheaper version of a certain part!). Quantities are just 1 (one) unless otherwise noted, prices are rounded to the nearest dollar as of September 2013.
Materials: Electronics
Update Feb. 2016: A kit with all the electronic materials for this project is now available from Jameco Electronics. Please note that this kit does not include materials for building the mirror frame so you will still need to purchase those separately (see below). I earn a commission on sales of this kit as described at the bottom of this page.
- Arduino UNO R3 with mini breadboard and jumper wires. I have the Getting Started with Arduino Kit from Maker Shed ($65).
- (Optional): Arduino/breadboard holder. The Maker Shed kit didn't come with one - I 3D printed this cool minimalist design I found on Thingiverse.
- 1 meter RGB LED strip ($25). This is an analog strip, which means you can only control the color of the whole strip at once. SparkFun also carries a digital RGB LED strip which has individually addressable LEDs (if you wanted to send pulses of light down the strip one LED at a time, or have some other pattern), but it's more expensive ($45) and you'll need completely different Arduino code. Both strips can be cut to length to fit your mirror.
- Four10K potentiometers ($1 each).
- ThreeN-channel MOSFETs ($1 each).
- SPDT power switch ($1.50).
- 22 AWG hookup wire (black), 100 feet ($8). This is only required if you pref to color-code your V+ and ground connections with red and black respectively. Otherwise you can just use the multi-colored jumper wires that come with most Arduino kits. 100 feet is also WAY more than you'll need for this project, but you can never have too much hookup wire! You can get a smaller 25' roll from SparkFun.
- 22 AWG hookup wire (red), 100 feet ($8). Same note as above, with smaller roll here.
- Barrel jack breadboard adapter ($1).
- 12V/5A DC power supply ($25). This is a big place to potentially save money. The RGB LED strip I used requires 12V, and according to the datasheet, draws 60mA for every 3-LED segment (the smallest unit the strip can be cut into). So at 60 LEDs for the whole strip, that's an absolute maximum of 1.2A at full brightness. I had a 12V charger laying around from some old long-forgotten device, but it was only rated at 0.5A and couldn't light the whole strip. So, I went ahead and bought a beefy supply because I figured it would be useful for future projects anyway. Adafruit and SparkFun both carry smaller, cheaper 12V supplies (1A and 600mA respectively) that might suit your needs just fine depending on the size of your mirror and how many LEDs it will use. You could also scavenge something like an old laptop charger, but be sure to check the output voltage and current specs (usually printed on the label).
Materials: Building the Mirror
Important: there are three main parts that need to fit together to build this: the regular mirror, the frame, and the one-way mirror. First, it's easiest if you can find a cardboard/paper mache lid and a regular mirror that will fit snugly inside it - the parts I bought didn't fit together perfectly, so I had to use a workaround (see Step 6). Second, cutting acrylic can be a pain depending on the tools you have available, so plan accordingly (see Steps 9 and 10). There's also an important consideration regarding the LED strip, which can't be cut to any length - it has to be cut in multiples of 3-LED segments, which are just shy of 2" long - so you want the inside perimeter of your mirror frame to be a multiple of that length. So, I'll link to the parts I used to build my mirror, but you can still follow these directions to build a mirror of a different size or shape.
- 9" diameter circular mirror. I bought this kit of 7 mirrors ($14) with the intent of also making some smaller infinity mirrors.
- Kit of 8", 9", and 10" diameter round paper mache boxes ($9). Important - I bought these hoping that the 9" diameter mirror would fit snugly inside either the 9" lid or the box itself (and because I couldn't find individual boxes for sale on Amazon). It didn't. The 9" lid was just too small, and the 10" box was too big. So, I made it work by cutting out the top of the 9" lid, and just using the rim. This will make sense if you skip ahead and look at the pictures in Step 6. Point being, ideally you should use a mirror that fits snugly inside a paper mache lid or box.
- 1/8" thick 12"x12" sheet of clear cast acrylic (plexiglass). Available on Amazon ($8) and McMaster-Carr ($9).Acrylic is super easy to cut if you have access to a laser cutter. I don't, so I tried using a jigsaw (Step 9) and a score-and-snap method (Step 10). Both worked reasonably well but resulted in some jagged edges, and in hindsight would have worked much better for a rectangular mirror instead of a round one. If you want to build a slightly smaller mirror, McMaster sells pre-cut 6" diameter circles. I didn't shop around much for larger pre-cut circles but you might be able to find them.
- Mirrored window tint. I ordered this stuff from Amazon ($27) but you can easily find this in hardware stores. Probably hard to find in small quantities, so plan on having plenty left over.
- Black paint. I picked up a can of generic black spray paint ($3) at A.C. Moore.
- Optional: if you want to get really fancy, you might be able to order a custom-sized one way mirror, instead of putting mirrored window tint onto a piece of plexiglass. This will probably give you a higher optical quality in your final product, but I didn't look into it.
Tools
- Soldering iron. I have this variable temperature one from SparkFun ($45). You might be able to get away without one, depending on how your LED strip arrives. The SparkFun product page says "You will need to solder on your own wires.", but my strip arrived with all four wires already soldered on. Even so, pushing the ends of the (stranded) wires into a breadboard can be a pain, so I recommend soldering on small segments of solid-core wire to make that easier.
- Lead-free solder ($8).
- Wire strippers ($5), if you don't already have a pair that can strip 22 AWG. Again, you can squeeze by without these if necessary, but I'm betting most people reading this have wire strippers.
- Mini needle nose pliers ($2) if, like me, you're clumsy and hate handling tiny breadboard components with your fingers.
- Power drill (see Step 6 - you can probably just get away with a sharp knife)
- Super glue
- Electrical tape
Got all that? Time to start building!
Step 1: How Does an Infinity Mirror Work?
Not surprisingly, there is no magic involved. The secret is that the infinity mirror actually contains two mirrors with different transmissivity and reflectivity. For all practical intents and purposes, mirrors that we deal with in everyday life are 100% reflective (technically a tiny amount of light will also be absorbed, but we can ignore that for now). That's the regular mirror at the "back" of the infinity mirror (on the left in the diagram above). The tinted window film, however (on the right in the diagram above), only reflects about half of the light that hits it*. This means that, when you sandwich an LED between the two mirrors, some of the light escapes through the front mirror and into your eye. The rest is bounced back off the rear mirror, then into the front mirror again, and this process continues off to infinity - thus the name. But, since a little bit of light escapes each time, each successive illusionary LED that you see will look a little bit dimmer, until they gradually disappear - you can't actually see infinitely many LEDs.
Note that this does not work because the window tint "only lets light through in one direction", which is a common misconception. In order for the illusion to work properly, the side of the front mirror the observer is on (the outside world) must be much darker than the side with the LEDs (inside the infinity mirror). This is the same effect that you see in crime dramas/movies where someone is held in an interrogation room that has a mirror on the wall, but there are people on the other side of that mirror observing as though it's just a window. That only works if the interrogation room is well-lit and the observation room is dark.
*The exact percentages of reflectivity/transmissivity might vary depending on what kind you buy - different levels of reflectivity and transmissivity are actually regulated in different states for use in car windows, Google it if you're curious.
Step 2: Building the Circuit
If you have experience working with breadboards, you can go ahead and assemble the circuit based on the third breadboard diagram above, or directly from the circuit diagram. For newbies I broke it into three steps, hopefully to make things less overwhelming - corresponding to the first three diagrams above:
1) Populate the breadboard with the three MOSFETs, four potentiometers, SPDT switch, and barrel jack adapter. I made these parts "transparent" in the figure above so you can see exactly where their pins go*.
2) Add wires to connect to your power and ground rails. I've color-coded these with red and black here, but remember that you can use whatever colors you want if you just have a multi-colored jumper wire kit and no red and black hookup wire. Notice how one of the breadboard rails is connected to the +12V supply from the barrel jack (which feeds power to the Arduino through Vin), and one is connected to the Arduino's +5V power pin, but they share a common ground. Whatever else you do, don't short the +12V and +5V supplies together!
3) Add wires to connect to the Arduino's inputs and outputs, and wires that you will connect to your LED strip (if your strip came with pre-soldered wires, use those)**. Again, I've color-coded the respective red, green, and blue wires here but your ability to do that will depend on what wire you have available.
* I started making this diagram in Fritzing, but got frustrated with the enormous amount of space components like MOSFETs and potentiometers take up in breadboard view mode (they give a quasi-3D view instead of a "top-down" view, so take up way more space than they do in real life and obscure other things on the breadboard). So, I took a screenshot of the Arduino and breadboard and drew over them in Powerpoint.
** If your LED strip did come with pre-soldered wires, be careful about the color coding. SparkFun's product page notes that the blue and green wires are switched, which can be irritating but won't cause any harm. My strip came with a black wire connected to V+, and getting the polarity reversed on the LED strip could be bad news. I guess I understand not wanting to use two red wires (one for V+ and one for the red LEDs) but I wish they'd use something other than black for V+.
Step 3: How Does the Circuit Work?
- The barrel jack adapter provides a +12V supply to the breadboard. This is required to power the LED strips, and also powers the Arduino through its Vin pin. Technically, the Arduino's built-in barrel plug will accept a +12V supply, which you can then access through the Vin pin, but the LEDs draw a lot of current - more than you want running through the Arduino board. This way, the current "splits up" - the Arduino only draws what it needs, and the high current goes straight to the LEDs through the breadboard. Special thanks to the Adafruit support forums for helping me figure this out.
- The SPDT switch just acts as a toggle to select which "mode" the program is in. The details of the code are explained in the next step, but essentially it just switches between a "color fade" mode that rotates through different colors, and a direct-control mode where you control individual red, green, and blue LED brightness. The middle pin of the switch is connected to one of the Arduino's digital input pins, and the outer two pins are connected to +5V and ground. So, depending on which way the switch is flipped, the program reads a digital HIGH or LOW using the digitalRead() function and acts accordingly (note: SPDT stands for "single-pole double-throw", the Wikipedia page on switches has a nice table summarizing the different types of switches, with diagrams).
- The potentiometers are your "controls" depending on which mode the program is in. In individual-control mode, the three potentiometers control brightness of the red, green, and blue LEDs respectively. In color-fade mode, a single potentiometer controls the speed of the fading. The potentiometers have three pins. Like the switch, one pin is connected to +5V, and one pin to ground. However, unlike the switch, rotating the potentiometer makes the voltage on the middle pin vary continuously between 0V and 5V, instead of just toggling between the two. So, the middle pins of the potentiometers are connected to the Arduino's analog inputs. Then, using the analogRead() function, the Arduino converts that voltage to a number between 0 and 1023 for use in the program (see next step).
- The MOSFETs are probably the trickiest part to understand for a newcomer to electronics. These are required to drive "high power" devices like motors, solenoids and LED strips, which frequently require more current than the Arduino can supply. The Wikipedia page on these is actually rather dense, so I'll try to give a simplified explanation here. The MOSFET has three pins, called the "gate" (G), "drain" (D), and "source" (S). In its simplest form, the MOSFET acts like a valve that lets current flow from the drain to the source. The "gate" controls this valve (think of opening and closing a valve to a garden hose), except that control is electrical instead of mechanical. A voltage applied to the gate from one of the Arduino's output pins turns the MOSFET "on" - allowing high current to flow from the drain to the source, without actually drawing any current from the Arduino. If the voltage to the gate from the Arduino is zero, the MOSFET shuts off and stops current from flowing. This way you can control even enormous motors and lights with a tiny little Arduino, as long as you have an external power supply big enough to handle it.
- I should also mention pulse width modulation (PWM). This is a common technique used to control LED brightness with an Arduino. In short, the Arduino's output pins are digital, so they can only output a HIGH or a LOW (5V or 0V). They can't continuously vary their voltage to adjust something like LED brightness or motor speed. Instead, what they can do is send out very rapid pulses (roughly 500 times per second with the Arduino), much faster than the human eye can see. Each pulse consists of a HIGH segment and a LOW segment, and the relative ratio between the two determines the "brightness" that we actually see. A pulse that is 0% high and 100% low will just look like "off". 100% high and 0% low will be "full brightness", and 50% high/50% low will be about half-brightness. You get the idea. In this circuit, a PWM signal is sent to the MOSFETs, which then controls the high current going through the LEDs, allowing a "fading" effect and adjustable brightness.
Step 4: Arduino Code
Caveat: this probably isn't the most efficient code! Particularly, I'm not sure of a nicer way to continuously monitor the fade-speed potentiometer without copying and pasting the same line of code over and over, or if there's a way to break out of a for loop if you flip the toggle switch (right now, if you switch to individual-control mode while in color-fade mode, the switch won't occur until it finishes the current fade cycle). So, I'll throw that out there as a challenge to anyone who's reading this and wants to post better code. Clearly I'm a mechanical engineer at heart and not a programmer.
// Arduino code to control and RGB LED strip
// Uses a toggle switch to switch between color-fade mode
// and individual RGB control mode
// adapted from http://learn.adafruit.com/rgb-led-strips/example-code
const int RED = 9; // define digital output pins for individual red,
const int GREEN = 10; //green and blue channels
const int BLUE = 11;
const int POT1 = 0; // define analog input pins for three potentiometers
const int POT2 = 1;
const int POT3 = 2;
const int POT4 = 3;
const int BUTTON = 2; // define digital input pin for the switch
int val = 0; // stores the state of the switch input pin
int FADESPEED = 0; // initiate fade speed set by potentiometer
int r = 0; // initialize the red, green and blue values
int g = 0;
int b = 0;
void setup(){
pinMode(RED, OUTPUT); // define digital pins as outputs and inputs as needed
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(BUTTON, INPUT);
}
void loop(){
val = digitalRead(BUTTON); // read the input value from the toggle switch
if (val == HIGH){
// code for RGB color fade
FADESPEED = analogRead(POT4)/10; // set the fade speed by reading analog input from 4th potentiometer
// analogRead will output a number between 0 and 1023, and "delay"
// is in milliseconds, so the biggest delay you'll get here is about
// 1/10 of a second. Divide by a different number to change the max
// fade time.
// fade from blue to violet
for (r = 0; r < 256; r++) {
analogWrite(RED, r);
FADESPEED = analogRead(POT4)/10; // check the fade speed continuously, otherwise
// it won't update until it's gone through a complete cycle.
// Probably not the most efficient way to do this...
delay(FADESPEED);
}
// fade from violet to red
for (b = 255; b > 0; b--) {
analogWrite(BLUE, b);
FADESPEED = analogRead(POT4)/10;
delay(FADESPEED);
}
// fade from red to yellow
for (g = 0; g < 256; g++) {
analogWrite(GREEN, g);
FADESPEED = analogRead(POT4)/10;
delay(FADESPEED);
}
// fade from yellow to green
for (r = 255; r > 0; r--) {
analogWrite(RED, r);
FADESPEED = analogRead(POT4)/10;
delay(FADESPEED);
}
// fade from green to teal
for (b = 0; b < 256; b++) {
analogWrite(BLUE, b);
FADESPEED = analogRead(POT4)/10;
delay(FADESPEED);
}
// fade from teal to blue
for (g = 255; g > 0; g--) {
analogWrite(GREEN, g);
FADESPEED = analogRead(POT4)/10;
delay(FADESPEED);
}
}
else {
// code for individual RGB control with potentiometers
r = analogRead(POT3)/4; // read values from the 3 potentiometers and divide by 4 to set brightness
g = analogRead(POT2)/4; // note that analog read is 10-bit (0-1023), analog write is an 8-bit PWM
b = analogRead(POT1)/4; // signal so you need to divide this value by 4.
analogWrite(RED, r); // write analog values to red, green and blue output pins
analogWrite(GREEN, g);
analogWrite(BLUE, b);
}
}
Step 5: Testing Your Circuit, Code, and LED Strip
Watch this video for a demonstration, and see below for troubleshooting tips if it doesn't work. Notice how there are a couple spots in this video where my LEDs flicker - this must mean I have a loose connection or two bare wires bumping into each other somewhere when I jostle the Arduino around. Watch out for that.
Troubleshooting Tips
- Double and triple check your breadboard connections. It only takes one misplaced wire to stop the whole thing from working.
- Make sure the I/O pins assigned in your code match the pins you're actually using. This shouldn't be an issue if you copied and pasted my code directly, but it can't hurt to check.
- Make sure your LED strip works. Hook the LED strip's V+ wire up directly to the +12V rail on the breadboard, then test red, green, and blue individually by plugging their respective wires into the ground rail. The LED strip has built-in resistors so you don't have to worry about blowing it out. If each color lights up, then your strip is fine, and the problem is elsewhere in your circuit.
- Test your circuit and code with regular LEDs, skip the MOSFETs. If MOSFETs are a bit too new and confusing, you can do a starter version of this project that just uses three plain old LEDs, or a single RGB LED (search common vendors like SparkFun or Adafruit, there are plenty of options). These are low-current and low-voltage enough that they can be driven straight from the Arduino and don't require the MOSFETs, but you will need current-limiting resistors so the LEDs don't burn out. LED blinking and fading are very common starter Arduino projects so I won't reproduce the directions here.
- Skip the potentiometers and test the circuit with a hard-coded color pattern. This lets you make sure the PWM signals and MOSFETs are working, without having to worry about the analog inputs and potentiometers.
Step 6: Preparing the Mirror Frame
1) Use a utility knife to carefully cut out the top of your cardboard lid. Not necessary if you bought a lid/mirror combo that fit together snugly.
2) Paint both pieces a color of your choice. I believe the illusion will work better if the inside of the rim is black, the outside doesn't really matter.
3) Drill a hole in the side of the rim that's big enough for the wires from your LED strip to fit through. In hindsight, I probably should have drilled first and painted second.
Step 7: Mounting the LED Strip
Carefully begin to remove the adhesive paper backing from the LED strip, and press it firmly against the inside perimeter or the lid. Make sure it is centered inside the rim.
Once you've gotten the entire way around, cut the LED strip. Important: the LED can't just be cut anywhere - you have to cut it in 3-LED segments, and you can see the cut lines with labeled solder pads. If you cut anywhere else, the last few LEDs of your strip won't work.
You'll also have to hope that the circumference of your lid matches up nicely with a multiple of the length of these 3-LED segments (about 1 15/16"), otherwise you could wind up with either a gap or a bit of overlap between your first and last LEDs.
Step 8: Assembling the Frame
I super-glued the back of the mirror to the flat (non-painted) part of the cardboard lid from earlier. Now is probably a good time to make sure your mirror is clean and free from fingerprint smudges, because any defects will detract from the illusion in the finished product. I used paper towels to handle/pick up the mirror from this point on, to avoid getting additional fingerprint marks around the edges.
After gluing the mirror to the cardboard circle, I just used electrical tape to wrap around the outer edge of the rim with the LED strip and attach it to the mirror (of course duct tape would work too, but I wanted it to be black). Again, this is just a roundabout process that I had to go through because my mirror didn't fit inside the lid to begin with.
Once you have everything secure, it's probably a good idea to fire up the Arduino and make sure you didn't somehow damage the LED strip or wires during this process.
Step 9: Cutting the Acrylic - Jigsaw
IMPORTANT SAFETY INFORMATION BEFORE CONTINUING: If you're using a laser, acrylic fumes aren't good for you. If you're cutting/sawing/sanding/whatever-ing it, you don't want to inhale the dust either. Be sure to work in a properly ventilated area and wear an appropriate mask if necessary.
So, with the jigsaw: I traced the outline of the 9" mirror onto the acrylic's paper backing. Then I used two C-clamps to hold it onto the edge of a table, and just roughly cut off the corners to make an octagon. Then I went in for successively smaller cuts following the line. The end result wasn't too bad - some cracking around the edges, but no catastrophic breaks that ruined the circular shape.
Some safety notes - first I tried this with a wood blade, which didn't work at all and resulted in some large, jagged pieces of acrylic snapping off when the blade snagged. Got a finer-toothed metal blade at the hardware store and that worked much better. The edges were still quite sharp so I just hand-sanded them to avoid cuts. As usual with power tools, I'd recommend safety glasses for this step.
Step 10: Cutting the Acrylic - Score-and-Snap
The first time I tried this, I used C-clamps to clamp the acrylic down on the edge of a table, and then hit the breakaway pieces with a mallet. That didn't work and resulted in big chunks breaking off inside the circular perimeter (this works fine for straight cuts if you're making a rectangular mirror, though).
Next, I took some helpful advice from the forum thread: I scored the acrylic and then put it in the freezer for a few hours. Then I used the C-clamps again, but snapped the edges off with a vise grip instead of hitting it with a mallet. This worked pretty well, with less cracking around the edges than the jigsaw method. It still had some sharp points sticking out, which I sanded down.
To be fair, I never tried using the vise grips without freezing first, or using the mallet after freezing - so I can't say with 100% certainty whether it was the vise grips or the freezing that made it work better the second time.
Step 11: Applying the Mirror Tint
Next you'll need to cut a piece of mirror tint that is bigger than your piece of acrylic - this means you can handle the extra material on the edges without worrying about fingerprint smudges.
The window tint comes with a clear protective coating on one side, that you need to remove to expose the sticky adhesive. Start in a corner and carefully use your fingernail to peel up the clear layer (this can be a pain to do), then carefully lay the mirror tint flat on your piece of acrylic. I think this is the most frustrating/difficult part of the whole project - you want to get the tint as flat as possible, without any air bubbles. Big air bubbles will be painfully visible in the final mirror and can detract from the illusion. I did my best to get the tint as flat as possible, and "popped" a few air bubbles by pushing them toward the outer edge with my fingertip (using a paper towel so I didn't smudge the window tint). If you really mess up on your first try, you can peel the window tint off most of the way and try laying it down flat again, the adhesive shouldn't lose its stickiness. If all else fails you can also just cut a new piece.
Once you're happy with the appearance and smoothness of your window tint, use scissors to cut around the outer perimeter so it's flush with your piece of acrylic.
Step 12: Attach One-Way Mirror to the Frame
*Here I'm just following the directions I've seen on other infinity mirrors. Optically, it should work in either direction, as discussed in Step 1. Maybe the acrylic is just harder to scratch/easier to clean, so it's better to have that facing out...honestly I'm not sure.
Step 13: Light It Up!
I want to make this Instructable as clear as possible for beginners - so if you saw something that wasn't clear, or I skipped over/implied something that you think should be spelled out, please leave a comment to let me know.
Thanks for reading! Here's a video of the final product: