What is the IR sensor?
IR sensor is an electronic sensor that emit and detecte infrared radiation.
How does it work?
IR Sensors work by using a specific light sensor to detect a select light wavelength. By using an LED which produces light at the same wavelength as what the sensor is looking for, you can look at the intensity of the received light.
When an object is close to the sensor, the light from the LED bounces off the object and into the light sensor.Since the sensor works by looking for reflected light, it is possible to have a sensor that can return the value of the reflected light. This type of sensor can then be used to measure how "bright" the object is. This is useful for tasks like line tracking.
IR sensor components
How to connect it?
Setting up IR sensor connection to Arduino is very simple. Beside VCC and GND pin, the sensor has two pins that should be connected to two of the digital pins on Junkbot board.
How to program it ?
Enabling the sensor is done by setting the digital pin connected to the EN pin as low (low --> enable, high --> disable) and attach it to any event from your choice. In order to display the IR sensor reading, Junkbot Sprite can do that using the “say” block inside a forever loop. Then set it to read the digital pin value connected to the IR sensor.
Here is an example code: