Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES Buy from JP

In this lesson,  we will first explain the principle of common IR communication protocols. Then we will write a small program to test the IR code of each button in a remote. Finally we will use OK button in the remote to turn on/off an LED.

For example, when you hit a button on your TV remote, an IR LED repeatedly turns on and off, 38,000 time a second, to transmit information (like volume or channel control) to an IR photo sensor on your TV.

Stage 1: Read IR code from Arduino Serial port

In this stage, we will tell you how to test the IR code of each button in IR remoter and display the code in Mixly serial monitor.

Please plug OSOYOO magic I/O board onto OSOYOO Basic Board for Arduino First. Then connect IR receiver module to D2 port of the Magic I/O board with 3-pin PNP cable as following picture:

Notice: Shut off your battery or Unplug your power adapter when upload sketch code to OSOYOO Basic Board for Arduino.

You can download the code directly, then click “Open” in Mixly to choose the code you download:

Download the Code

Or you can do as following operations:
After above operations are completed, connect the OSOYOO Basic Board for Arduino to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Graphical Programming software Mixly and follow the next operations:

Drag out the IR Control block from the Communicate category ,set pin 3 as input.

Save and upload program to OSOYOO Basic Board for Arduino
(1)Click Save after programming is done.

(2) Select the board type and serial port before uploading. In our case, we are using Uno board, so just select Arduino/Genuino Uno.

(3) Select the serial device of the OSOYOO Basic Board for Arduino from the COM menu.

(4)Next,upload the code. If the uploading fails, check connection according to the prompts.

(5)Finally, the status will change to ‘Upload success!’.

Open the Serial Monitor in the Mixly at 9600 bps and hit different buttons on your IR remote controller. The sketch will automatically decode the type of remote you are using and identify which button on your remote controller is pressed. The Serial Monitor displaying random button presses on my remote controller. Different buttons show different codes:

(NOTE: Receiving “FFFFFFFF” means “repeat” if you hold the button down.)

Now you can press OK button and see what is the result in serial monitor of Mixly. Write down this code for later use.

Stage 2: Use IR remote to turn on/off an LED

In Stage 1, we can know the IR code of the OK button by press OK button in Stage 1 program . In Stage 2, we will take advantage of this knowledge to use OK button turn on/off an LED.

Connection

Plug OSOYOO magic I/O board onto UNO board First. Then connect IR receiver to the D2 port of Magic I/O board with 3-pin PNP cable as following picture(same as stage 1), then plug an LED module to D12 port of the Magic I/O board as following :

You can download the code directly, then click “Open” in Mixly to choose the lesson12-2 code you download:Download the Code

Or you can do as following operations:
Firstly Drag out a  if block in Control category.
Drag out the first block in Logic category.
Drag out a ir item block in Variables category.
Drag out a  0 block in Match category.

Note: The 0xFF38C7 in above picture  is the OK button  we got  from stage 1 sample program.

Drag out a  DigitalWrite block in In/Out category and a Delay block in Control category.

Set the pin 12 as output, drag out a not block from logic category into the stat block

Drag out a DigitalWrite block from In/Out category into stat block

Save and upload program to OSOYOO Basic Board for Arduino
(1)Click Save after programming is done.

(2) Select the board type and serial port before uploading. In our case, we are using Uno board, so just select Arduino/Genuino Uno.

(3) Select the serial device of the OSOYOO Basic Board for Arduino from the COM menu.

(4)Next,upload the code. If the uploading fails, check connection according to the prompts.

(5)Finally, the status will change to ‘Upload success!’.

A few seconds after the upload finishes, press the “OK” button of a remote controller, the LED attached connected to D12 will be light up. Then press “OK” again, and the LEDs will go out.

WHAT IS IR?

Infra-Red light is actually normal light with a particular colour. We humans can’t see this colour because its wave length of about 950nm is below the visible spectrum.

We need to konw there are many more sources of Infra-Red light. The sun is the brightest source of all, but there are many others, like: light bulbs, candles, central heating system, and even our body radiates Infra-Red light.

A common modulation scheme for IR communication is something called 38kHz modulation. There are very few natural sources that have the regularity of a 38kHz signal, so an IR transmitter sending data at that frequency would stand out among the ambient IR. 38kHz modulated IR data is the most common, but other frequencies can be used.

When you hit a key on your remote, the transmitting IR LED will blink very quickly for a fraction of a second, transmitting encoded data to your appliance.

If you were to hook an oscilloscope up to your TV remote’s IR LED, you would see a signal similar to the one above. This modulated signal is exactly what the receiving system sees. However, the point of the receiving device is to demodulate the signal and output a binary waveform that can be read by a microcontroller. When you read the OUT pin of the VS1838B with the wave from above, you will see something like the second.

Modulation

As everything that radiates heat, also radiates Infra-Red light. Therefore we have to take some precautions to guarantee that our IR message gets across to the receiver without errors.Modulation of the signal on a carrier frequency is the answer to make our signal stand out above the noise. With modulation we make the IR light source blink in a particular frequency. The IR receiver will be tuned to that frequency, so it can ignore everything else.In the picture below you can see a modulated signal driving the IR LED of the transmitter on the left side. The detected signal is coming out of the receiver at the other side.