Using Apple IR Remote to Control Arduino

by dcaditz in Circuits > Arduino

1368 Views, 2 Favorites, 0 Comments

Using Apple IR Remote to Control Arduino

IMG_2112.jpg

The IR (infrared) remote control that comes with many Apple TVs and computers is a nicely designed device and you or a friend may have more than one of them stashed away unused in a drawer. This Instructable will show you how you can use your Apple IR remote to control an Arduino. While it can be used for almost any functionality, here I show how to use the IR remote to step through a menu on an LCD screen to select display units - Celsius, Fahrenheit or Kelvin - for a digital thermometer. I use a hacked Arduino Mega / Ramps hardware platform, which you can read about in my previous Instructable here. This platform is powerful, inexpensive and comes with a handy LCD and controller board. The code can easily be adapted to another Arduino by defining the correct pin mappings.

Supplies

  • Arduino IDE
  • RAMPS 1.4 kit including: Arduino Mega 2560 R3 RAMPS 1.4 shield LCD display(Kit can be obtained from numerous vendors. I used this one from Amazon)(There may be a newer RAMPS board available when you read this.)
  • NTC Thermistor (e.g., this one)
  • Apple IR Remote (other remotes can also be used with slight modification to the code)
  • IR receiver TSOP38238 or similar (e.g., this one)
  • Three jumper wires for connecting the thermistor to the RAMPS TEMP0 header

Set Up Your IDE and Test Your IR Remote

MEGA RAMPS IR_bb.png

Now you have to assemble your RAMPS kit and connect your TSOP38238 IR
receiver as shown in the diagram. You can inspect the TSOP23838 datasheet here. We will connect the TSOP38238 to the RAMPS AUX 2 header as follows:

  • TSOP38238 data pin 1 to RAMPS AUX2 pin 7
  • TSOP38238 Gnd pin 2 to RAMPS AUX2 pin 2
  • TSOP38238 Vcc pin 3 to RAMPS AUX2 pin 1

Now, fire up your Arduino IDE and start a new file. Select Tools->Manage Libraries and in the search field type "IRremote". Install the IRremote library by shirriff. The latest version at the time of writing this Instructable is v.2.8.0. This library is being actively maintained and there may be some changes in later versions. Read through the release notes for necessary code modifications if you have a later library version.

Once the library is installed you will see several example sketches in File->Examples->IRremote. Open up the IRreceiveDemo example sketch.

In order to run this demo on our MEGA/RAMPS platform, you will have to change the IR data receive pin to 44. Comment line 14 and add a line setting IR_RECEIVE_PIN to pin 44:

//int IR_RECEIVE_PIN = 11;
int IR_RECEIVE_PIN = 44; // D44 on MEGA = AUX 2 pin 7

This is because pin D44 on the MEGA is mapped to AUX2 pin 7 on the RAMPS (where we have physically connected the IR receiver data pin). Now upload and run the IRreceiveDemo sketch and open the serial monitor to view the results. If things are working you should see something like the following:

START C:\[YOUR_FILE_PATH]\IRreceiveDemo.ino from Jan 21 2021
Enabling IRin<br>Ready to receive IR signals at pin 44
Protocol=NEC Data=0x77E15061
Protocol=NEC Data=0x77E13061
Protocol=NEC Data=0x77E16061
Protocol=NEC Data=0x77E19061
Protocol=NEC Data=0x77E1A061
Protocol=NEC Data=0x77E1C061

The last 6 lines are responses to clicking the Apple remote up, down, left, right, center, and menu buttons in that order. (If your remote has more buttons, you can also click them and view their codes.)

You may also see lines like the following:

Protocol=NEC Data=0xFFFFFFFF R

These are repeated signals from the remote due to pressing the button longer than about 100ms, which is how long it takes to receive and decode the IR signal from a single button click. We can ignore these repeat responses for this Instructable.

Now we know how to detect remote control clicks in our main sketch. (This should work with any IR remote control, not just the Apple version!) If things are not working as expected, check the TSOP38238 wiring and also make sure you have a good battery in your remote!

Mega Code for IR Remote Digital Thermometer

MEGA RAMPS IR_bb.png

Now connect your NTC thermistor to TEMP0 as shown in the above diagram. Download the code files into a folder called MEGA_RAMPS_MENU_IR and open the MEGA_RAMPS_MENU_IR.ino file in your Arduino IDE.

Notice the following defines:

#define apple_left 0x77E190   //7856528
#define apple_right 0x77E160  //7856480
#define apple_up 0x77E150     //7856464
#define apple_down 0x77E130   //7856464
#define apple_middle 0x77E1A0 //7856544 
#define apple_menu 0x77E1C0   //7856576
#define apple_repeat 0xFFFFFF //16777215

These are the decoded values for the specified button presses that we found in Step 1. However, I have truncated the HEX values by dividing the raw values by 256. This is because I noticed that different apple remotes seem to have different values for the last two digits and they are unnecessary because we can differentiate between different button clicks using the truncated codes.

Upload the code to your MEGA. You should see the current temperature in Celsius. Click the Apple remote Menu button to display the units menu. You can scroll through the menu using the Up and Down buttons. Click the Menu (or Center) button to view the temperature in the selected units. Look through the code and read the comments for explanations.

You can easily port this code to other Arduino versions and/or other IR remote control devices.

Hooray! Now you can use to Apple IR remote for your own amazing project!