This is the Line Tracking Sensor designed for line following robots. The board has two main components IR Transmitter and IR Receiver in one package named TCRT5000. The TCRT5000 are reflective sensors which include an infrared emitter and photo-transistor in a leaded package which blocks visible light. The package included two mounting clips. As you look at the board you can see a Potentiometer or Trimmer which used to adjust the sensitivity of the sensor.
Component Required
- Raspberry Pi / Banana Pi / Orange Pi (If your using Banana Pi or Orange Pi See first the GPIO Pins)
- TCRT5000 Reflective Optical Sensor (Line Follower)
- Solder Less Bread Board
- Jumper Wire / DuPont Wire
- LED (Any Color)
- Resistor 220 Ohms
Wiring Diagram
Wiring Pi C-CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
/* 14CORE Test Code for: TCRT5000 Sensor Test .:+osysso++:` `+yhs/-` `-+s+` `:/+++++++++` .:/++ooo++/-` .ooooooooooo+: :///////////- `odh/` `:y+` /ddhsooooooo+ /hddhsooooydddh sdddoooooosdddy` `////////////` -hds` `sy. +ddy` .ddd: sddy.dddo +ddd- .-----------` `hds :sssss/ -ossssso-yy` `hdd: oddy `ddd/oddd:......+dddo .++++++++++++ +dd` :sdddh` :ydddddddo +y/ .ddd+........ `hddy:.....:yddy.hdddddddddddy+. ```````````` ydy .hddd/+hdddhydddh/.+yo /hdddddddddd. :shddddddddhs/`+ddd:````-yddy- :ooooooooooo+ odh` sdddooyyyyyhddddyy.sy+ ` `......... ``.... ....` ```...` ` `` `` ` -dd+`::::` .:::- /yy. -oos+:-oos+--oos+: /o `+y o/: o:+/ h:`yos /+-`/+/+ s:y/y. /dd/ `+yy: +//+ +/:+ +/:+ -. `/ -:o.:/:`//+- + +:- :`-+:`://: +`o`+. -yds. `/yys- .`-.. .``` ```` .`` ` ` ``` ``-..` ` :ydy/.`````.-/oyhs: `+++oo+oo+:.+-++/-/ooo+o +:o/oo///:+/ .:oyhhhhhhhso:` `. ``` */ #include <wiringPi.h> #include <stdio.h> #define SensorPin 4 #define LedOutput 5 void INOUT(char* ledstate) { pinMode(Rpin, OUTPUT); if (ledstate == "OUTPUT") { digitalWrite(LedOutput, HIGH); } else if (ledstate == "INPUT") { digitalWrite(LedOutput, LOW); } else printf("Error Led Output"); } int main(void) { if(wiringPiSetup() == -1) //If no response from wiringpi.h print { printf("Wiring Pi Initialization Faild"); return 1; } pinMode(SensorPin, INPUT); INOUT("INPUT"); while(1){ if(0 == digitalRead(SensorPin)){ delay(10); if(0 == digitalRead(SensorPin)){ INOUT("OUTPUT"); printf("Button is pressed\n"); } } else if(1 == digitalRead(SensorPin)){ delay(10); if(1 == digitalRead(SensorPin)){ while(!digitalRead(SensorPin)); INOUT("INPUT"); } } } return 0; } |
Python Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#!/usr/bin/env python import RPi.GPIO as GPIO SensorPin = 16 OutputPin = 18 def setup(): GPIO.setmode(GPIO.BOARD) # Set the GPIOS physical location as numbers GPIO.setup(OutputPin, GPIO.OUT) # Setting up the Output pin GPIO.setup(SensorPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(OutputPin, GPIO.HIGH) # Setting up the Outpin to HIGH def loop(): while True: if GPIO.input(SensorPin) == GPIO.LOW: print '14CORE | Output Led is On' GPIO.output(OutputPin, GPIO.LOW) # Turn LED output led on else: print '14CORE | Output Led is Off' GPIO.output(OutputPin, GPIO.HIGH) # Turn LED output led off def destroy(): GPIO.output(OutputPin, GPIO.HIGH) # Turn output LED off GPIO.cleanup() # Releasing the resource if __name__ == '__main__': # Execute the program from here setup() try: loop() except KeyboardInterrupt: # When pressed 'Ctrl+C' child program destroy(). destroy() |
Downloads
Download the TCRT5000 Datasheet Here | PDF
Wiring with TCRT5000 Reflective Optical Sensor Module on Raspberry Pi