STM32 IR Remote Control Receiver and Transmitter

Two Test Remotes

02/04/2023

This was a revision of something I investigated many years ago but thought it would be
a good topic to re-visit and apply to the STM32F103 microcontroller.

Using an old TV remote as an input device for your microcontroller project is a simple way
to implement an entire keypad using only a single I/O pin.

The key is getting the receiver/demodulator device, in my case a VS1838 IR Receiver Module, easily
found online.  Since most appliance remotes actually transmit a burst of 38khz IR flashes it helps to
use a device that will sense this wavelength of light and frequency of flashes but ignore everything else.
So when this receiver detects a 38Khz burst of light in the 860-1050nm wavelength, it will output
a single logical ‘LOW’ on it’s output pin.  (the VISHAY TSOP2838 can also be used)

The next task is to decode the sequence of bursts (and the spaces between them) to create a unique code for each button on the remote.

Basically I wrote some code to watch for the transitions on the pin the receiver is connected to and
measure the time between changes. When no changes are detected for a specific period of time the
program will set a flag and allow us to examine the patterns to decode the message.

The two old remotes I dug up were quite different in the signals they produced.
The “Teac” remote used a fairly common IR protocol and produced a single 32bit code for each button press.

The “Sony” remote used a variation of another common protocol but in this case the length of the codes differed depending on which buttons were pressed, producing 12, 15 and 20bit codes that repeated 3, 4 or 5 times. Sometimes the same button repeated the code a different number of times the 2nd and 3rd time it was pressed. (thankfully the actual code was still the same)   The sample projects I’ve supplied below decode the buttons of only the 2 remotes in the picture, but it will try to read the bursts from anything you point at it and with a little experimentation, one could come up with routines to decode more devices.


The second part of this experiment was to build an IR Transmitter.
This project requires an IR LED producing an output in the 950nm range.
(Borrowing one from another old/broken remote is the easiest way to get one.)

In this case the code needs to generate the 38Khz burst signal and turn it on/off for specific amount of
time to generate a signal.

For this, the code simply translates a 32bit code into an array of time values that will duplicate the signal of an actual remote then send them off for processing.
I’ve read that it’s possible, with the help of some amplification, to use an IR LED as a light detector. This would allow us to “learn” codes from another remote and store them to re-transmit on demand.

If you take a look at the code you'll find some useful explanations in the comments.

Here's some photos to explain a bit better

Download links for the project code can be found the bottom of the page

IR Receiver Breadboard 

IR Transmitter Breadboard

Serial terminal output.  Times are displayed  in hex for compactness and represent 10us counts.
(e.g.  the 2nd hex value, 0379 = 889 decimal  representing 8890us or approx. 9ms)
The upper batch of pulse times was produced by the IR Transmitter Breadboard.
The lower batch was generated by the actual 'TEAC' Remote.
Note: the first and last values in each batch are my markers not actual pulse values

Description of download links:

STM32F103_UART_IR_Remote.zip IR Remote Receiver Project code

STM32F103_UART_IR_XMIT.zip IR Remote Transmitter Project code

VS1838_datasheet.pdf IR Detector datasheet