Make: Projects

Smart Remote Control

Build this easy universal remote and command all your entertainment gadgets from your smartphone!


wp14 20140729 165723 Smart Remote Control

Is your remote control collection getting out of control? With a television, cable box, Blu-ray player, and stereo, not only does each remote take up space, but making them work to turn on the right devices and set the right inputs can be very frustrating! You might consider buying a fancy programmable remote control, but they can be expensive and sometimes don’t offer the control or interface you want. This smart remote control project will show you how to build a device that can send and receive remote control codes from a web page. You can program exactly the functionality that you need from any smart phone or computer!

This project uses the Arduino Yún, which is a special Arduino that’s perfect for network-connected devices. The Yún has two processors, one of which runs the Linux operating system and can connect to wired or wireless networks. The second processor is the same as the one used in the Arduino Leonardo. It therefore has great compatibility with Arduino libraries and hardware.

wp14 20140729 172834 Smart Remote Control
smart easter egg Smart Remote Control

To send and receive remote control signals, this project uses an infrared LED and receiver. Infrared light is invisible to the human eye but easy for electronic sensors to detect. To make the transmission of signals more reliable, devices typically modulate (flash or flicker) infrared light very quickly, so there’s less chance for stray infrared light (like from sunlight) to interfere. An infrared receiver is a small device that can pick up infrared signals modulated at a particular frequency, commonly 38kHz (38,000 times per second). Using an infrared receiver, an Arduino can detect the bits being sent by a remote control. And to play back a remote control signal, the Arduino can flash an infrared LED at 38kHz!

Taking command of your entertainment center is accomplished through a simple web interface which is run locally on the Yún and accessible to most web browsers. The website facilitates basic infrared device control and even allows for multiple commands to be strung together. For example, a ‘Watch Movie’ button might send the control codes to turn on your TV, Blu-ray player, and set the TV to the Blu-ray player input.

This is a moderately difficult project which will require some experience running Arduino sketches and using command line tools. The electronic components for this project are simple and can be easily assembled on a solderless breadboard.

Related

Steps

Step #1: Connect Components

PrevNext
Smart Remote ControlSmart Remote ControlSmart Remote ControlSmart Remote Control
  • Connect the infrared LED to the Yún by running a wire from the LED's anode (longer lead on the LED) to the Yún's digital pin 13.
  • Using a 100 ohm resistor, connect to the infrared LED cathode (shorter lead on the LED) to the IR sensor's ground pin (middle lead on the IR sensor).
  • Connect the IR sensor detection pin (left-most lead when looking at front/rounded part of sensor) to digital pin 11 of the Yún.
  • Connect the IR sensor ground (middle lead) to a ground pin on the Yún.
  • Finally, connect the IR sensor voltage (right-most lead when looking at front/rounded part of sensor) to the 5 volt pin on the Yún.

Step #2: Install Software Dependencies

PrevNext
Smart Remote Control
  • With the MicroSD card inserted in the Yún, power on the Yún by connecting the USB Micro B cable to the Yún and a USB power adapter.
  • Make sure your Yún is already setup and connected to your wireless network. If you need help setting up the Yún, check out the guide here.
  • Connect to the Yún command line using SSH. If you're not familiar with how to do this, check out this guide.
  • After you connect to the Yún's command line, it will show the firmware version. This project has been tested and works with BusyBox v1.19.4 dated 2014-04-10 and later. If you're using an older version, you may need to follow these instructions to update your board.
  • From the command line, execute the following command to update the package manager: opkg update
  • Now install PIP, the Python package manager:opkg install distribute && opkg install python-openssl && opkg install python-expat && easy_install pip This process may take a few minutes. You may see some warnings; they're safe to ignore.
  • Create a directory on the SD card to store Python packages: mkdir /mnt/sda1/python-packages
  • Install the Flask Python web framework: pip install --target /mnt/sda1/python-packages flaskYou may see some warnings; they're safe to ignore.
  • Update Python's package search path: echo "export PYTHONPATH=/mnt/sda1/python-packages" >> /etc/profile
  • Create the directories where the Arduino IDE will upload the web server files: mkdir /mnt/sda1/arduino mkdir /mnt/sda1/arduino/www
  • Restart your Arduino Yún to make sure the Python search path is updated.

Step #3: Load Arduino Sketch

