With EV3 IR Sensor being recognized as Color Sensor, to detect the IR Remote Control’s button presses, one can use the Color Value reading change events. This data reading detects one of the 9 different button press patterns of the IR Remote as illustrated below.
E.g. When your program detects a color value of 10 (White), it means the user has pressed both the Red Down and Blue Down buttons. And, you would probably program the logic to interpret that as “going backwards” or “going downwards”.
Note that using this method, you will not get any channel information for the button press.
The following Word Block example program demonstrates how one would perform this discrete color value detection. The program will light up your hub’s dot matrix LEDs at locations based on the button pattern you pressed.
Note: We could have used the Color Sensor – “when color is” event block for this detection. However, during our development, we found that for whenever the sensor detects a color that matches blue (3) or Teal (4), the “when color is” block would fire both color events. This would not be acceptable for our use case. That’s why we use the “when” event block with condition based on the numeric value of the color being read.
The resulting app will run as follows:
To retrieve full information (including Channel) for the IR Remote Control’s button presses, one may use the Reflected Light Value data reading. This data reading provides full information for the IR physical remote button press including information about the selected channel on your remote control. It value ranges from 0 to 47. The following formulas may be used to decode the value into Channel and Button Press Code:
The following example Word Block program shows how one would perform such detection using the formulas above.
The defined code values for the Button Presses are as follows:
One can use the Red channel of the RGB Raw value to access the distance proximity feature. This data reading is in the range from 0 to 255, representing the object’s approximate distance from the sensor.
The following example Word Block program shows how one would perform such detection. This program draws a horizontal bar on the LED Matrix of the hub based on the distance of the object from the sensor. In this program, we defined a custom block “Draw_light_bar” that takes a number in the range of 0 to 5 as a parameter to draw the bar. In the main program, we stored the scaled distance value into the variable “Distance_0_to_5”. This distance is calculated with the formula:
( Log ( IR Sensor reading ) – 1 ) * 5
This formula scales the proximity distance value (ranged from 0 to 255) down in log scale to a range of 0 to 5. The formula is derived by “Trial and Error” such that all values >= 80 will light up 5 lights. Then, as the object gets closer, the program would progressively light up less number of lights.
With Python, user may use the Reflected Light Value change events for detecting IR Remote Control’s button presses. This data reading detects button press patterns of the IR Remote as well as channel information. The formulas for decoding the IR channel and IR code are:
The Button Code is defined as in the table on the right.
The following Python example program shows how one would perform such detection. This example program will light up the LED matrix at locations based on the button pattern you pressed. The resulting app will work exactly the same as the example program in Word Blocks.
Note: This program will only respond to an IR Remote Control that is set to Channel 3. You may change the program accordingly to detect for other channels.
User may use the Red channel of the RGB Raw value to decode the proximity distance information. This data reading is in the range from 0 to 1024.
The following example program is to demonstrate how one performs this proximity distance decoding in Python. This program draws a horizontal bar on the LED Matrix of the hub based on the distance of the object from the IR sensor. In the program, we defined a function that takes a number in the range of 0 to 5 as parameter to draw the bar. Similar to the equivalent Word Block example, we use the following formula to scaled the RGB Red value down to a value in the range of 0 to 5, and store the value into the variable “Distance_0_to_5”:
( Log ( IR Sensor reading /4 ) – 1 ) * 5
The EV3 IR Sensor has the ability to estimate the general direction (heading) of and the distance (proximity) to the IR Beacon. One can use this functionality to implement a robotic vehicle that follows the IR Beacon. It is important to note that even with the QikEasy Adapter, this feature is only available to Spike Prime and Robotic Inventor when you program in Python.
To use the channel, heading direction and distance information, the user program has to read the sensor’s data value array in Mode 7. This data array contains 3 values as described below:
|When the beacon is on the left side of the sensor||-25|
|When the beacon is on the right side of the sensor||25|
|When the beacon is directly in front of the sensor||0|
Below is an example program that demonstrates this IR Beacon Seek functionality in Python. The program will simply repeatedly print the channel, heading and distance information in the console area.