An IR sensor can be used as a close distance proximity sensor or to detect the brightness of an object. How it works is that it consists of an IR LED that emits infrared light, and another component that will receive that infrared light. When the emitted light bounces off a surface and returns back to the receiver it will get an intensity reading of the light. This intensity reading can vary depending on the material that the light is bouncing off of. For example a matte black surface will absorb more of the light, whereas a glossy white surface will bounce more of the light back. In this module we will be going through the process to set up the Breadboard block to get these readings from the sensor.
First connect up your Breadboard block to your WIFI and Power Station Blocks.
Add the Breadboard block to your Workspace and click the gear icon to open the Properties panel
Click on the ‘Visual Map’ button and configure pins 1, 2, 3 and 4 as follows:
|IO1 - AnalogIn||IO2 - Input||IO3 - GND||IO4 - VCC|
You can now connect up the sensor to the block. The sensor should have the name for each of the pins printed on the board. Use those names as a reference to plug it into the corresponding pins on the board.
A0 → IO1 AnalogIN
D0 → IO2 Input
GND → IO3 GND
VCC → IO4 VCC
With the Breadboard block configured you can now go into the logic maker to read the sensor values.
Drag two INPUT Gates into the workspace. From the dropdown menu of the ACTION Gate select IO1 for one of the gates and IO2 for the other. Next connect up a DISPLAY Gate to each and hit apply.
You will see that the ACTION Gate connected to IO1 will display the analogue reading and the IO2 gate will display the digital reading. The analogue readings will vary depending on the intensity of light reflected back, if less light is reflected back the value will be greater.
The readings from IO2 will give a digital 1 or 0 reading depending on the threshold set.
If we want to adjust the threshold on the digital reading we can use the potentiometer on the sensor. By using a screwdriver to turn the screw anticlockwise it will decrease the threshold.
The LEDs on the board are useful for setting the threshold. There are two LEDs on the board, one is the power LED and the other is the output LED. The power LED will always be on as long as there is power given to the board. The output LED will be on when the D0 pin is set to 1, so it can be used to see where the threshold is set.
Now that your sensor is configured and the threshold is set you will see that as you move the sensor from a dark surface to a light one it will change in both the analogue readings as well as the digital one.