Sensor

๐Ÿ“ก IR Transmission

๐Ÿ“Œ Description

Infrared (IR) transmission is a way for the robot to send signals using invisible light. Itโ€™s the same technology used in TV remotes. The robot can send coded messages that another device can understand.

๐ŸŽฏ Use

In our projects, infrared transmission is used to:

  • Control other devices wirelessly (like turning on a TV or robot module).
  • Send commands without cables.
  • Practice communication between robots or sensors.

๐Ÿ‘‰ Think of infrared transmission as the robotโ€™s remote control voice โ€” it talks to other devices using invisible light signals.

ย Module parameters

Pin name Description
G GND (Power Input Negative)
V VCC (Power Input Cathode)
S Digital signal pins
  • Supply voltage: 3.3V/5V

  • Connection: PH2.0 terminal wire

  • Installation method: double screw fixing


๐Ÿ–ฅ๏ธ Code Explanation

import machine
import irremote
import time

pin18 = machine.Pin(18, machine.Pin.IN)          # Button connected to pin 18
ir_tx = irremote.NEC_TX(26, False, 100)          # IR transmitter on pin 26

while True:
    if not pin18.value():                        # If button is pressed
        while not pin18.value():                 # Wait until button is released
            time.sleep_ms(10)
        ir_tx.transmit(0x45, 0x1c, 1)          # Send hex command (0x45)
        print(ir_tx.busy())                      # Print if transmitter is busy

Step by Step

  1. import machine, irremote, time โ†’ Tools for pins, IR communication, and timing.
  2. pin18 = machine.Pin(18, machine.Pin.IN) โ†’ Reads the button input.
  3. ir_tx = irremote.NEC_TX(26, False, 100) โ†’ Sets up the IR transmitter on pin 26.
  4. while True: โ†’ Loop that repeats forever.
  5. if not pin18.value(): โ†’ Checks if the button is pressed.
  6. while not pin18.value(): โ†’ Waits until the button is released (avoids multiple signals).
  7. ir_tx.transmit(0x45, 0x1c, 1) โ†’ Sends a hex command (0x45) using NEC protocol.
  8. print(ir_tx.busy()) โ†’ Shows if the transmitter is still sending.

๐Ÿ‘‰ Together, this program makes the robot send an infrared command whenever the button is pressed.


โœ… Conclusion of the Test

  • If pressing the button makes the IR transmitter send a signal, the program is working correctly.
  • This test shows how the robot can send wireless commands using infrared light.
  • Later, you can change the hexโ€‘command (like 0x45) to control different actions or devices, just like different buttons on a TV remote.

button Hex-raw hex-command
1 0xba45ff00 0x45
2 0xb946ff00 0x46
3 0xb847ff00 0x47
4 0xbb44ff00 0x44
5 0xbf40ff00 0x40
6 0xbc43ff00 0x43
7 0xf807ff00 0x7
8 0xea15ff00 0x15
9 0xf609ff00 0x9
* 0xe916ff00 0x16
0 0xe619ff00 0x19
# 0xf20dff00 0xd
Up 0xe718ff00 0x18
Left 0xf708ff00 0x8
Right 0xa55aff00 0x5a
Down 0xad52ff00 0x52
Ok 0xe31cff00 0x1c

On this page