🚀 Read and emulate remotes with Raspberry Pi and LiRC
In the last few months i was thinking about how could i control a few things in my home. The solution was obvious at first: let’s get a few relays (or dimmers), cables and start soldering. But then where to hide the cables and where to put the relays?! Most of the rooms have wallpaper and the housing of the light switches is small and already full with the cables and stuff. So this kept me thinking and then came to this idea. Nowadays many things come with remote controllers, IR or 433mhz. Why not begin the house automation with these devices?! It’s an easy and relaxing task, not much of soldering skills is needed! I was using the following parts:
- TSOP4838 IR Sensor
- 5mm IR LED 940nm
- 2PN2222 NPN Transistor
- 4,7K ohm resistor
Part 1: Reading the remotes with LiRC
The receiver should connected like on the image above and then follow the steps.
[code language=”bash”]sudo apt-get install lirc[/code]
Paste the following line in /etc/modules:
lirc_rpi gpio_in_pin=18 gpio_out_pin=17[/code]
Uncomment or insert this line in /boot/config.txt:
Now edit the /etc/lirc/hardware.conf according to this:
After reboot check that the receiver is working properly,
by stopping LiRC:
[code language=”bash”] sudo /etc/init.d/lirc stop [/code]
then execute mode2:
[code language=”bash”] mode2 -d /dev/lirc0 [/code]
Time to point a remote to the receiver and test some buttons.
If output is flooding the screen then it’s most likely working good.
Start recording the remote(s):
[code language=”bash”]irrecord -d /dev/lirc0 remote_name[/code]
for the list of available keys:
[code language=”bash”] irrecord –list-namespace [/code]
That’s it, now can copy the remote_name.conf to the /etc/lirc/lircd.conf:
[code language=”bash”]sudo cp remote_name.conf /etc/lirc/lircd.conf[/code]
then start LiRCd:
[code language=”bash”] sudo /etc/init.d/lirc start [/code]
To try the recorded remote just run:
[code language=”bash”] irw [/code]
It should output the key name when you press something on the remote.
Part 2: Emulating remotes with LiRC
Finally i ended up using 2 leds facing in 45 degree and like this it's covers the whole room.
To send a remote's signal:
[code language=”bash”] irsend SEND_ONCE remote_name KEY_NAME [/code]
In Python is the best to call this command:
[code language=”python”] os.system("irsend SEND_ONCE remote_name KEY_NAME") [/code]
With this simple solution i can now remotely control the led strips, the fireplace which serves as a electronic heater, the vacuum cleaner robot and the tv.