IR Transmission

🎮 First Light

Microproject Image

📦 CONCEPT BOX A protocol is a public language 

The transmitter is an invisible flashlight that speaks NEC the exact same language the commercial remote spoke. When you call: 

ir_tx.transmit(0x45,0,0) # Command 0x45, address 0, toggle 0 

three numbers travel: the command (your message the star), the address (which device family 0 means "anyone"), and the toggle (leave at 0). 

Two consequences to feel today: 

The language is public. Your robot can send 0x45 the exact code of remote button 1 and any NEC receiver on Earth will believe it. Your board will even fool itself.

busy() is the "mouth full" test True while light is still flying. And line of sight rules everything: light does not turn corners. 

Goal: 

fire your first invisible signal and catch it with your own receiver the full loop on one board. 

Concepts: 

IR Transmission · IR Reception · busy() · Line of Sight

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

TRANSMITTER UNIT

import irremote
import time
# Controls the infrared transmitter
# pin26 corresponds to D2 on the Sensor Shield V5.0
ir_tx = irremote.NEC_TX(26,False,90)
ir_tx.transmit(0x45,0,0)	# Transmit command 0x45 to turn on light
time.sleep(2)
ir_tx.transmit(0x46,0,0)	# Transmit command 0x46 to turn off light

RECEIVER UNIT, connect to battery, upload the code only once (ALL IN 1)

import irremote
import machine
import time
# Controls the infrared receiver
# Controls pauses and timing
# Sets up ir_rx as the infrared receiver
# pin25 corresponds to D3 on the Sensor Shield V5.0
ir_rx = irremote.NEC_RX(25,8)
# Sets up pin17 as an output for the RED channel
# pin17 corresponds to D4 on the Sensor Shield V5.0
pin17 = machine.Pin(17, machine.Pin.OUT)
# Sets up pin16 as an output for the GREEN channel
# pin16 corresponds to D5 on the Sensor Shield V5.0
pin16 = machine.Pin(16, machine.Pin.OUT)
# Sets up pin27 as an output for the BLUE channel
# pin27 corresponds to D6 on the Sensor Shield V5.0
pin27 = machine.Pin(27, machine.Pin.OUT)
# Listen forever
while True:
    # Is there a signal waiting to be read?
    if ir_rx.any():
        # Byte 0 of the received message
        x = ir_rx.code[0]
        # Show all four in hexadecimal
        if hex(x) == '0x45':	c
            pin17.value(1)
        elif hex(x) == '0x46':	# turn off light
            pin17.value(0)
        elif hex(x) == '0x47':	# turn on light
            pin16.value(1)
        elif hex(x) == '0x44':	# turn off light
            pin16.value(0)
        elif hex(x) == '0x40':	# turn off all lights
            pin17.value(1)
            time.sleep(2)
            pin17.value(0)
            pin16.value(1)
            time.sleep(2)
            pin16.value(0)
            pin27.value(1)
            time.sleep(2)
            pin27.value(0)
        elif hex(x) == '0x43':	# turn on the red light
            pin17.value(0)
            pin16.value(0)
            pin27.value(0)
            pin17.value(1)
        elif hex(x) == '0x7':	# turn on the green light
            pin17.value(0)
            pin16.value(0)
            pin27.value(0)
            pin16.value(1)
        elif hex(x) == '0x15':	# turn on the blue light
            pin17.value(0)
            pin16.value(0)
            pin27.value(0)
            pin27.value(1)
        elif hex(x) == '0x9':	# turn off all the lights
            pin17.value(0)
            pin16.value(0)
            pin27.value(0)
        else:
            pass
    # Fast checking pace
    time.sleep_ms(20)

💡 Note: for a heartbeat after firing, busy() was True your code was still shouting in light. No glow, no sound, yet 0x45 crossed your desk and came home. If you see "Nothing heard", the fix is physical, not code: point the transmitter's LED straight at the receiver's dome. With invisible light, alignment IS the connection.

🎮 Send, ON, OFF

Microproject Image

Goal: 

send three letters one by one and don't send the next until the echo of the previous one arrives. 

Concepts: 

Send-and-Wait · Confirmation (ACK) · For-Each over a List

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

import irremote
import machine

# Controls the infrared transmitter
# pin26 corresponds to D2 on the Sensor Shield V5.0
ir_tx = irremote.NEC_TX(26,False,90)
# Transmits command 0x45
while True:
    y = input('Type ON to turn the light on or OFF to turn it off.')
    if y == 'ON':
        ir_tx.transmit(0x47,0,0)
    elif y == 'OFF':
        ir_tx.transmit(0x44,0,0)
    else:
        y = input('Type ON to turn the light on or OFF to turn it off.')

Serial Monitor: 

=== SEND AND CONFIRM === 

Sent: 0x41 - waiting for the echo... 

>>> Confirmed! It arrived as 0x41 

Sent: 0x42 - waiting for the echo... 

>>> Confirmed! It arrived as 0x42 

Sent: 0x43 - waiting for the echo... 

>>> Confirmed! It arrived as 0x43

 All three letters made the round trip! 

💡 Note: two new ideas in one program. ① The list [0x41, 0x42, 0x43] a box holding several values, and for letra in letters visits each one (you peeked inside lists during the Wi-Fi scan). ② Send-then-wait-for-confirmation engineers call the confirmation an ACK, and it is how the internet guarantees delivery: no new packet until the old one is confirmed. Notice what your waiting loop guaranteed: nothing gets lost silently the program simply refuses to move on until the letter comes home.

🎮 Turn off all lights

Microproject Image

Goal: 

your board sends the EXACT codes of remote buttons 1 and 2 and its own Module-30 translator announces the button names, completely fooled. 

Concepts: 

Public Protocols · Impersonation · Security Thinking

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

import irremote
import time

# Controls the infrared transmitter
# pin26 corresponds to D2 on the Sensor Shield V5.0
ir_tx = irremote.NEC_TX(26,False,90)
while True:
    ir_tx.transmit(0x40,0,0)
    time.sleep(7)

Serial Monitor: 

=== THE IMPERSONATOR === 

This board will fool ITSELF... 

The board believed: BUTTON ONE 

The board believed: BUTTON ONE 

The board believed: BUTTON ONE 

A receiver cannot tell a remote from a robot! 

💡 Note: the crime and the deception happened on the same desk, in front of the same screen and the receiver still believed it. That is the power and danger of a public protocol: whoever speaks NEC is believed. This is exactly how universal remotes command your TV and why real car keys use rolling codes that change every press: a copied signal must stop working. Two modules and one desk just taught you why digital security exists.

🎮 Turn on the RED, GREEN, BLUE light

Microproject Image

Goal: 

fire 10 numbered packets while you sabotage the beam then read the report and see exactly WHICH packets died. 

Concepts: 

Numbered Packets · Loss Detection · Link Testing

Infrared · Sequence · Timing · Pattern · Serial Output

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

import irremote
import machine

# Controls the infrared transmitter
# pin26 corresponds to D2 on the Sensor Shield V5.0
ir_tx = irremote.NEC_TX(26,False,90)
# Transmits command 0x45
while True:
    y = input('Type R - G - B to turn the light on or OFF to turn it off.')
    if y == 'R':
        ir_tx.transmit(0x43,0,0)
    elif y == 'G':
        ir_tx.transmit(0x7,0,0)
    elif y == 'B':
        ir_tx.transmit(0x15,0,0)
    elif y == 'OFF':
        ir_tx.transmit(0x9,0,0)
    else:
        y = input('Type R - G - B to turn the light on or OFF to turn it off.')

Serial Monitor (a hand blocked packets 4, 5 and 6): 

=== DELIVERY REPORT === 

10 packets leaving block the beam mid-volley! 

Sent: 1 2 3 4 5 6 7 8 9 10 

Arrived: 1 2 3 - - - 7 8 9 10 

💡 Note: the volley takes about 2.5 seconds enough time to slide your hand between the modules for packets 4–6. The dashes are detected losses: the numbering does the detective work, no guessing. This is precisely how the internet measures itself every data packet carries a number, and gaps mean "resend that one." Run the report three times: clean, blocked, and with the transmitter rotated 45°. Fill your own table that table is your link's personality card, same as the dead-zone maps you made for motors.