You don't want to send some (interrupted) TV code, but a continuous 38kHz signal.
The code in void setup() of this sketch will just do that.
An Arduino pin can directly drive an IR LED with 100ohm current limiting resistor.
If distance is a problem, you can increase LED drive current with an external drive transistor.
The code in void loop() is for a receiver.
Transmitter and receiver can run on the same Arduino.
Leo..
const byte IR_LED = 11; // IR transmitter LED with 100ohm (minimum) CL resistor
const byte IR_Receiver = 8; // from receiver output
const byte onboard_LED = 13; // onboard indicator LED
boolean receiverState;
void setup() {
pinMode (onboard_LED, OUTPUT);
pinMode (IR_LED, OUTPUT);
pinMode (IR_Receiver, INPUT);
// from Nick Gammon
TCCR2A = _BV (COM2A0) | _BV(WGM21);
TCCR2B = _BV (CS20);
OCR2A = 209; // ~209 = ~38kHz | ~219 = ~36kHz
}
void loop() {
receiverState = digitalRead (IR_Receiver);
if (receiverState == HIGH) { // beam interrupted
digitalWrite(onboard_LED, LOW); // green onboard LED off
delay(1000);
}
else { // beam detected
digitalWrite(onboard_LED, HIGH); // green LED on
}
}