PrevNext
Smart Remote ControlSmart Remote ControlSmart Remote ControlSmart Remote Control
  • Download the the IR library. (This library is a fork I created of the excellent Arduino IRremote library created by Ken Shirriff.)

    Unzip the archive, rename the folder from Arduino_IRremote-master to Arduino_IRremote, and import the Arduino_IRremote folder as a library into your Arduino IDE. Check out this guide for more information on installing libraries.
  • Download the Smart Remote Control Arduino sketch by grabbing the zip file from this location.

    Uncompress the archive and drag the SmartRemoteControl folder into your Arduino sketchbook folder. Open the sketch in the Arduino IDE.
  • Compile the sketch and upload it to the Yún over WiFi by selecting the 'Arduino Yún at ...' option in the port list. Make sure to upload the sketch over WiFi so the necessary python scripts are copied to the Yún! Once the sketch has uploaded, open the Serial Monitor in the Arduino IDE. (Be patient, the first upload can take a few minutes.)
  • Aim a remote control at the IR sensor and press a few buttons on the remote. You should see IR code information displayed in the Serial Monitor. If you don't see codes displayed, double check your sensor wiring.

Step #4: Configure Remote Control Codes

PrevNext
Smart Remote Control
  • You can now configure the activities and remote control codes associated with them by editing an XML configuration file. Using a text editor, open the activities.xml file in the www subdirectory of the sketch's folder on your computer. (From the Arduino IDE, click the Sketch menu and then select "Show Sketch Folder.")
  • Notice the format of the example activities in the file. Each activity node defines a name attribute which will be displayed as a button on the remote web page. Within each activity, the codes node contains a sequence of IR codes to execute. The example activity will first execute a Sony A90 command (power on/off) to turn on the TV, and then a Panasonic command (power on/off) to turn on the Blu-ray player. Each code has a string value which is the direct output of the detected remote code from the Arduino sketch.
  • Add your own activities to the file by copying the example and changing the name and codes. While your remote is aimed at the IR sensor, press buttons and carefully record the detected IR code string. Copy the string into the activity code configuration.
  • Once you're happy with the activity configuration, save the file and upload the sketch to the Yún again using WiFi. Each time you want to update the activity configuration, change the file and upload the sketch over WiFi using the Arduino IDE.

Step #5: Start Web Interface Server

PrevNext
Smart Remote ControlSmart Remote ControlSmart Remote Control
  • To run the server, connect to the Yún over SSH. Execute the following command to start the server:python /mnt/sda1/arduino/www/SmartRemoteControl/server.py
  • If the server starts successfully you should see the following text: * Running on http://0.0.0.0:5000/ * Restarting with reloader
  • If you see an error, check that all the required dependencies were installed in the previous steps.
  • In a web browser, navigate to the URL http://arduino.local:5000/. If your browser doesn't support mDNS URLs (like Windows, Android, and some Linux distributions) instead access http://arduino_ip_address:5000/ where arduino_ip_address is the IP address of your Arduino Yún. The IP address can be found at the bottom of the Arduino IDE when the Yún is connected (image 2).
  • Once the page is loaded, you should see a list of the configured activities as buttons. If you see an error, check that dependencies were installed properly, the sketch was uploaded, and the server is running without errors.
  • To stop the server, press Ctrl-C in the command window where you started running the server.

Step #6: Use Web Interface

PrevNext
Smart Remote ControlSmart Remote ControlSmart Remote ControlSmart Remote Control
  • To use your smart remote control, aim the LED at your electronic devices and press one of the activity buttons. If you don't see all your expected devices turn on, try moving the LED closer to the devices. The range of the LED can be somewhat small, around 6 feet of distance. You can consider adding a transistor to increase the LED range as well. Check out this post for more information.
  • You can also test IR codes by opening the Yún Serial Monitor in the Arduino IDE and sending the IR code as a command. For example, sending "SONY: C A90" (without quotes) would cause the hardware to send a Sony A90 power command. (The "C" above represents the bit length of the command, 12, converted to hexadecimal.)
  • To make the server automatically start on boot, edit the file /etc/rc.local on the Yún (using a text editor such as nano or vi) and add the following line before the "exit 0" line at the end:PYTHONPATH=/mnt/sda1/python-packages python /mnt/sda1/arduino/www/SmartRemoteControl/server.py
  • To use speech recognition, make sure you're running the Google Chrome web browser. Click the 'Speak' button and Chrome should ask for your permission to listen to the microphone. Once you allow microphone permission, say the name of an activity and wait a moment to see if the activity was recognized. For example, to play the 'Movies' activity, click the 'Speak' button, allow microphone access, and say the word 'Movies'. Phrases like 'Play Movies' or 'Run Movies' unfortunately aren't supported — only the exact activity name will be recognized.
  • Enjoy your smart remote control!

Tony DiCola

Tony DiCola is an engineer who works at Adafruit Industries and has a passion for making things that use Arduino, Raspberry Pi, and other embedded platforms.


blog comments powered by Disqus

Related Supplies at Maker Shed

Follow

Get every new post delivered to your Inbox.

Join 28,412 other followers