Introduction: Magic Wand TV Remote
One night about a month or so ago, I was watching an episode of The Big Bang Theory. In this particular episode, Howard and Raj were controlling their TV using a MAGIC WAND TV REMOTE!!!!!! Upon witnessing this sheer awesomeness, the preteen Harry Potter Fangirl inside of me had a minor heart attack.
Of course after seeing the episode, I did a quick google search to see if this Magic Wand TV Remote actually existed, and I came across the Kymera Wand. I was tempted to purchase this product, but decided against it. I had been wanting to learn how to work with Arduino for quite some time, so I decided that making my own Magic Wand TV Remote would be a great way to force myself to do just that.
In case you are not familiar with the Kymera Wand or the episode of The Big Bang Theory that I mentioned, a Magic Wand TV Remote functions without pressing any buttons. By waving the wand in different ways, different commands are sent to your television. I have programmed my Magic Wand TV Remote to turn the TV and cable on and off, control HDMI functions, and to turn volume and channels up and down.
Step 1: Accio Materials and Tools!!!!!
Quit being a muggle and gather the following materials and tools! You will need the following....
Materials:
Arduino Micro (with pins)
MPU-6050 3 axis Gyroscope + Accelerometer (with pins)
6V Battery Holder (you will need one shaped exactly like the battery holder I have linked to)
Infrared LED (you can buy a new LED or take one from an old TV remote)
1x 100Ω resistor
Gauge Wire
4x AA batteries
1x 3M nut
1x 3M screw
Solder
Elmer's Model & Hobby Cement (or equivalent glue)
LED (optional but HIGHLY RECOMMENDED!!!!)
Additional resistor (if you use the optional LED, you will need to use an appropriate resistor)
Tools:
Breadboard
Jumper Wires
Micro USB cable
3D printer
Soldering Iron
Sandpaper
Hex Wrench or Screw Driver (for the M3 screw)
TV remote for the TV you are trying to control
Step 2: Set Up Your Arduino Micro and Infrared Reciever
Let's get started! The first thing that you need to do is set up your Arduino Micro so it is attached to your Infrared Receiver using a breadboard and jumper wires. The pins that you need to connect are as follows:
Infrared Receiver | Arduino Micro |
---|---|
Left Pin | Pin #11 |
Center Pin | GND |
Right Pin | 5V |
Please keep in mind that when I mention left, center and right pins, you should be looking at your Infrared Receiver from the rounded side, not the flat one.
Step 3: Download IRLib
The first piece of information you need to gather is a set of codes transmitted by your TV remote. TV remotes work by sending a series of pulses using Infrared LEDs. These pulses are then received by the TV, where they are decoded so that the TV can carry out the corresponding command.
One thing that is important to understand before embarking on this project is that pulses submitted by TV remotes usually differ between brands and models. Because of this, the code that I have developed to use with my Magic Wand TV Remote will most likely differ from yours if you choose to make one yourself.
To get the correct code from your TV remote, you will need to downloadIRLibby Chris Young. This library is a variation of Ken Shirriff's IRLibrary. From what I have read, IRLibrary is great, but it is not compatible with the ATmega32u4 microcontroller which is used by the Arduino Micro.
After downloading this library, you will want to save it in the following location:
Documents > Arduino > libraries (I have a Mac, so this location might be slightly different on a PC)
Step 4: Decode Your TV Remote
After you have added the IRLib to the libraries folder, you will need to find a file titled IRrecvDump.ino. You will find this file located in the following location:
Documents > Arduino > libraries > IRLib > examples > IRrecvDump
Open up IRrecvDump.ino using Arduino software and upload it to your Arduino Micro. Make sure that under Tools, you have selected Arduino Micro as your board along with the correct serial port.
Next you will need to grab your TV remote and open up the serial monitor in the Arduino program. Point your TV remote at the Infrared Receiver attached to your breadboard, and one at a time, press the buttons on your remote that you would like to decode. After pressing a button, your serial monitor should show a code similar to that in the image that I have included above. You will see numbers in your serial monitor decoding the bit stream, but the only information you will be needing is from the header. The information we need from this header includes the protocol name, function code and number of bits. For example when pressing the 'Channel Down' button, the information that I need from the header is as follows:
Decoded Panasonic Old(5): Value:36F121 (22 bits) |
There are many protocol names, and this library supports the following:
NEC, SONY, RC5, RC6, 2 PANASONIC_OLD, JVC, NECX, HASH_CODE, 3 LAST_PROTOCOL=HASH_CODE |
If you are pressing down a button on your remote and read the protocol name 'Decoded Unknown', try holding the button down for several seconds to see if a different name appears. 'Decoded Unknown' is usually paired with function code 0 and 0 bits, so you will not be able to retransmit this information.
Now you will need to simplify the information from the header. Write your protocol name as it is written in the box that I have included above instead of how it is written in your serial monitor's header. An example of how I wrote my code is as follows:
PANASONIC_OLD, 36F121, 22 |
The last thing you should do is add '0x' before your function code, for example, mine would read:
PANASONIC_OLD, 0x36F121, 22 |
Save this code in TextEdit or a similar text document and repeat for the rest of your TV remote buttons.
Step 5: Set Up Your MPU-6050 and Infrared LED
Now that you are done gathering codes from your TV remote, you can remove the Infrared Receiver from your breadboard. It is time to start working with your MPU-6050 and Infrared LED. To set up these items, the following connections have to be made:
Arduino Micro | MPU-6050 | Infrared LED |
---|---|---|
5V | VCC | x |
GND | GND | x |
Pin #3 | SCL | x |
Pin #2 | SDA | x |
RX | INT | x |
Pin #9 | x | 100Ω resistor, anode(+) |
GND | x | cathode(-) |
As pictured above, make sure that you attach your Infrared LED close to the end of the breadboard and fold it over the edge so that the LED lays parallel to the breadboard pointing sideways instead of up. This needs to be done so you can later test motions for the Magic Wand TV remote with all of your components still on your breadboard.
Step 6: Reading Raw Values From Your MPU-6050
It is time to begin working with our MPU-6050! To begin, you will need to use the sketch that I have attached at the bottom of this step written by Arduino User JohnChi. This sketch reads raw Accelerometer and Gyroscope values as well as Temperature. For this Instructable, all we need to concern ourselves with are the raw Accelerometer values.
Once you have uploaded this sketch to your Arduino, open up the serial monitor and start waving your breadboard around. Take note of which values are changing when you move or tilt your breadboard.
Attachments
Step 7: Coding for Final Arduino Sketch (Swinging/Tapping Motion)
Now that you understand how to read raw values from your MPU-6050, it is time to select values for the final Arduino Sketch. Through trial and error, I have come to the conclusion that the best way to think about coding for different TV commands is by dividing our motions two categories: Swinging/Tapping and Twisting. In this step, I will go over selecting values and coding for Swinging/Tapping motions. Twisting motions will be discussed in the next step.
The first thing you will need to do download the sketch included at the bottom of this step. The sketch includes elements from JohnChi's sketch (included in the previous step), Chris Young's IRsend Demo sketch, along with some of my own coding.
For an example, I am going to work with the 'Volume Down' command. For 'Volume Down', I have decided that I want to use small taps down to execute this command. With the MPU6050RawValues.ino sketch uploaded to the Arduino, I took note of which Accelerometer values were changing when I used a downward tapping motion with my breadboard, Arduino and MPU-6050. I noted that Accelerometer values were changing in the Y and Z axes. Using 'greater and less thanstatements', I then took note of which raw MPU-6050 values could be included in the motion. For Accelerometer values in the Y axis (or AcY), the raw values were usually greater than 7000 when angling the breadboard slightly down. The Accelerometer values in the Z axis (or AcZ) were generally less than 10000 when using the same motion. Using '>' and '<' symbols, I began to write my code like this:
AcY > 7000 and AcZ < 10000 |
In order to include these values within the MagicWandTVRemote.ino sketch, we will need to replace the word 'and' with '&&'. We will also need to include these values within an 'if statement' which requires the addition of parentheses and an end bracket. In my case, the code would look like this:
if (AcY > 7000 && AcZ < 10000) { |
You can add as many or as few 'greater and less than statements' as you would like to as long as you include '&&' between each one. Don't feel that you need to include only two just because I did.
The next thing we need to do is define how many times our code needs to repeat. Because swinging/tapping motions requires our code to start sending while the Magic Wand TV remote is not pointing at the TV, we need to make sure the signal is still being sent by the time the remote is pointing at it. It is important to play around a bit to find the right value because if you don't repeat the signal enough times, the LED will not still be transmitting the signal by the time the remote is pointing at the TV. On the other hand, if you repeat the signal too many times, you run the risk of the code being sent out too many times causing the code to be sent to the TV multiple times. This is where your optional LED light and resistor can come in handy. If you swap out the Infrared LED and resistor for a visible LED and resistor, you will be able to practice moving your breadboard in the way you would like to move your Magic Wand TV Remote, and see If the LED is blinking the correct number of times. It is a lot easier to swap out LED's then have to hold a camera up to the Infrared LED to see what it is doing.
The code for using a repeat is as follows:
for (int i=0; i <= 5; i++){ |
The number that needs to change based on how many times you want to repeat your command comes after the '<='. In my case, I wanted to repeat the command 5 times. Since small taps down allowed me to return my breadboard to a point where it was pointing at the TV fairly quickly, I didn't need to repeat the command many times. In contrast for the command 'TV-Power', I decided to do a larger swing down. It took me a little longer to point the remote at the TV so I had to repeat the command 15 times.
Lastly, we need to include the correct code that we found in the Decode your TV Remote step. I determined this code to be:
NEC, 0x20DFC03F, 32 |
This code needs to be inserted between the parentheses in the statement 'My_Sender.send( );' so in my case, the code would look like this:
My_Sender.send(NEC, 0x20DFC03F, 32); |
Lastly, I added a short delay which should read like this:
delay(100); |
All together, you code should look like this:
if (AcY > 7000 && AcZ < 10000) { for (int i=0; i <= 5; i++){ My_Sender.send(NEC, 0x20DFC03F, 32); delay(100); }} |
Whatever you do, do not forget the two brackets at the end! One bracket ends your 'if statement', and the other one ends your 'repeat statement'. Your code will not work if you forget these brackets.
To integrate the values that you have found into the MagicWandTVRemote.ino sketch, just scroll down to the second half of the sketch and replace the values that I have found with your own. Make sure that you test your code with all of your components attached to the breadboard to make sure that you can actually control the TV.
Attachments
Step 8: Coding for Final Arduino Sketch (Twisting Motion)
Coding for twisting motions is different than coding for swinging/tapping motions mainly due to the fact that when using twisting motions, your Magic Wand TV remote will always be pointing at the TV. This is not the case with swinging/tapping motions because the code begins to send before you point your Magic Wand TV remote at the TV. Because of this, there is no need to use a 'repeat statement' when using twisting motions, but this makes the use of 'delay' extremely important!
I am going to continue working with the 'Channel Down' command that we earlier worked with in the Decode your TV Remote step. For 'Channel Down', I have decided that I want to twist my remote to the left. With the MPU6050RawValues.ino sketch uploaded to my Arduino, I was able to see which Accelerometer values were changing when twisting my breadboard to the left. I noticed that Accelerometer values in the Z axis (AcZ) were generally less than 5000 and greater than 0. In addition, Accelerometer values in the X axis (AcX) were generally less than -4000. Using what we learned in the last step, the first line of our code should read:
if (AcZ < 5000 && AcZ > 0 && AcX < -4000) { |
Next, I included the code that I found while decoding my TV remote within the statement 'My_Sender.send( );'. The code would be written like this:
My_Sender.send(PANASONIC_OLD, 0x36F121, 22); |
The next thing we need to do is add a delay. This is a very important thing to add because without a delay in your code, the command will repeat over and over again. A delay allows you to have time to twist your remote upright without accidentally sending out functions multiple times. I decided that I wanted to delay the command two seconds so I wrote my code as follows:
delay(2000); |
1000 = 1 second, so you can alter your code accordingly.
Using these elements, your final code should look like this:
if (AcZ < 5000 && AcZ > 0 && AcX < -4000) { My_Sender.send(PANASONIC_OLD, 0x36F121, 22); delay(2000); } |
Note that you only need to add one bracket. There is no 'repeat statement' so you only need to include a bracket for the 'if statement'. Once you are done, replace the values I have found with your own in the MagicWandTVRemote.ino sketch and upload it to your Arduino. Congratulations! You are now done coding!
Step 9: Download and Print the 3D Models
To house the electronics, you will need to download and print the included 3D models. I printed these models using both a raft and supports. When printing, the inside of the model(with the cutout rectangles) should be facing up so that the support material is on the outside of the model.
I printed these models on a Makerbot Replicator 2 3D printer. The files TopLong.stl and BottomLong.stl do not fit lengthwise on the build plate, but do fit diagonally across.
When you are done printing, remove the support material and you should be good to go!
Step 10: Glue Together BottomShort.stl and BottomLong.stl
Using the Elmer's Cement Glue (or equivalent), glue together the two models that you printed from the files BottomShort.stl and BottomLong.stl. To get a stronger adhesion, rough up the sides that need to be glued together using sandpaper.
Step 11: Solder Your Arduino Micro, MPU-6050 and Infrared LED
The next step is to solder your Arduino Micro and MPU-6050 using gauging wire to connect the pins. As I am not very experienced in soldering, I found this step to be extremely difficult. Luckily I found this great tutorial on Youtube which helped me quite a bit.
Make sure when soldering to use as little gauging wire as possible. The 3D printed parts do not have enough extra space to fit large amounts of extra wire. To make sure your Arduino and MPU-6050 fit properly, test them out by placing them inside their designated spots inside of your 3D printed parts as you solder.
To prepare to solder on the infrared led, you will want to cut two long pieces of gauging wire that each stretch from the end of the remote to their corresponding pins. When soldering on the Infrared LED, we want as little space between the LED and the end of the remote as possible. If you do this correctly, the LED should be centered with the hole on the end of the Magic Wand TV remote when gluing all the parts together.
Solder the gauging wire onto the correct pins and solder your 100Ω resistor onto the end of one of the pieces of gauging wire. Solder the cathode(+) onto the resistor and the anode(-) onto the other piece of gauging wire. It is a good idea to include heat shrink tubing around your anode to ensure that the two LED terminals don't accidentally touch.
Step 12: Solder Your Battery Holder and Slide Switch
To begin soldering your Battery Holder and Slide Switch to the Arduino, you will need to trim the wires on the battery holder to just span the length from the correct pin on the bottom of the Arduino to the hole cut out of the file TopLong.stl.
Begin by soldering the black wire to the GND pin. Next, solder the thered wire to any one of the corner pins on the Slide Switch. The slide switch that I purchased has 6 pins, 3 on each side. Cut a piece of gauging wire that can span from the Slide Switch to the bottom of the Arduino. Solder one end of the gauge wire to the center pin on the same side of the Slide Switch that you soldered the battery holder to. The other end of the gauge wire needs to be soldered to the VIN pin on the Arduino.
If you have soldered everything correctly, you should be able to use this switch to turn you Magic Wand TV Remote on and off.
Step 13: Insert Your M3 Nut Into the 3D Printed Part
Inside of the part you printed from the BottomShort.stl file, there is a hole that can fit an M3 nut. The fit is pretty snug so if you can't push the nut in with your fingers, grab a hammer or another small heavy object and give it a good whack! This should the nut to fit tightly within the hole.
Step 14: Glue It All Together!
Yay, you're almost done! The last thing you need to do is glue everything together.
All of the 3D printed parts need to be glued together except for the part printed from TopShort.stl. Since we have already glued two of the parts together, the only part we need to glue on is the one printed from TopLong.stl. Grab your Elmer's Model & Hobby Cement (or equivalent) and apply the glue to the edges of the parts that you want glued together. It is very easy for wires to pop out while gluing, so make sure you are being patient and looking out for anything not in place. All of the components fit very tightly within the 3D printed model so the parts have a tendency to want to separate. Apply pressure to the pieces by squeezing them together with your hands while they are drying.
Also, make sure your Slide Switch is popping through it's designated hole. Adding a little bit of glue will help the slide switch to stay in place as well. I found it was easier to apply to glue to a thin object which I could use to brush the glue between the slide switch and the 3D printed part. I found a spare piece of PLA filament to use, but anything thin such as a toothpick, end of a paint brush or Q-tip would work.
Lastly, pop your 3D printed part from the file TopShort.stl in place and secure it with an M3 screw.
Step 15: Blimey, You're Done!!!!!!!!!
Woohoo! You've made a Magic Wand TV Remote! 10 points for Gryffindor!!!!!!!!
Go call your friends, show them your remote and watch them be amazed! Most people who I've explained this project to either think I'm the coolest person they know.....or the strangest. If you make this remote, you will probably get similar reactions.
Hope you enjoyed!