Example Code for Using the On-board IR TX/RX

Last revision 2026/01/06

This blog post offers example code and instructions for using infrared transmission and reception to control RGB lights with UNIHIKER boards, providing a comprehensive guide for beginners to achieve remote light control.

Hardware Preparation

This example uses 2 UNIHIKERs and 2 expansion boards, one of which uses the infrared transmission function, and the other uses the infrared reception and RGB light function, to achieve infrared remote control light switch.

Software Preparation

According to the Getting Started section in the UNIHIKER official documentation, it is recommended for beginners to operate according to the instructions in the Mind+ section. [Click to view]

The main process is: download and install MInd+ on your PC, open Mind+, switch to Python mode and Code page, click on the icon in front of Terminal, open the Connect Remote Terminal menu, and then connect the UNIHIKER. After that, you can create a new py file in the File System, write code and run.

Mind+ interface diagram

Wiring Diagram

Wiring Diagram

Sample Code

  • Receiver End:
#  -*- coding: UTF-8 -*-
# MindPlus
# Python

import time
from pinpong.board import Board,Pin,IRRecv,NeoPixel
from pinpong.extension.unihiker import *

def event(data):
    my_variable = hex(data)
    print(my_variable)
    if (my_variable == (str("0xfd00ff"))):
        print("open")
        np1.range_color(0,2,0x0000FF)
    if (my_variable == (str("0xfd807f"))):
        print("close")
        np1.range_color(0,2,0x000000)

Board().begin()

ir1 = IRRecv(Pin((Pin.P14)),event)
np1 = NeoPixel(Pin((Pin.P13)),3)
np1.brightness(128)

while True:
    time.sleep(1)

  • Transmitter End:
#  -*- coding: UTF-8 -*-
# MindPlus
# Python

import time
from pinpong.board import Board,Pin,IRRemote
from pinpong.extension.unihiker import *

Board().begin()

p_p15_irSend=IRRemote(Pin(Pin.P15))

while True:
    print("TX:0xfd00ff")
    p_p15_irSend.send(0xfd00ff)
    time.sleep(2)
    print("TX:0xfd807f")
    p_p15_irSend.send(0xfd807f)
    time.sleep(2)

Result

The RGB light can be switched on and off using the infrared remote control, and the RGB light can also be controlled using the infrared transmission board. When the infrared is blocked, the RGB light stops.

Dynamic illustration of infrared transmission and reception effect

Dynamic illustration of infrared remote control effect

Additional Information

The IR Remote Controller in this example is from DFR0107 Gravity: IR Kit for Arduino

Was this article helpful?

TOP