# Using an IR Remote with a Raspberry Pi Media Center

## Overview

In this tutorial, you will learn how to use an Infrared remote with a Raspberry Pi configured as a media center.

The IR receiver is attached to the GPIO connector on the Raspberry Pi.

![](https://cdn-learn.adafruit.com/assets/assets/000/005/907/medium800/raspberry_pi_overview.jpg?1396829538)

Before tackling this project, you need to follow [this tutorial](http://learn.adafruit.com/raspberry-pi-as-a-media-center "Link: http://learn.adafruit.com/raspberry-pi-as-a-media-center") to set up your Raspberry Pi as a media center.

# Using an IR Remote with a Raspberry Pi Media Center

## Parts

To build this project, you will need everything from the [Media Center setup tutorial](http://learn.adafruit.com/raspberry-pi-as-a-media-center) and the following items.

# Using an IR Remote with a Raspberry Pi Media Center

## Hardware

The IR sensor has just three pins, that will connect with three pins on the GPIO connector. To do the connecting, we can use female to female jumper leads. These make a good reliable connection as the IR sensor has unusually thick leads for an IC.

![](https://cdn-learn.adafruit.com/assets/assets/000/005/908/medium800/raspberry_pi_overview.jpg?1396829563)

Make the connections as shown below. Note that you do not have to use the same colored jumper wires. But selecting adjacent wires that are still in a 'ribbon' will help keep things neat.

![](https://cdn-learn.adafruit.com/assets/assets/000/005/909/medium800/raspberry_pi_wiring.png?1396829644)

Note that the IR sensor chip needs to be operated at 3.3V not 5V when used with the Raspberry Pi.

# Using an IR Remote with a Raspberry Pi Media Center

## LIRC

The interface between the hardware and the Raspberry Pi media centre is managed by a piece of software called LIRC (Linux Infrared Remote Control). This is pre-installed on most recent Raspberry Pi distributions and is included in the Rasbmc distribution, so there is nothing to install, however, there is some setting up to do.

To make sure that the IR hardware is correct, we can connect to the Raspberry Pi running Rasbmc using SSH, which is automatically enabled on this distribution.

[If you have not connected to a Raspberry Pi using SSH before, please see this tutorial.](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh/ "Link: http://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh/")

You can find the IP address of the Raspberry Pi using the XBMC System Info page.

![](https://cdn-learn.adafruit.com/assets/assets/000/005/910/medium800/raspberry_pi_xmbc_ip_address.jpg?1396829659)

To be able to test the IR receiver without XBMC, you need to make sure that the IR remote feature is turned off, or you will not be able to use LIRC from the SSH. So run the Rasbmc Settings program and make sure that the option **Enable GPIO TSOP IR Receiver** is disabled.

![](https://cdn-learn.adafruit.com/assets/assets/000/005/911/medium800/raspberry_pi_TSOP_IR_disabled.jpg?1396829675)

If you needed to change this you will need to reboot.

Now connect to the Raspberry Pi using SSH and issue the commands shown below:

![](https://cdn-learn.adafruit.com/assets/assets/000/005/912/medium800/raspberry_pi_mode2_on_xmbc.png?1396829702)

Now hold the remote in front of the receiver and you should see a series of 'pulse' / 'space' messages appear each time you press a button.

Congratualtions! The IR receiver is working.

# Using an IR Remote with a Raspberry Pi Media Center

## Configure and Test

Now that we know that the hardware is okay, we need to give LIRC a config file to tell it about the keys on the remote that we are using.

From the SSH session, issue the command:

```auto
nano lircd.conf
```

... and then paste the following text into it, before saving the file by clicking CTRL-x then Y.

```auto
# Please make this file available to others
# by sending it to &lt;lirc@bartelmus.de&gt;
#
# this config file was automatically generated
# using lirc-0.9.0-pre1(default) on Thu Mar 14 14:21:25 2013
#
# contributed by 
#
# brand:                       /home/pi/lircd.conf
# model no. of remote control: 
# devices being controlled by this remote:
#

begin remote

  name  /home/pi/lircd.conf
  bits           16
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header       8945  4421
  one           594  1634
  zero          594   519
  ptrail        598
  repeat       8949  2187
  pre_data_bits   16
  pre_data       0xFD
  gap          106959
  toggle_bit_mask 0x0

      begin codes
          KEY_VOLUMEDOWN           0x00FF
          KEY_PLAYPAUSE            0x807F
          KEY_VOLUMEUP             0x40BF
          KEY_SETUP                0x20DF
          KEY_UP                   0xA05F
          KEY_STOP                 0x609F
          KEY_LEFT                 0x10EF
          KEY_ENTER                0x906F
          KEY_RIGHT                0x50AF
          KEY_KP0                  0x30CF
          KEY_DOWN                 0xB04F
          KEY_BACK                 0x708F
          KEY_KP1                  0x08F7
          KEY_KP2                  0x8877
          KEY_KP3                  0x48B7
          KEY_KP4                  0x28D7
          KEY_KP5                  0xA857
          KEY_KP6                  0x6897
          KEY_KP7                  0x18E7
          KEY_KP8                  0x9867
          KEY_KP9                  0x58A7
      end codes

end remote
```

This file should be saved in the home directory for the user pi.

Now, return to the Rasbmc Settings program and enable the option **Enable GPIO TSOP IR Receiver**. At the same time, change the GPIO Remote Profile as shown below:

![](https://cdn-learn.adafruit.com/assets/assets/000/005/913/medium800/raspberry_pi_xmbc_ir_on.jpg?1396829717)

Restart XBMC and when it has rebooted, you should see a small popup message in the bottom right corner like the one below.

![](https://cdn-learn.adafruit.com/assets/assets/000/005/914/medium800/raspberry_pi_xmbc_detects_lirc.jpg?1396829736)

You should now find that your IR remote control will work and that you no longer need the keyboard and mouse to control XBMC.

# Using an IR Remote with a Raspberry Pi Media Center

## Using Other Remotes

I generated the config file for this remote using a utility that is part of LIRC called 'irrecord'.

If you have a different remote, then you can generate a config file for it using this tool.

The process is as follows:

- Turn the remote off on XBMC using Rasbmc as we did before using 'mode2'.

- Rename the existing lircd.conf out of the way

- Type the command 'irrecord&nbsp;--list-namespace'. This will tell you the allowed key names that you can use when prompted.

- Type the command 'irrecord -d /dev/lirc0 ~/lircd.conf'

- Follow the instructions to the letter. It all seems a bit odd, but the program has to work out the timings and encodings used by the remote.

![](https://cdn-learn.adafruit.com/assets/assets/000/005/915/medium800/raspberry_pi_recording_keys.png?1396829772)


## Featured Products

### IR (Infrared) Receiver Sensor

[IR (Infrared) Receiver Sensor](https://www.adafruit.com/product/157)
IR sensor tuned to 38KHz, perfect for receiving commands from a TV remote control. Runs at 3V to 5V so it's great for any microcontroller.  
  
To use, connect pin 3 (all the way to the right) to 5V power, pin 2 (middle) to ground and listen on pin 1. It doesn't do any decoding...

In Stock
[Buy Now](https://www.adafruit.com/product/157)
[Related Guides to the Product](https://learn.adafruit.com/products/157/guides)
### Mini Remote Control

[Mini Remote Control](https://www.adafruit.com/product/389)
This little remote control would be handy for controlling a robot or other project from across the room. It has 21 buttons and a layout we thought was handy: directional buttons and number entry buttons. The remote uses the NEC encoding type and sends data codes 0 thru 26 (it skips #3, #7,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/389)
[Related Guides to the Product](https://learn.adafruit.com/products/389/guides)
### Premium Female/Female Jumper Wires - 40 x 3" (75mm)

[Premium Female/Female Jumper Wires - 40 x 3" (75mm)](https://www.adafruit.com/product/794)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 3" (75mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" female header contacts on either end and fit cleanly next to each...

In Stock
[Buy Now](https://www.adafruit.com/product/794)
[Related Guides to the Product](https://learn.adafruit.com/products/794/guides)
### Programming the Raspberry Pi: Getting Started with Python

[Programming the Raspberry Pi: Getting Started with Python](https://www.adafruit.com/product/1089)
 **Program your own Raspberry Pi projects!**

An updated guide to programming your own Raspberry Pi projects. Learn to create inventive programs and fun games on your powerful Raspberry Pi--with no programming experience required. **This practical book has been revised...**

In Stock
[Buy Now](https://www.adafruit.com/product/1089)
[Related Guides to the Product](https://learn.adafruit.com/products/1089/guides)

## Related Guides

- [Use Apple HomeKit Devices with itsaSNAP and Adafruit IO](https://learn.adafruit.com/use-apple-homekit-devices-with-itsasnap.md)
- [LSM303 Accelerometer + Compass Breakout](https://learn.adafruit.com/lsm303-accelerometer-slash-compass-breakout.md)
- [Adafruit I2S MEMS Microphone Breakout](https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout.md)
- [Set up Home Assistant with a Raspberry Pi](https://learn.adafruit.com/set-up-home-assistant-with-a-raspberry-pi.md)
- [Controlling Motors using the Raspberry Pi and RasPiRobot Board V2](https://learn.adafruit.com/controlling-motors-using-the-raspberry-pi-and-raspirobot-board-v2.md)
- [RePaper eInk Development Board for ARM + GNU/Linux](https://learn.adafruit.com/repaper-eink-development-board-arm-linux-raspberry-pi-beagle-bone-black.md)
- [Adafruit BNO055 Absolute Orientation Sensor](https://learn.adafruit.com/adafruit-bno055-absolute-orientation-sensor.md)
- [MicroBlocks Circuit Playground Express Ornament](https://learn.adafruit.com/microblocks-circuitplayground-express-ornament.md)
- [Cupcade: the Raspberry Pi Micro Arcade Cabinet](https://learn.adafruit.com/cupcade-raspberry-pi-micro-mini-arcade-game-cabinet.md)
- [Low Level Magstripe Reader](https://learn.adafruit.com/low-level-magstripe-reader.md)
- [Motion-Activated Solder Fume Extractor With Lamp](https://learn.adafruit.com/motion-activated-solder-fume-extractor-with-lamp.md)
- [Adafruit's Raspberry Pi Lesson 13. Power Control](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-13-power-control.md)
- [DotStar Pi Painter](https://learn.adafruit.com/dotstar-pi-painter.md)
- [Adafruit Ultimate GPS HAT for Raspberry Pi](https://learn.adafruit.com/adafruit-ultimate-gps-hat-for-raspberry-pi.md)
- [No-Code Offline Data Logger with WipperSnapper](https://learn.adafruit.com/no-code-offline-data-logging-with-wippersnapper.md)
