Each button of an IR remote control (as shown below) has a string of specific encoding. When a button is pressed, the IR transmitter in the remote control will send out the corresponding IR encoding signals. On the other side, when the IR receiver receives certain encoding signals, it will decode them to identify which button is pressed.

Components

-1 * Raspberry Pi

- 1 * Breadboard

- 4 * Jumper wires (Male to Male, 2 red and 2 black)

- 1 * Network cable (or USB wireless network adapter)

- 1 * IR Receiver

- 1 * RGB LED module

- 1 * IR Remote Control

- 1 * 3-Pin anti-reverse cable

- 1 * 4-Pin anti-reverse cable

Experimental Principle

In this experiment, we use the lirc library to read infrared signals returned by buttons of the remote control and translate them to button values. Then use liblircclient-dev (C) and pylirc (Python) to simplify the process for reading values from the remote control. In this experiment use 9 buttons on the top of the remote to control the color of the RGB LED module. Each row represents one color, and each column represents the brightness.

Run the command to stop lircd and start outputting raw data from the IR receiver:

irw

When you press a button on the remote, you can see the button name printed on the screen.

pi@raspberrypi:~ $ irw

0000000000000001 00 KEY_CHANNELDOWN /home/pi/lircd.conf

0000000000000002 00 KEY_CHANNEL /home/pi/lircd.conf

0000000000000003 00 KEY_CHANNELUP /home/pi/lircd.conf

0000000000000004 00 KEY_PREVIOUS /home/pi/lircd.conf

0000000000000005 00 KEY_NEXT /home/pi/lircd.conf

0000000000000006 00 KEY_PLAYPAUSE /home/pi/lircd.conf

0000000000000007 00 KEY_VOLUMEDOWN /home/pi/lircd.conf

0000000000000008 00 KEY_VOLUMEUP /home/pi/lircd.conf

0000000000000009 00 KEY_EQUAL /home/pi/lircd.conf

000000000000000a 00 KEY_NUMERIC_0 /home/pi/lircd.conf

0000000000000014 00 BTN_0 /home/pi/lircd.conf

0000000000000015 00 BTN_1 /home/pi/lircd.conf

000000000000000b 00 KEY_NUMERIC_1 /home/pi/lircd.conf

000000000000000c 00 KEY_NUMERIC_2 /home/pi/lircd.conf

000000000000000d 00 KEY_NUMERIC_3 /home/pi/lircd.conf

000000000000000e 00 KEY_NUMERIC_4 /home/pi/lircd.conf

000000000000000f 00 KEY_NUMERIC_5 /home/pi/lircd.conf

0000000000000010 00 KEY_NUMERIC_6 /home/pi/lircd.conf

0000000000000011 00 KEY_NUMERIC_7 /home/pi/lircd.conf

0000000000000012 00 KEY_NUMERIC_8 /home/pi/lircd.conf

0000000000000013 00 KEY_NUMERIC_9 /home/pi/lircd.conf

If it does not appear, somewhere may be incorrectly configured. Check again that you’ve connected everything and haven’t crossed any wires.

For C language users:

Step 5: Download LIRC client library:

sudo apt-get install liblircclient-dev

Step 6: Change directory

cd /home/pi/SunFounder_SensorKit_for_RPi2/C/23_ircontrol/

Step7: Create a lirc directory under /etc/lirc/:

sudo mkdir /etc/lirc/lirc/

Copy the lircrc file to /etc/lirc/lirc/:

sudo cp lircrc /etc/lirc/lirc/

Step 8: Compile

gcc ircontrol.c -lwiringPi -llirc_client

Step 9: Run

sudo ./a.out

For Python users:

Step 5: Download pylirc:

sudo apt-get install python-pylirc

Step 6: Change directory:

cd /home/pi/SunFounder_SensorKit_for_RPi2/Python/

Step 7: Run

sudo python 23_ircontrol.py

Each of the top three rows of buttons on the remote control represents a kind of color, i.e. red, green, and blue, top to bottom. Each column represents off, light, and dark. For example, press the second button (light) on the first row (red), and the LED will flash light red. You can use the remote to generate 27 colors in total (including all the LEDs off). Try to change the color of the RGB LED with the 9 buttons!