It's easy to use the High Power Infrared LED Emitter with Python or CircuitPython, and the Adafruit_CircuitPython_IRRemote module. This module allows you to easily write Python code that allows you to send IR remote pulses using the pulseio core module

CircuitPython Microcontroller Wiring

First, wire up an infrared LED emitter to your board exactly as shown below. Here's an example of wiring a Feather M4 to the infrared LED emitter using one of the handy STEMMA JST PH cables:

  • Board 3V to LED emitter V+ (red wire)
  • Board GND to LED emitter GND (black wire)
  • Board pin 5 to LED emitter In (white wire)

You can also use standard 0.100" pitch headers to wire it up on a breadboard:

  • Board 3V to LED emitter V+ (red wire)
  • Board GND to LED emitter GND (black wire)
  • Board pin 5 to LED emitter In (white wire)

CircuitPython Usage

To use with CircuitPython, you need to first install the IRRemote library, and its dependencies, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.

Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.

Your CIRCUITPY/lib folder should contain the following folders and file:

  • adafruit_irremote.mpy
CIRCUITPY

Example Code

# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
# SPDX-License-Identifier: MIT
# Based on irremote_transmit.py for CPX by ladyada

import time
import pulseio
import board
import adafruit_irremote

# Create a 'PulseOut' to send infrared signals on the IR transmitter @ 38KHz
pulseout = pulseio.PulseOut(board.D5, frequency=38000, duty_cycle=2**15)
# Create an encoder that will take numbers and turn them into NEC IR pulses
emitter = adafruit_irremote.GenericTransmit(
    header=[9500, 4500], one=[550, 550], zero=[550, 1700], trail=0
)

#  count variable
count = 0

while True:
	#  send IR pulse
    emitter.transmit(pulseout, [255, 2, 255, 0])
	#  increase count
    count += 1
	#  print to REPL
    print("IR signal sent %d times!" % count)
	#  two second delay
    time.sleep(2)

Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!

The code begins by creating a pulseio object on pin D5. This will send infrared signals via the IR transmitter at 38KHz. Then, emitter is created with the adafruit_irremote library that will take numbers and turn them into NEC IR pulses.

In the loop, an IR signal is pulsed out every two seconds. In the REPL, you'll see "IR signal sent # times!" print out after the pulse is sent. The variable count counts the number of times this occurs and is passed to the string in the REPL.

This guide was first published on Nov 16, 2022. It was last updated on May 18, 2024.

This page (CircuitPython) was last updated on May 18, 2024.

Text editor powered by tinymce.