03-04 PhotoInterrupter
From Manuals
A simple program to test KTIR slotted optosensor. It switches an LED according to state of sensor.
The signals used for this example are listed below:
| Signal | LPC4330 PIN NAME | BAM210E | BAM210 | BAM200E | BAM200 | Used for |
| D0 | P6_5 | J9-1 | J9-1 | S2-5 | S2-5 | LED |
| D2 | P1_7 | J9-3 | J9-3 | S3-7 | S3-7 | Photo Interrupter |
The following schematic can be used to build the circuit with a BAM210E or BAM210.
/*Program Example 3.4: Simple program to test KTIR slotted optosensor. Switches an LED according to state of sensor
*/
#include "mbed.h"
DigitalOut redled(D0);
DigitalIn opto_switch(D2);
int main()
{
while(1) {
if (opto_switch==1) //input = 1 if beam interrupted
redled = 1; //switch led on if beam interrupted
else
redled = 0; //led off if no interruption
} //end of while
}
The following image shows the built circuit on a BAM210E.


