SEARCH
TOOLBOX
LANGUAGES
modified on 17 September 2014 at 17:58 ••• 21,571 views

03-04 PhotoInterrupter

From Manuals

Jump to: navigation, search

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:

Signals Used and Connector Locations for Example 03-04
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.

BAM210
Schematic for example 03-04
/*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.