Infrared around us
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.
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. IrRead() is used to read the received codes.
IrEnable(1) k = IrRead() Println(k)
They codes received can come from any remote with similar protocols. The table here maps they codes to buttons on the remote. You can see there that the numbers 1 to 9 on the remote map to 16 to 24 on the received codes. IrRead() will return -1 if it has nothing.
We will build a program that IrRead() 10 times a second. If it receives a key press that is more than 16 then this is a 1 to 9 key.
IrEnable(1) @Loop Wait(100) k = IrRead() If k = -1 Goto Loop End If k > 16 Println(k-15) Else Println("Other Press") End Goto Loop
What other technologies use IR? Can you think of any ways to use the remote to do different things?