Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TCRT5000 tracking sensor
#!/usr/bin/env python
# TCRT5000 tracking sensor
# https://raspberrytips.nl/tcrt5000
import RPi.GPIO as GPIO
TrackingPin = 11
def setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(TrackingPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def loop():
while True:
if GPIO.input(TrackingPin) == GPIO.LOW:
# Detectie wit oppervalk (of voorwerp bij sensor)
print '[wit | object]'
else:
# detectie zwart oppervlak (of geen voorwerp bij sensor)
print '[zwart | geen object]'
def destroy():
GPIO.cleanup()
if __name__ == '__main__':
setup()
try:
loop()
except KeyboardInterrupt:
destroy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment