Author Options:

Example schematic / code for transmitting infrared signal (ie TV remote control)? Answered

I am trying to send a infrared signal (ie TV remote control) from my PC. I have a usb connection to a PIC18F4550. The USB connection works fine but I cant get the IR LED to work properly. Does anyone have a example schematic / code that will do this?



This is from the Picaxe command manual at

It may help you - of course it applies to the Picaxe microprocessor a PIC based system running a form of basic - In this case it applies to the sony protocol.

IROUT pin,device,data
- pin is a variable/constant which specifies the i/o pin to use.
- device is a constant/variable (valid device ID 1-31)
- data is a constant/variable (valid data 0-127)
Transmit an infra-red signal, modulated at 38kHz.
This command is similar to the ‘infraout’ command found on earlier PICAXE
devices, but can be used on any output pin.
This command is used to transmit the infra-red data to Sony ™ device (can also be
used to transmit data to another PICAXE that is using the irin, infrain or infrain2
command). Data is transmitted via an infra-red LED using the SIRC (Sony Infra
Red Control) protocol.
device - 5 bit device ID (0-31)
data - 7 bit data (0-127)
When using this command to transmit data to another PICAXE the device ID
used must be value 1 (TV). The irout command can be used to transmit any of
the valid TV command 0-127. Note that the Sony protocol only uses 7 bits for
data, and so data of value 128 to 255 is not valid.
Therefore the valid infraout command for use with infrain2/infrain/irin is
irout 1,1,x ; (where x = 0 to 127)
Sony SIRC protocol:
The SIRC protocol uses a 38KHz modulated infra-red signal consisting of a start
bit (2.4ms) followed by 12 data bits (7 data bits and 5 device ID bits). Logic level
1 is transmitted as a 1.2 ms pulse, logic 0 as a 0.6ms pulse. Each bit is separated
by a 0.6ms silence period. For more information about the protocol see the
‘infraout’ command description.
Effect of Increased Clock Speed:
This command will automatically use the internal 4MHz resonator for correct
All commercial remote controls repeat the signal every 45ms whilst the button is
held down. Therefore when using the PICAXE system higher reliability may be
gained by repeating the transmission (e.g. 10 times) within a for..next loop.
for b1 = 1 to 10
irout 1,1,5
pause 45
next b1"

For any length of button push duration...

Thanks for the reply, but I am using C18 and this does not have a library function equivalent to the IROUT on PICAXE

How are you driving the LED now ?