using ir remote with raspberry pi without lirc

Master Your Raspberry Pi with Infrared Remote Control (No LIRC Setup)

By Brian Martin
AD

For many makers and hobbyists, the desire to control a Raspberry Pi with a television remote control often leads directly to the LIRC (Linux Infrared Remote Control) ecosystem. While LIRC is a powerful and established solution, its configuration can be notoriously complex, involving daemon management, custom configuration files, and deciphering kernel device names. The good news is that you can bypass this complexity entirely by leveraging the raw capabilities of the GPIO pins and modern Python libraries. This guide provides a streamlined, dependency-light approach to using an IR remote with your Raspberry Pi without ever installing or configuring LIRC.

Understanding the Foundation: GPIO and IR Demodulation

The secret to skipping LIRC lies in the Raspberry Pi’s GPIO (General Purpose Input/Output) pins. Unlike older models that lacked dedicated hardware, modern Raspberry Pi boards, including the Pi 3, 4, and Zero 2 W, feature a dedicated IR decoder on the GPIO. This hardware peripheral is specifically designed to handle the 38kHz carrier frequency used by standard consumer IR remotes, taking the heavy lifting off the CPU. Instead of writing a complex software library to decode the messy IR signal, the peripheral filters and demodulates it into clean pulse-width modulation (PWM) data that the Pi can read via a simple sysfs interface. This hardware efficiency is the cornerstone of a lightweight, LIRC-free setup.

Pinout and Hardware Preparation

Before diving into software, ensure your wiring is correct. Most consumer remotes output a modulated 38kHz signal, which is incompatible with standard GPIO pins. You have two primary options:

AD
IR remote extender - Electronics-Lab
IR remote extender - Electronics-Lab
Read/emulate Remotes With Arduino and Raspberry Pi
Read/emulate Remotes With Arduino and Raspberry Pi
an electronic device with the words home automated with rasberry pi 3 projects you can do today
an electronic device with the words home automated with rasberry pi 3 projects you can do today
  • Dedicated IR Receiver: Use a purpose-built receiver module, such as the TSOP4838. These modules are inexpensive, widely available, and handle the demodulation internally, outputting a clean digital signal.
  • General Purpose Receiver: If using a raw phototransistor, you will need to build a demodulating circuit with a 38kHz filter, adding significant complexity.

Physically connect the receiver to the Raspberry Pi. Typically, the module has three pins: Vcc (5V or 3.3V), GND, and Data. The Data pin must connect to a specific GPIO pin designated for the IR receiver. For the Raspberry Pi, this is almost always GPIO18 (physical pin 12). Double-check your connections against your specific board's pinout diagram to avoid damaging the controller.

The Software Stack: RPi.GPIO and GPIO Zero

With the hardware connected, the software side becomes remarkably straightforward. We will utilize two Python libraries: RPi.GPIO for low-level pin control and gpiozero for high-level, event-driven programming. gpiozero is particularly elegant for this task as it abstracts the complexity of interrupt handling and state management. You will also need the lirc-rpi kernel module, but this is a minimal driver, not the LIRC user-space suite. Install the necessary Python packages using the standard pip command:

Learn everything about Raspberry Pi
Learn everything about Raspberry Pi
Best Raspberry Pi Projects – Pi DIY Lab
Best Raspberry Pi Projects – Pi DIY Lab
10 Raspberry PI & Arduino Projects for Gamers
10 Raspberry PI & Arduino Projects for Gamers
sudo apt update
sudo apt install python3-pip
pip3 install RPi.GPIO gpiozero

Loading the Kernel Module and Configuring GPIO

Before your Python script can communicate with the IR hardware, the appropriate kernel module must be loaded. This driver enables the dedicated IR decoder on the SoC. Add the module to the system configuration to ensure it activates on every boot:

sudo nano /boot/config.txt

Insert the following line at the bottom of the file to load the LIRC driver for the GPIO peripheral:

dtoverlay=lirc-rpi,gpio_in_pin=18

Save the file and reboot your system. After the reboot, verify that the kernel interface is active by checking for the device file:

ls -l /dev/lirc*

You should see a device such as /dev/lirc0. This confirms the kernel is ready to provide raw IR data, even though we won't be using the LIRC daemon.

Writing the Python Script: Capturing Raw Signals

Now you can write the Python script to capture the raw pulse data. The gpiozero library provides the IRReceiver class, which simplifies reading the signal protocol and timing. Create a new Python file and implement the following logic to print the duration of each pulse:

from gpiozero import IRReceiver
from signal import pause

def pulse_callback(filename, length, toggle):
    print(f"Pulse: {length} microseconds, Toggle: {toggle}")

ir = IRReceiver(18)
ir.when_pulse = pulse_callback

print("Listening for IR signals. Press Ctrl+C to exit.")
pause()

Run the script with sudo privileges, as accessing the GPIO hardware requires it:

sudo python3 ir_reader.py

Press a button on your remote. The script will output a stream of numbers representing the high and low durations of the IR signal in microseconds. This raw data is the foundation for creating your unique remote control map.

Decoding Signals and Creating a Remote Map

The output from the script is a long sequence of pulses. To make sense of it, you must identify the specific patterns that correspond to each button. A standard remote protocol like NEC or Sony SIRC organizes a button press into a header (a unique timing pattern) followed by an address and a command byte. To decode this efficiently, modify the script to log the pulses to a text file instead of printing them to the console. Analyze the file using a text editor or a spreadsheet to identify the consistent header and the distinct patterns for "Power," "Volume Up," or "0-9." Manually build a dictionary in your Python code that maps these pulse sequences to human-readable string identifiers. This process eliminates the need for irrecord and gives you direct control over the interpretation logic.

Integration and Application: Acting on the Commands

With your decoding logic in place, the final step is to integrate the IR control into your projects. Instead of printing the button name, trigger the desired action directly within the callback function. For example, you could integrate the remote with a media center by using the subprocess module to call omxplayer or mpv, or control GPIO pins to turn LEDs on or off. Because you are working with the raw data, you have the flexibility to debounce signals, implement long-press detection, or create custom macros. This method provides a direct, efficient, and highly customized remote control interface, proving that powerful automation does not always require heavy, legacy dependencies.

Control your TV using HDMI-CEC
Control your TV using HDMI-CEC
The ultimate Raspberry Pi Lakka tutorial (with pictures)
The ultimate Raspberry Pi Lakka tutorial (with pictures)
Raspberry Pi Kernel Updated to 4.19
Raspberry Pi Kernel Updated to 4.19
Raspberry Pi Tips for Beginners
Raspberry Pi Tips for Beginners
Contrôler un Raspberry Pi depuis un appareil Android
Contrôler un Raspberry Pi depuis un appareil Android
How to Install Android on Raspberry Pi in 2026 (+Play Store)
How to Install Android on Raspberry Pi in 2026 (+Play Store)
Online Hub for Robotics Projects, Tutorials,
Online Hub for Robotics Projects, Tutorials,
Installing Kodi on your Raspberry Pi
Installing Kodi on your Raspberry Pi
a flat screen tv with the words how to build an android tv box with a raspberry pi
a flat screen tv with the words how to build an android tv box with a raspberry pi
23 Operating Systems That Run on Your Raspberry Pi
23 Operating Systems That Run on Your Raspberry Pi
How to Control the GPIO on a Raspberry Pi with an IR Remote
How to Control the GPIO on a Raspberry Pi with an IR Remote
How to Setup Spotify Connect on the Raspberry Pi
How to Setup Spotify Connect on the Raspberry Pi
16 cool projects ideas for the small Raspberry Pi Zero
16 cool projects ideas for the small Raspberry Pi Zero
Setup Android on the Raspberry Pi using EmteriaOS
Setup Android on the Raspberry Pi using EmteriaOS
How to Run Netflix on the Raspberry Pi
How to Run Netflix on the Raspberry Pi
Steps to setting up a Raspberry Pi Alexa
Steps to setting up a Raspberry Pi Alexa
the raspberry pi without a monitor is shown in this manual for beginners
the raspberry pi without a monitor is shown in this manual for beginners
Portable Raspberry Pi Bluetooth Receiver/Player
Portable Raspberry Pi Bluetooth Receiver/Player
The 5 Best Raspberry Pi Smart TV Projects We've Seen
The 5 Best Raspberry Pi Smart TV Projects We've Seen
11 Fun Raspberry Pi Projects to Try This Weekend
11 Fun Raspberry Pi Projects to Try This Weekend
AD