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
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.
ReplyDeleteHi,
ReplyDeleteYou 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.
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.
DeleteHi,
ReplyDeleteIn hardware connection figure, what is confused about gpio_in_pin = 23 ?
In the figure, the led is connected in the wrong direction. Anode should go to the positive terminal via 330 ohm resister.
Deletealso use a mobile phone camera to see if the infrared led is lighting up (ir is visible through cell phone cameras!)
DeleteThe gpio_in_pin should be the gpio_out_pin in your diagram
ReplyDeleteHi,
ReplyDeleteCan 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 !
Hi,
ReplyDeleteThanks 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
irsend LIST myremote ""
ReplyDeleteFrom where does name " my remote" came???
Please help me
I am stuck at this step :( ;(
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
DeleteFor 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
I keep getting this error: hardware does not support sending
ReplyDeleteError running command: Input/output error
I have spent hours trying to find out what is wrong, could you please help me?