Introduction: IPhone Universal Learing Remote With Arduino
Hello, and welcome to my first Instructable.
I don't know about you, but I can never find the remote for my TV. It always seems to disappear whenever I need it and then only turns up days later wedged inside the sofa by one of the kids. One thing do I always have with me though, is my iPhone. My iPhone can happily read my email, browses the internet, plays games and even turns my heating on and off. What would be great is if it could only operate my TV too.
Operating an infra red controlled TV with the iPhone gives us a few problems to solve. Firstly, iPhones aren't blessed with an IR emitter. Secondly, how do we know what IR codes to broadcast to operate the TV?
If we had a magic box that could read codes from an IR remote, transmit IR codes to a TV and have a network connection to talk to the iPhone, then this could solve our problems. The box wouldn't have to do much, just handle recording and transmitting IR codes, an App on the iPhone could do all the complicated stuff remembering all the IR codes and sending them at the right time.
So how do we go about making this magic box? Well, an Arduino can drive an IR emitter and read the IR codes using an IR receiver so if we can get an iPhone App to talk to an Arduino, and the Arduino to talk to the TV then hey presto, we have an iPhone TV remote.
Step 1: Required Materials
To make our universal IR Remote server, were going to need a few eternal components to add to the Arduino. We'll need an IR transmitter, IR receiver, a connection to the network and a couple of LEDs to let us know what's going on. The Total list of materials I used was:
- Arduino Uno
- Arduino Ethernet shield
- TSOP4838 IR receiver
- 3 pin IR Transmitter module
- Strip of jumper pins
- 2x LEDs - different colours
- 3x 220 Ohm 0.25W resistors
- 2.2uF 16v electrolytic capacitor
- Hookup wire
- Heatshrink
Tools
- Soldering iron and solder
- Wire cutters
- Multimeter / continuity tester
Miscellaneous hardware
- Case
- Ethernet cable
- USB power supply
- Spare Ethernet port on my home network
- iPhone
Software
- Arduino IDE
- Arduino IR Remote library
- Universal Remote App for iPhone (more on this later)
- Universal IR Remote sketch for the Arduino
Skills Needs
- Basic electronic knowledge of resistors and LEDs
- Ability to solder
- Ability to upload a sketch to an Arduino
- Basic knowledge of IP addresses and networking
Step 2: Making the IR Transmitter (Tx) Cable
Solder three wires onto the IR transmitter module and finish off with heatshrink. Alternatively use a pre-made 3 pin header cable (as pictured) to save a little time.
Step 3: Making the IR Reciever (Rx) Cable
Take the IR receiver module and identify which pins are which. With the sensor facing you and then leads pointing down, pin 1 is on the left, 2 the center and 3 is on the right.
- Solder one of the 220 Ohm resistors onto pin 3 of the receiver
- Solder the 2.2uF capacitor between pins 2 and 3. Ensure the negative (short) lead of the capacitor goes to pin 2.
- Solder flylead wires to pins 1 and 2 and the lead of the resistor.
The resistor and capacitor form what is a basic RC Filter. This helps cut out spurious electronic noise being passed to the IR receiver and interfering with the IR decoding process.
Joints can be finished off with heatshrink to provide some mechanical strength and to prevents short circuits if the wires touch.
Step 4: Making the LED Status Cable
- Solder a wire between the negative (shorter) wires of each of the two status LEDs, and a flylead on to one of them. It doesn't matter which.
- Solder a 220 Ohm resistor to each of the positive (longer) leads of the LEDs, and a wire to each too. Again, finish off with heatshrink.
Step 5: Connecting the Cables to Arduino
The IR transmitter (Tx), receiver (Rx) and status LEDs cable will be connected to your Arduino as follows:
Arduino IR Tx: Data Pin 3 Vcc 5v * Gnd Gnd IR Rx: Data Pin 9 Vcc 5v (via 220 Ohm resistor) Gnd Gnd Status LEDs: Tx+ Pin 5 (via 220 Ohm resistor) Rx+ Pin 6 (via 220 Ohm resistor) Gnd Gnd
* This is not actually connected for the IR transmitter that I used, however there are IR transmitters that do require a 5v source, so I have included this.
In the next steps we'll use some header pins to complete the IR and LED cables to plug in the Arduino. The Arduino Uno itself will be on the bottom layer, the Ethernet shield will plug into that, and finally the header pins on the cables will plug into that making the top layer. Will will make one (6 pin) header connection to the 'Power' set of pins on the Arduino, and two (8 pin) header connections to the 'Digital' pins. Due to a manufacturing error on the original Arduino the digital pins are separated by a 0.16" gap. This is why we will use two 8 pin headers rather than a single strip of 16 pins. We won't be making any connection to the 'Analog In' pins.
While making these cables up this it may be helpful to refer to the table above and pins as labelled on your Arduino and Ethernet shield. You should double check the correct cables are going to the correct Arduino pins.
When soldering, solder to the shorter pin, the longer pin will plug into the Arduino. Once again a small amount of heatshrink can help isolate and mechanically support the connections.
Step 6: Connecting the Cables to the 'Power' Header Pins
Cut a strip of 6 jumper pins. When finished, this will connect to the 'Power' header and use the 5v and ground (0v) pins of the Arduino. Call the leftmost pin 1 and the right most pin 6.
- Solder centre the wire from the IR transmitter and pin 3 of the IR receiver (the one with a resistor) to the 3rd pin of the headers. This is the 5v supply from the Arduino. As mentioned before, my IR transmitter seemed not to use the 5v supply, so I've not connected it in the photos. If your not sure if your IR transmitter uses the 5v or not, then connect it anyway just to be on the safe side.
- Solder pin 2 of the IR Rx to the 4th pin of the header. Solder pin 1 of the IR Tx to the 5th pin of the header. These are both the ground connections.
Step 7: Connecting the Cables to the 'Digital 0 - 7' Header Pins
Cut a strip of 8 jumper pins. Again, we'll call the left most pin 1 and the rightmost pin 8. This will connect the Data lines for the Tx and also connect the status LEDs to the Arduino digital socket pins 0 - 7.
- Solder the wire from the Tx status LED (I've used red) to the 2nd pin on the header (Arduino Pin 6) and the Rx status LED (I've used yellow) to the 3rd pin (Arduino Pin 5)
- Solder the Tx Data pin to the 5th Pin of the header (Arduino Pin 3)
Step 8: Connecting the Cables to the 'Digital 8 - 13' Header Pins
Cut another strip of 8 jumper pins. Again, we'll call the left most pin 1 and the rightmost pin 8. This will connect the ground of the status LEDs and the IR Rx data pin to the Arduino Digital socket pins 8 -13.
Solder the ground wire of the status LEDs to 2nd pin (Arduino ground) and the IR Rx Data wire to the 7th pin (Arduino pin 9).
Step 9: Assembing the Arduino
Stack the Ethernet shield on top of the Arduino. Ensure all the pins are engaged in the correct holes and pressed fully home.
Install the headers into the Ethernet shield. Make sure that the headers are fitted the correct way round and that the two 8 pin headers are fitted in the correct 8 pin sockets. Take time to verify each component lead connects to the correct Arduino pin specified by the wiring table.
If you are satisfied with the wiring, then connect the board to and Ethernet cable, connect the Ethernet cable to a spare socket and connect the USB cable to your PC.
Step 10: Download the Arduino Sketch, Configure, and Upload
Open the Arduino IDE and install the IRRemote library if you don't already have it installed. There are instructions on installing libraries here.
Download my Arduino Universal Remote project from github. This has the Arduino sketch and some support files for the project.
From the Arduino IDE open the ArduinoUniversalRemote.ino sketch. You may need to make a couple of alterations to support your particular network:
Firstly, you may need to change the MAC address specified in the sketch. Some Ethernet shields come with a MAC address assigned to them on a sticker, or you could just generate a random MAC address. Edit the code at the top of the sketch just under the includes to specify your new address e.g.:
... byte mac[] = {<br> 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; ...
Next you will have to assign an IP address to your Arduino. The current sketch does not support DHCP so you will need to find a spare IP address on your network. The code that specifies the IP address is directly below the code that specifies the MAC address. Edit the code to specify your new IP address, e.g.:
... IPAddress ip(192, 168, 1, 80); ...
Once the changes have been made, up load the sketch to the Arduino and open the Serial Monitor. This should show a start up message like this:
Arduino Universal Remote Server server is at 192.168.1.80 Version: 1.0.0
Your Arduino IR server is now up and running.
Step 11: Testing the Arduino and Network Connection
Now we have the server up and running, you should now be able to talk to your Arduino over the network, and start decoding and sending some IR signals.
Testing Decoding
Aim your TV or other IR remote at the IR receiver on the Arduino and press a button. When a valid IR code is received and decoded the Rx Status LED (I used yellow) should flash. Within a few seconds the section Last IR code should be completed with the decode type (or manufacture), value, address and bits values completed. If this does not become populated, its time to check the wiring of the receiver module. Apparently fluorescent lights can also interfere with IR reception, so switch of any fluorescent tubes that my be near by.
Testing Transmission
Now we can successfully decode remote signals, its time to start transmitting. Try decoding a few buttons on your remote and note down some values so we can get the Arduino to send them to your TV. Channel up and down is a good place to start as this produces an obvious change on the TV. Fill in one set of values in the Send Code section and press the send button. The IR Tx status LED should flash, also if you have used the IR sending module I have, then you should see the repeater LED flash too. Hopefully, your TV should now be changing channel. If not, the check the alignment of the IR transmitter. The one I used is very directional. Unless it was aimed directly at the IR receiver on the TV, then it would not function. There is an example sketch with the IR decode library called IRSendDemo that repeatedly sends the same IR code . If you run into transmission problems, edit this code to e.g. send a channel up command to your TV, run it on the Arduino and use this to gauge exactly where the IR transmitter can be placed.
Step 12: Installing the IPhone App
The iPhone App to drive the server is located on iTunes here, or rather will be as soon as the App goes through Apple's approval procedure. Unfortunately there is a chicken and egg situation. These instructions are going to form part of the App submission process, so need to be published before the App can be submitted, but for he moment there is no App publicly available for the instructions to make use of.... As soon as the App is approved, I'll update this step.
Step 13: Configuring the IPhone App - Adding the Server Configuration
Fire up the App.
The first thing you notice is the helpful message that you have no remotes configured, so lets go ahead and do that now.
Tap on the configuration button (the cog icon) which will open the server and remote config screen.
To add a configuration for the Arduino server, click on the + next to the Add Server button. Give the server a name - 'Test' in the example above, and enter the IP address of the server that was configured previously. Once the IP address has been added, the App will test the connection with the Arduino server. If the connection is made, then a green radar icon will appear and we can move on to adding a new remote.
Step 14: Configuring the IPhone App - Adding the Remote
Now the Arduino server has been added, we can now go ahead and add a remote.
Tap on the + button next to Add Remote
On the new remote screen, give your new remote a name, and select a server to communicate with. We only have one server - called 'Test' - so we'll be using that one.
Now we need to select an image to use on the iPhone for the remote. There are three options for this. You can use select one of the pre-supplied remote images, you can take a photo of your own remote, or use an image from your existing photos. The screen shots show the supplied image 'Mini' Remote being used.
Select the image, to return to the config screen. Now tap done and you will return to the main screen with the new Mini remote showing.
Next we'll to start configuring some buttons.
Step 15: Configuring the IPhone App - Adding Buttons to the Remote
Now we can start assigning buttons to the new remote.
Firstly, we need to put the app in record mode. Tap the record button in the top right corner of the screen. The message 'Tap button to record' will appear. Now you need to tap on remote which button you wish to assign. In the screenshots the Vol+ button has been tapped and displays a pulsating circle to identify it.
Next we need to press the button on the physical remote control that we wish to assign to this button. Aim the remote at the IR sensor attached to the Arduino and press a button. The yellow IR receiving LED should flash, then after a few seconds the button on the app should change from a pulsating circle to a dotted line. This signifies that the app has captured the IR code from the physical remote and assigned it to button. You can now go ahead and repeat the process, tapping on the remote on the app, then on the physical remote and assign as many buttons as you wish.
To exit record mode, tap the red button in the top right once more. Now we can move on to testing with your actual device.
Step 16: Configuring the IPhone App - Using the Remote
Now you are ready to use the remote
Tap on any of the buttons you previously configured and they will transmit the correct IR codes to the Arduino server. A green radar icon will appear in the top left of the screen when transmission is taking place. In case you need to be reminded what buttons you have configured, the spyglass icon on the bottom left of the screen will show you all the buttons that you have set up
Congratulations, you should now be able to control your IR device with your iPhone!
Step 17: The Whole Thing in Action
This is a screen recording of the iPhone simulator running the app. This shows setting up a virtual remote, configuring the buttons and operating a TV.
Step 18: Next Steps
I've already started on plans for a v2.0 of the server. I know not everyone has a home Ethernet network, so the next logical step would be to ditch the Ethernet shield and move to bluetooth. For v2.0 I'm also going to move to strip-board instead of the point-to-point wiring. I might even start etching the boards for it - something I haven't done for a few years.
I've got plans for the App too. A pre-configured database of remotes would be a great asset and would save all that time reading in the remote codes and assigning to your virtual remote. If there is enough interest, I could develop an Android version too.
Have Fun!