I want to create a square wave of 38 KHz pulsed at 10hz to be fed to an IR led so a receiver can read it's value and figure it out the distance from 0 to 255.
I tried making a pin high and low for 13 microseconds but it doesn't seem to work.
Is there a way by using a timer or something else to achieve this purpose ?
The easiest way might be to feed 38khz into the anode of a diode (1N914), cathode to a series 220R resistor to the base/gate of a NPN/NchannelMOSFET transistor, emitter/source to GND.
The feed 10hz to the anode of a 2nd diode, the cathodes of both diodes are connected.
Anode of IR diode to +5v cathode to a 50 Ω resistor then to the collector/drain of the transistor.
If using MOSFET, cathodes of the two drive diodes to a 10k resistor to GND.
Does your project require the 38 kHz signal to be phase coherent with the on-off signal? In other words, can the 38 kHz signal be chopped short or long?
You can't get exactly 38 kHz with a 16 MHz Arduino timer since 16000000 / 38000 = 210.5263 clock ticks per half cycle. Would 37914.7 Hz be close enough?