Control Your Raspberry Pi with a Repurposed IR Remote: Shutdown & Reboot via LIRC
Introduction
Have an unused infrared remote lying around? Turn it into a convenient power control for your Raspberry Pi—no keyboard or mouse required.
Scope
This guide covers how to install and configure the LIRC client irexec to map remote button presses to Pi shutdown and reboot commands. Adding the IR receiver to the Pi is addressed in a separate tutorial.
Target Readers
Anyone who owns a Raspberry Pi equipped with an IR receiver.
Step 1: Record and map infrared codes to LIRC events
Follow the instructions in our prior guide, "Record Infrared Codes of Any Remote Control Unit for Linux Infrared Remote Control (LIRC) on Raspberry Pi", to capture the remote’s button codes.
Step 2: Install and configure the LIRC daemon
Use the steps outlined in our earlier post to install LIRC and set it up to listen to the receiver.
Step 3: Create an irexec configuration file
Create or edit the /etc/lirc/lircrc file to tell irexec what action to perform when a LIRC event occurs.
sudo vi /etc/lirc/lircrc
Example configuration (replace remote_name and codes with the values you recorded):
begin remote
name = remote_name
bits = 12
flags = RC5
eps = 30
aeps = 200
[KEY_RESTART]
codes = 0x1FEA45, 0x1FECAD
begin
program = /usr/bin/irexec
arguments = -e "sudo reboot"
end
[KEY_POWER]
codes = 0x1FEA1C, 0x1FEA1D
begin
program = /usr/bin/irexec
arguments = -e "sudo poweroff"
end
end remote
Step 4: Test the setup
Reboot the Raspberry Pi with sudo reboot, then point the remote at the receiver and press the button mapped to KEY_RESTART—the Pi should reboot. Press the button mapped to KEY_POWER—the Pi should power off. If nothing happens, consult the LIRC logs or check that the receiver is correctly connected.
For more details, see our related tutorial: Reuse Unwanted Infrared Remote Control to Shutdown and Reboot Raspberry Pi.
Manufacturing process
- Seamless MQTT Integration: NodeMCU DHT22 Sensors with Raspberry Pi 3 B+ as Broker
- Build a Remote Temperature Sensor with Raspberry Pi and Python – Step‑by‑Step Guide
- Remote Weather Monitoring with Raspberry Pi 3 and PubNub
- Build a Professional Raspberry Pi Universal Remote with LIRC
- Build a Multi‑Sensor Temperature & Light Monitoring System with Raspberry Pi & DS18B20
- Mastering Raspberry Pi Sensor & Actuator Control: Accelerometer, Servo, and Data Streaming
- Capturing IR Remote Commands on Raspberry Pi without LIRC: A Python UART Approach
- Build a Universal Android Remote with Arduino, 1Sheeld & IR Control
- Build a Raspberry Pi 3 & Arduino Laptop: Step‑by‑Step Guide
- Build a 4WD IR Remote‑Controlled Arduino Robot Car Kit