< async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"">

Thursday, January 9, 2014

Raspberry pi ir blaster- Control your Infrared Devices from the Internet

ADVERTISEMENT

Raspberry pi is a small device which can do a lot more with its GPIO pins and the internet connectivity. The low power consumption compared to a full blown desktop pc makes it as a good choice in many remote controlled home automation projects. As in aprevious post, the high definition media capability of pi offers a good opppurtunity to use it as a media player while doing the other stuffs.

Often it is convenient to control your devices with an infrared remote control, for example an HVAC system or an air conditioner to be turned on from a mobile phone while you are heading towards your home. It is also good to keep the room temperature optimal in winter while you are planning to return from your office.

My previous post on remote temperature monitoring can go to gether with this. raspberry pi can be used as an excellent internet controlled ir blaster or ir extender. An other scenerio is when you use an old system without hdmi cec and want to turn off your tv or the amplifier from the raspberry pi, an infrared emitter helps. It is also possible to set up a cronjob (a kind of timer) to send an infrared signal at a specified time to turn a device on or off.

There are two ways to do this. First one is a bit expensive, easy and less fun. There are ready made modules which can be plugged in to the usb port of the pi/ addon boards to GPIO and the work is half done. But here am going to do it from scratch. The basics of all remote control is an infrared led which switches on and off in a specific sequence (at the same time the led has a high frequency flashing at 38KHZ so that the tv set / devices know that the ir is coming from a remote and not any noice)

So we need

  • IR LED (TSAL5300), All leds works, Choose one with 940nm peak wavelength.
  • NPN transistor (e.g. 2N2222 or BC548) 
  • Resistor (10Kilo ohm and one 330 ohm) 


Software: I used raspbmc which has lirc in its latest kernels (See more at http://aron.ws/projects/lirc_rpi/)

The gpio ir driver has 5 parameters: debug, gpio_out_pin, gpio_in_pin, sense, softcarrier.

The default gpio input pin (PIN12 - GPIO18) is used when no input pin is specified as a parameter. The default gpio output pin for transmission is PIN11 - GPIO17.

Be careful with gpio pins as wrong connection can permanently damage your pi. Have a look at here to understand how the pins are placed. !!WARNING GPIO PINS ARE NOT 5V TOLERANT!!
Settings:

1) Enable the kernel modules for gpio infrared control

 in /etc/modules

lirc_dev
lirc_rpi gpio_in_pin=23 gpio_out_pin=22 

In /etc/lirc/hardware.conf

########################################################
# /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=""
########################################################

More about setting up IR receiver with lirc was discussed before. Same tactics are used to create and record the infrared signals from HVAC or other devices. In short create the lirc config files and map the buttons. The shortest explanation is irrecord command and check the previous post for more details.

Hardware Connections





once you make a config file using irrecord and saved/added it to /etc/lirc/lircd.conf, These commands can be send to the IR led by the following routines

# List all of the commands that LIRC knows for 'myremote'
irsend LIST myremote ""

# Send the KEY_POWER command once
irsend SEND_ONCE myremote KEY_POWER

and check for the device getting powered on /off. More on linking to the web interface in next post

12 comments:

  1. Very nice and informative. I had the same thinking. I am now looking for an end to end solution with a web server and android application.

    ReplyDelete
  2. Hi,
    You might want to check the led icon in the hardware connections drawing. I think that the arrow inside the led simbol shoul point from +3.3 to 0V direction.

    ReplyDelete
    Replies
    1. Thanks for pointing, In the figure, the led is connected in the wrong direction. Anode should go to the positive terminal via 330 ohm resister.

      Delete
  3. Hi,
    In hardware connection figure, what is confused about gpio_in_pin = 23 ?

    ReplyDelete
    Replies
    1. In the figure, the led is connected in the wrong direction. Anode should go to the positive terminal via 330 ohm resister.

      Delete
    2. also use a mobile phone camera to see if the infrared led is lighting up (ir is visible through cell phone cameras!)

      Delete
  4. The gpio_in_pin should be the gpio_out_pin in your diagram

    ReplyDelete
  5. Hi,
    Can someone help to create web example for sending IRSEND. I have try irsend did not working when put on html.
    But sending IRSEND works via terminal. Please help !

    ReplyDelete
  6. Hi,
    Thanks for this tutorial, though, I'd like to point the fact that it won't work on all Raspbian versions because of a timing bug in the kernel.
    I lost a lot of time before finding this post : https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=62063
    Raspbian wheezy with 3.18.7 kernel : fail
    OpenElec Kodi 14 with 3.17.16 kernel : OK

    ReplyDelete
  7. irsend LIST myremote ""
    From where does name " my remote" came???
    Please help me
    I am stuck at this step :( ;(

    ReplyDelete
    Replies
    1. Type just irsend LIST to show the cinfigured devices (if any). 'Myremote' is the name used to define a remote. A bit more can be read here : http://www.lirc.org/html/lircd.conf.html

      For the LIST DIRECTIVE, REMOTE and/or CODE can be empty:

      LIST "" "" - list all configured remote names
      LIST REMOTE "" - list all codes of REMOTE
      LIST REMOTE CODE - list only CODE of REMOTE

      Fore more info, see http://www.lirc.org/html/irsend.html

      Delete
  8. I keep getting this error: hardware does not support sending
    Error running command: Input/output error
    I have spent hours trying to find out what is wrong, could you please help me?

    ReplyDelete