With an Arduino I am using a code snippet that Nick Gammon published in an Arduino forum post:
How do I best create a 38 kHz square wave using a Teensy LC?
The purpose of the square wave is, you guessed it, driving an IR LED. It's not for remote control, however. It's for a simple light barrier. This means, the 38 kHz signal doesn't need to be modulated.
BTW, I will likely upgrade to a Teensy 3.6.
Code:
// set up Timer 2
TCCR2A = _BV (COM2A0) | _BV(WGM21); // CTC, toggle OC2A on Compare Match
TCCR2B = _BV (CS20); // No prescaler
OCR2A = 209; // compare A register value (210 * clock speed)
// = 13.125 nS , so frequency is 1 / (2 * 13.125) = 38095
How do I best create a 38 kHz square wave using a Teensy LC?
The purpose of the square wave is, you guessed it, driving an IR LED. It's not for remote control, however. It's for a simple light barrier. This means, the 38 kHz signal doesn't need to be modulated.
BTW, I will likely upgrade to a Teensy 3.6.