Recently I have been working on a project that would allow anyone to turn a Raspberry Pi into a universal remote. To do this I have been using LIRC (LINUX Infrared Remote Control), LIRC is a package that allows you to decode and send infra-red signals to many (but not all) commonly used remote controls. This project provides a starting point for experimenting with an IR LED and the LIRC package on the Raspberry Pi and extending the basic setup with new features and functionality, such as adding an IR receiver to generate a LIRC remote profile using an existing remote control.
Step 1: Materials- 940nm IR LED 40deg - 40 degree viewing angle. Bright and tuned to 940nm wavelength.
- 38khz IR Receiver - Receives IR signals at remote control frequencies
- PN2222 Transistor - Transistor to help drive IR LED
- 10k Ohm resistor - Resistor that goes between RPI GPIO and the PN2222 transistor
Although you can connect an IR LED directly to GPIO pins on the Raspberry Pi, the LED's output signal will be too weak, and the IR transmitter will have a very limited range. A simple transistor circuit solves the problem by amplifying the current output from a pin and thus increasing the IR LED's signal strength. First place your IR LED on the breadboard and wire the long leg(Anode) to 3.3 volts(pin 1) and the long leg(Cathode) to the Emitter of your transistor. Next, run a wire from ground(pin 6) to the collector of your transistor and then use a 10K resistor to connect the base of your transistor to pin 22.
First place your IR LED on the breadboard and wire the long leg (Anode) to 3.3 volts (pin 1) and the long leg (Cathode) to the Emitter of your transistor. Next, run a wire from ground (pin 6) to the collector of your transistor and then use a 10K resistor to connect the base of your transistor to pin 22. Next, place your IR receiver on the breadboard. Run 3.3 Volts to its right leg and connect its center leg to ground. Finally connect pin 23 to the left leg of your IR receiver.
Step 3: LIRC Install and SetupFirst, we’ll need to install and configure LIRC to run on the RaspberryPi:
sudo apt-get install lirc
Add to your /etc/modules
file by entering the command below:
sudo cat >> /etc/modules <<EOF
lirc_dev
lirc_rpi gpio_in_pin=23 gpio_out_pin=22
EOF
Change your /etc/lirc/hardware.conf
file by entering the command below:
sudo cat > /etc/lirc/hardware.conf <<EOF
########################################################
# /etc/lirc/hardware.conf
#
# Arguments which will be used when launching lircd
LIRCD_ARGS="--uinput"
# Don't start lircmd even if there seems to be a good config file
# START_LIRCMD=false
# Don't start irexec, even if a good config file seems to exist.
# START_IREXEC=false
# Try to load appropriate kernel modules
LOAD_MODULES=true
# Run "lircd --driver=help" for a list of supported drivers.
DRIVER="default"
# usually /dev/lirc0 is the correct setting for systems using udev
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"
# Default configuration files for your hardware if any
LIRCD_CONF=""
LIRCMD_CONF=""
########################################################
EOF
Edit your /boot/config.txt
by entering the command below:
cat >> /boot/config.txt <<EOF
dtoverlay=lirc-rpi,gpio_in_pin=23,gpio_out_pin=22
EOF
Now restart lircd
so it picks up these changes:
sudo /etc/init.d/lirc stop
sudo /etc/init.d/lirc start
Step 4: Testing the IR ReceiverTesting the IR receiver is relatively straightforward. Run these two commands to stop lircd
and start outputting raw data from the IR receiver:
sudo /etc/init.d/lirc stop
mode2 -d /dev/lirc0
Point a remote control at your IR receiver and press some buttons. You should see something like this:
space 16300
pulse 95
space 28794
pulse 80
space 19395
pulse 83
space 402351
pulse 135
space 7085
pulse 85
space 2903
If you don’t, something is probably incorrectly configured. Triple check that you’ve connected everything properly and haven’t crossed any wires. I highly recommend referring to the schematics I linked to above. There is also some trouble shooting advice in the RaspberryPi Forum thread I linked to above. Finally - you may want to do this in a dark room. I found that my desk lamp and overhead light would cause the IR receiver to think it was receiving valid signals.
Step 5: Testing the IR LEDYou’re going to need to either find an existing LIRC config file for your remote control or use your IR receiver to generate a new LIRC config file(find existing remote profiles here). In my case, I created a new LIRC config file. To do this, read the documentation on the irrecord application that comes with LIRC.
When using irrecord it will ask you to name the buttons you’re programming as you program them. Be sure to run irrecord --list-namespace
to see the valid names before you begin.
Here were the commands that I ran to generate a remote configuration file:
# Stop lirc to free up /dev/lirc0
sudo /etc/init.d/lirc stop
# Create a new remote control configuration file (using /dev/lirc0) and save the output to ~/lircd.conf
irrecord -d /dev/lirc0 ~/lircd.conf
# Make a backup of the original lircd.conf file
sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd_original.conf
# Copy over your new configuration file
sudo cp ~/lircd.conf /etc/lirc/lircd.conf
# Start up lirc again
sudo /etc/init.d/lirc start
Once you’ve completed a remote configuration file and saved/added it to /etc/lirc/lircd.conf
you can try testing the IR LED. We’ll be using the irsend application that comes with LIRC to facilitate sending commands. You’ll definitely want to check out the documentation to learn more about the options irsend
has.
Here are the commands I ran to test my IR LED (using the “Roku” remote configuration file I created):
# List all of the commands that LIRC knows for 'Roku'
irsend LIST Roku ""
# Send the KEY_POWER command once
irsend SEND_ONCE Roku KEY_POWER
# Send the KEY_VOLUMEDOWN command once
irsend SEND_ONCE Roku KEY_VOLUMEDOWN
I tested that this was working by pointing the IR led at my Roku receiver and testing whether I could turn it on and press enter.
Step 6: The EndThank you for reading my tutorial, if you are interested in making this project yourself but don't have the right supplies you can purchase the LabVIEW computing kit for the Raspberry Pi 2. This kit includes a copy of LabVIEW 2014 home edition and everything you will need to run LINX 3.0 and start making projects. Please comment with any questions or comments you may have.
Comments