Infrared

Infrared

What is Infrared and how is it used?

Infrared is basically a color our eyes cannot perceive but is around us everywhere. Infrared is used in many different products, such as telescopes to see distant planets and gases. Weather satellites use infrared to show us images of storms. Infrared is also used in night vision to see objects in the dark.

In the IR Receiver module and remote control, infrared is used to communicate between the remote control and the IR Receiver.  The invisible infrared light emits from the remote control when a button is pressed. This light turns on and off very fast. The IR Receiver has a light sensor, which can see these light flashes and then convert those pulses into information. Since an infrared module must ‘see’ the invisible light it only works within the same room. IR light does not go through walls.

There are thousands of remote and receiver options but we will use a BrainPad Microcomputer with IR Receiver from the BrainClip kit.

Connect the BrainPad Pulse/Edge as shown in the diagram. The IR Decoder feature is fixed on pin 2.

We can now enable the IR decoder.

Python

BrainPad.Infrared.Enable(1)

C#

BrainPad.Infrared.Enable(true);

JS

await BrainPad.Infrared.Enable(1);

Each time the button on the remote control is pressed a new number is sent to the IR receiver, which then the decoder reads and stores internally, up to 16 presses. Infrared.Read() is used to read the received codes.

Python

ir = BrainPad.Infrared.Read()

C#

ir = BrainPad.Infrared.Read();

JS

ir = await BrainPad.Infrared.Read();

The codes received can come from any remote with similar protocols. A remote press will result in Infrared.Read() in a “code” and no press will result in a -1.

We will build a program that Infrared.Read() 10 times a second.

Python

BrainPad.Infrared.Enable(1)
while(True):
    BrainPad.System.Wait(100)
    k = BrainPad.Infrared.Read()
    if k == -1:
        continue
    BrainPad.System.Println(k)

C#

BrainPad.Infrared.Enable(true);
while(true){
    BrainPad.System.Wait(100);
    var k = BrainPad.Infrared.Read();
    if(k == -1){
        continue;
    }
    BrainPad.System.Println(k);
}

JS

await BrainPad.Infrared.Enable(1);
while(true){
    await BrainPad.System.Wait(100);
    var k = await BrainPad.Infrared.Read();
    if(k == -1){
        continue;
    }
    await BrainPad.System.Println(k);
}

BrainStorm

What other technologies use IR? Can you think of any ways to program the remote to do different things?

Content Licensing
Newsletter

Twitter Feed
Hot off the press!