Skip to content

Instantly share code, notes, and snippets.

@raspberrytipsnl
Last active June 13, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raspberrytipsnl/2368a3679e4c5419b2fa0fa8280bc1ab to your computer and use it in GitHub Desktop.
Save raspberrytipsnl/2368a3679e4c5419b2fa0fa8280bc1ab to your computer and use it in GitHub Desktop.
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