Files
microcontroller/nano/Lichtschranke_TCST2103/Lichtschranke_TCST2103.ino
T
2020-04-29 15:41:56 +02:00

40 lines
728 B
Arduino

// https://www.youtube.com/watch?v=po_lHVKFQWI
// http://heliosoph.mit-links.info/photointerrupter-basics/
/*
+5V --220 Ohm-- ---- GND
| |
+ D
TCST2103
E +
| |
GND ---- ----10kOhm---- +5V
|
|
----A0 PIN
*/
int sensorPin = A0;
int sensorValue = 0;
int ledPin = LED_BUILTIN;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if (sensorValue > 512) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
delay(200);
}