This example is for Wiring version 0024+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.
Transmissive optical sensor without aperture Vishay TCST1000/TCST2000 by Diana Fernandez
Demonstrates how to use a transmisive optical sensor. This sensor is used in mechanisms to detect when the gap in the top is blocked by an object. When the sensor detects an interruption the Wiring onboard LED is turned on.
Demonstrates how to use a transmisive optical sensor. This sensor is used in mechanisms to detect when the gap in the top is blocked by an object. When the sensor detects an interruption the Wiring onboard LED is turned on.
int sensorSwitch = 1; // digital pin to attach the switch
int sensorLED = 0; // sensor LED
int boardLED = 48; // Wiring onboard LED
void setup()
{
pinMode(sensorSwitch, INPUT); // sets digital pin 1 as input
pinMode(sensorLED, OUTPUT); // sets digital pin 0 as output
pinMode(boardLED, OUTPUT); // sets digital pin 48 as output
digitalWrite(sensorLED, HIGH); // turns ON the sensor LED
}
void loop()
{
// make the onboard LED to show the sensor status
digitalWrite(boardLED, digitalRead(sensorSwitch));
}


