My Account

Wish List (0)

Saved Carts

Compare

Raspberry Pis, Remotes & IR Receivers!

September 23, 2014

Introduction to IR Sensors

Infrared (IR) light is invisible electromagnetic radiation. Everything absorbs and emits IR, and it's utilised in a plethora of applications. You may have heard of IR used in night vision equipment. This is becuase, in low visible-light conditions, everything still emits IR radiation. The night vision equipment has IR sensors which detect and output this information!

IR sensors consist of a photocell & chip tuned to look out for specific wavelenghts of invisible infrared light. This is why IR is used for remote control detection, such as your TV. You "could" use visible light, however you would be essentially shining a torch at you TV, which isn't ideal.

So, in order to use IR for remote sensing, you need an IR LED (in the remote to output the IR signal) coupled with an IR sensor (inside the TV) which detects the IR pulses and follows the direction that these pulses are coded to e.g. turn off, change channel etc.

In this tutorial we're going to test an IR sensor and then hook it up to our Raspberry Pi and programme a remote to interact with it!

Testing the IR Sensor

You will need:

  • IR Sensor
  • LED (visible light)
  • 200 – 1000 ohm resistor
  • 4x AA batteries

IR Sensors contain a semiconductor/chip inside them, so they need to be powered in some way (always check the datasheet for your specific receiver) before they can be tested. In this case, the sensor can be powered by 5V

Connect up the sensor like so:

  • Pin 1 is the output so we wire this to a visible LED and resistor
  • Pin 2 is ground
  • Pin 3 is VCC, connect to 5V

The positive (longer) head of the Red LED connects to the +5V pin and the negative (shorter lead) connects through a 200 to 1000 ohm resistor to the first pin on the IR sensor.

Now grab any remote control (TV, BluRay etc…) and point it at the detector. While pressing some buttons, you should see the LED blink a few times!

That's it - your receiver is working. . . . !

Attaching IR Sensor to the Raspberry Pi

Now that we're happy our reciever is working, we're going to hook it up to our Raspberry Pi, and configure it with a remote control for use with RaspBMC Media Center!

  • Pin 1 is DATA, goes to RPi pin 12 (GPIO 18);
  • Pin 2 is GND, goes to RPI pin 6 (GROUND)
  • Pin 3 is POWER, goes RPi pin 1 (5V)

If you have different sensor you may have different pinout. Check the datasheet for you sensor.

Testing the IR Sensor on the Rasberry Pi

To check if the IR Sensor is working on the Pi, simply run the following commands one after each other:

sudo modprobe lirc_rpi

then

sudo kill $(pidof lircd)
(if you get a usage list come up, don't worry, it just means that lircd wasn't running to begin with)

then

mode2 -d /dev/lirc0

Now, when you press buttons on your remote, assuming your receiver is connected correctly, you should see something resembling this appear on the screen with each press:

If nothing happens when you press buttons on your remote, please check the following:

1. Go back and test the IR Sensor using the LED method mentioned above

2. Make sure the IR Sensor has been connected to the Pi correctly

3. Make sure the remote is working (try a different remote if you have one, change the batteries etc...)

Setting up the remote control buttons

First thing to do, is to check that your remote doesnt already have a preset within raspbmc.

Login to raspbmc, go to Programs -> Raspbmc settings

Scroll across to the IR Remote Tab

Select the option enable GPIO TSOP IR Receiver

Below that, you should be able to select a bunch of different remotes. If yours is listed, then boom! Select it, then select OK at the bottom. Raspbmc should prompt you to restart.

After Raspbmc has restarted, you should be good to go.

If however, your remote isnt listed then you will need to record your remote.

Recording your remote

Before, going through this process, have a look here: http://lirc.sourceforge.net/remotes/ and see if your remote has already had a lircd.conf created for it. If it has, then copy the lircd.conf file to your pi's home directory: /home/pi/lircd.conf and skip to step 3.

(If you find the lircd.conf you have downloaded has incorect KEY mappings, then you can record your own)

1. First thing to do is to get the list of KEY commands that are accepted.

To do this, run the following commands (rember to copy the list that you get and save it somewhere, as you'll need them later)

sudo kill $(pidof lircd)

irrecord --list-namespace | grep KEY
(if you get a usage list come up, don't worry, it just means that lircd wasn't running to begin with)

Once you have saved this list you are ready to record your remote.

2. To record your remote, run the following commands

sudo kill $(pidof lircd)
(if you get a usage list come up, don't worry, it just means that lircd wasn't running to begin with)

irrecord -d /dev/lirc0 ~/lircd.conf

Follow the instructions given by irrecord exactly.

When you get to the bit where you are asked "Please enter the name for the next button (press <ENTER> to finish recording)"

This is where you start to configure each button.

So pick a button on the remote you want to configure, for example on our IR Remote Control, the first button is the Volume Down button.

So we need to find the KEY command that we want to associate with the Volume Down button. In this case, it makes sense to use the KEY_VOLUMEDOWN key. You can however configure any KEY command to any button.

Once you have found the KEY command for the button you want configure, simply enter that KEY and hit ENTER, you should now be prompted to press and hold the button on the remote you want to assign to this KEY.

Now do that for every button you want to use on the remote.

After you have configured the last button, simply hit ENTER to stop recording.

You'll then be asked to repeatedly press an arbitary button as fast as you can (make sure you press the same button each time, and that you don't hold the button down).

The recording has now been completed, and hopefully our lircd.conf has been created (this can be found here: /home/pi/lircd.conf)

3. Login to Raspbmc, go to Programs -> Raspbmc settings

Scroll across to the IR Remote Tab

Now from the list of remotes, you'll want to select custom (lircd.conf on pi's home folder)

Then select OK and you should be prompted to restart.

After you restart you should have a working remote control!

Last update: September 11, 2015

11 Comments(3 Replies)

Leave a Comment

Leave a Reply

* Name:
* Comment:
* E-mail: (Not Published)
Website: (Site url with http://)
Verification code: