diff --git a/nano/Lichtschranke_TCST2103/Lichtschranke_TCST2103.ino b/nano/Lichtschranke_TCST2103/Lichtschranke_TCST2103.ino new file mode 100644 index 0000000..bdde16f --- /dev/null +++ b/nano/Lichtschranke_TCST2103/Lichtschranke_TCST2103.ino @@ -0,0 +1,39 @@ +// 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); +}