Building an Infrared Proxy
All of our previous remote control approaches have one major drawback: they
all depend on a serial connection to a PC. In this section, you’ll learn how to
replace this connection with an Ethernet connection, so you no longer need
a PC but only Internet access. You will directly plug your Ethernet cable into
an Ethernet shield connected to the Arduino, so it is available on your network.
Then you’ll connect an infrared LED to the Ethernet shield using the same
circuit as shown in Cloning a Remote, on page 207.
You don’t necessarily have to use your PC’s web browser to access the Arduino.
You could also use the browser on your PlayStation Portable or on your
iPhone. Yes, you can now control your TV set using your game consoles or
your smartphone. Oh, and you could replace the Ethernet shield with a Wi-
Fi shield so you don’t have to connect your Arduino physically to your network
router.
Before we dive into the code, we should do a little planning ahead and make
clear what we’d like to achieve. We’ll build an infrared proxy—a device that
receives commands via Ethernet and turns them into infrared signals. (See
the image on page 212.) To make it easy to integrate the device into a network,
we’ll make it accessible via HTTP. This way, we can control it using a regular
web browser.
We’ll implement only a very small portion of the HTTP standard on the
Arduino—we’ll support only a certain URL scheme. The URLs we’ll support
look as follows:
http://«arduino-ip»/«protocol-name»/«command-length»/«command-code»
We’ll replace «arduino-ip» with the IP address of the Arduino’s Ethernet shield.
The element «protocol-name» can be one of the supported protocols (“NEC,”
“SONY,” “RC5,” “RC6,” “DISH,” “JVC,” or “SAMSUNG”). «command-length»
specifies the length of the command code in bits, and «command-code» con-
tains the command code itself as a hexadecimal number.
Note that the sketch currently doesn’t support Panasonic devices because
they don’t fit our URL scheme.
Let’s assume we’d like to send the code for the power key on a Samsung
remote, and our Arduino has the IP address 192.168.2.42. Then we’d have
to point our web browser to the following URL:
http://192.168.2.42/SAMSUNG/32/E0E040BF
Chapter 12. Creating Your Own Universal Remote Control • 216
report erratum • discuss
www.it-ebooks.info