This light blocking module (other known as photo interrupter module) is a photosensor, which consists of a light emitting element and the light receiving elements aligned facing each other in a single package, that works by detecting light blockage when a target object inserted between these elements. It acts as an optical switch.
Code example for light blocking module
Upload the code to Arduino and test the module. When you want to block the light between the two elements, insert any solid object between the gap of these two elements in the light blocking module. If there is an object in the middle of two elements, the sensor will output a HIGH level signal, and the light of led will turn on.