Projects / Pico infrared remote code reader

Pico infrared remote code reader

Beginner2.3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. PICOVS1838B

    Wire the receiver

    VCC to 3V3(OUT), GND to GND, OUT to GP15.

  2. PICO13.8 mASSD1306

    Wire the OLED

    VCC to 3V3(OUT), GND to GND, SDA to GP0, SCL to GP1.

  3. PICO13.8 mASSD1306

    Install the ssd1306 module

    Using Thonny packages.

  4. PICO

    Run the program

    The display asks you to point a remote.

  5. PICO

    Press a key on the remote

    The address and command appear.

  6. PICO

    Hold a key

    A repeat count appears.

  7. PICO

    Make a table

    Write down the command for each key.

In short

How do you build a pico infrared remote code reader?

A Pico reads a VS1838B infrared receiver, decodes the pulse timing of a remote's NEC code and shows the address and command on an OLED. You need Raspberry Pi Pico H, IR receiver VS1838B, SSD1306 OLED Display and Breadboard 830 Tie Points. It takes 7 steps and about 140 minutes.

Level
Beginner
Time
About 140 min
Parts
4

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
IR receiver VCCPico 3V3(OUT) pin 36Power at 3.3 V (check the pin order on your module)
IR receiver GNDPico GND pin 38Common ground
IR receiver OUTPico GP15 pin 20Signal, idles high
OLED VCCPico 3V3(OUT) pin 36Power at 3.3 V
OLED GNDPico GND pin 3Common ground
OLED SDA and SCLPico GP0 pin 1 and GP1 pin 2I2C data and clock

Code

A remote control flashes an infrared LED on and off very fast, and the receiver module removes the carrier and gives a clean signal that is low while the LED is on. The NEC code used by many remotes sends a 9 millisecond burst, a 4.5 millisecond gap, and then 32 bits. Each bit is a short burst followed by a gap: a short gap of about 0.56 milliseconds means 0 and a long gap of about 1.7 milliseconds means 1. The program records the time of every edge using an interrupt, waits until nothing has changed for 20 milliseconds, then measures the gaps between edges and rebuilds the bits. The 32 bits are an address byte, its inverse, a command byte and its inverse, sent least significant bit first, so the program can check the command for errors. Holding a key sends a shorter repeat code about every 110 milliseconds. Not every remote uses NEC, so a different brand may show nothing or an unusual result.

import time
from array import array
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C

i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
ir = Pin(15, Pin.IN)

stamps = array('l', [0] * 80)                       # time of each edge in microseconds
count = 0

def on_edge(pin):
    global count
    if count < 80:
        stamps[count] = time.ticks_us()
        count += 1

ir.irq(trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING, handler=on_edge)

repeats = 0

def show(lines):
    oled.fill(0)
    for i, text in enumerate(lines):
        oled.text(text, 0, i * 12)
    oled.show()

def decode(t):
    global repeats
    n = len(t)
    if n < 4:
        return
    def d(i):
        return time.ticks_diff(t[i + 1], t[i])
    if not 7000 < d(0) < 11000:                     # the 9 ms start burst
        return
    gap = d(1)
    if n < 10 and 1500 < gap < 3000:                # 2.25 ms gap: the repeat code
        repeats += 1
        show(["IR remote reader", "Repeat code", "Repeats: " + str(repeats)])
        return
    if 3500 < gap < 5500 and n >= 67:               # 4.5 ms gap: a full frame
        value = 0
        for i in range(32):
            space = d(3 + 2 * i)                    # a long space is a 1, a short one a 0
            if space > 1100:
                value |= 1 << i
        addr = value & 0xFF
        addr_inv = (value >> 8) & 0xFF
        cmd = (value >> 16) & 0xFF
        cmd_inv = (value >> 24) & 0xFF
        repeats = 0
        good = (cmd ^ cmd_inv) == 0xFF
        show(["IR remote reader",
              "Address 0x%02X" % addr,
              "Command 0x%02X" % cmd,
              "Check OK" if good else "Check failed",
              "Normal NEC" if (addr ^ addr_inv) == 0xFF else "Extended NEC"])

show(["IR remote reader", "Point a remote", "at the receiver"])
while True:
    if count > 0 and time.ticks_diff(time.ticks_us(), stamps[count - 1]) > 20000:
        n = count
        times = [stamps[i] for i in range(n)]
        count = 0
        decode(times)
    time.sleep_ms(5)

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Press the power keyA command number appears
Press the same key againThe same address and command
Press a different keyA different command, same address
Hold a keyRepeat count rises
Press a key from the side or far awayNeeds a closer aim or a shorter distance

If it does not work

Nothing appears

Check the receiver pin order, many modules are OUT, GND, VCC from the left.

Check failed

Hold the remote steady and closer, and keep bright sunlight and fluorescent lights away from the receiver.

Random numbers

The remote may not use NEC, try another remote.

ImportError for ssd1306

Install the micropython-ssd1306 package.

Display blank

Check the I2C wires and that the address is 0x3C.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the pico infrared remote code reader?

Raspberry Pi Pico H, IR receiver VS1838B, SSD1306 OLED Display and Breadboard 830 Tie Points.

How long does the pico infrared remote code reader take to build?

About 140 minutes for a beginner maker, in 7 steps.

How do I know the pico infrared remote code reader works?

Press the power key: A command number appears. Press the same key again: The same address and command. Press a different key: A different command, same address.

Nothing appears: what should I check?

Check the receiver pin order, many modules are OUT, GND, VCC from the left.

Check failed: what should I check?

Hold the remote steady and closer, and keep bright sunlight and fluorescent lights away from the receiver.

Random numbers: what should I check?

The remote may not use NEC, try another remote.

ImportError for ssd1306: what should I check?

Install the micropython-ssd1306 package.