IR Light reflection switch, useful for obstacle avoidance or line following, for obstacle avoidance you can place this module in front of the sender /receive diodes that will cause the out pin to be pulled low at distance of 1cm.
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.
Components Required
- Raspberry Pi / Banana Pi / Orange Pi (If your using Banana Pi or Orange See first the GPIO Pin Mapping)
- IR Tracking Sensor / Line Following Module
- Solder Less Bread Board
- Jumper Wire / DuPont Wire
Wiring Guide
Compiling the Code
C Source 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 |
/* 14CORE Test Code for: IR Tracking on C Code .:+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 TrackingPIn 0 #define OutLedPin 1 int main(void) { if(wiringPiSetup() == -1){ // Wiringpi initialization failed print error printf(" Wiripin initialization failed!"); return 1; } pinMode(TrackingPIn, INPUT); pinMode(OutLedPin, OUTPUT); while(1){ if(digitalRead(TrackingPIn) == LOW){ printf("The sensor detects white color line\n"); digitalWrite(OutLedPin, LOW); // Set Output Led turn HIGH delay(100); digitalWrite(OutLedPin, HIGH); // Set Output Led turn LOW } else{ printf("The sensor detects black color line.\n"); delay(100); } } return 0; } |
Python Source 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 |
#!/usr/bin/env python import RPi.GPIO as GPIO IRTrackingPin = 11 OutLedPin = 12 def setup(): GPIO.setmode(GPIO.BOARD) # Set the GPIO pins as numbering GPIO.setup(OutLedPin, GPIO.OUT) # Set the OutLedPin's mode is output GPIO.setup(IRTrackingPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(OutLedPin, GPIO.HIGH) # Set the OutLedPin high(+3.3V) to off led def loop(): while True: if GPIO.input(IRTrackingPin) == GPIO.LOW: print '14CORE | IR Tracking Test Code' print '------------------------------' print 'The sensor detects white color line' GPIO.output(OutLedPin, GPIO.LOW) # Set the OutLedPin turn HIGH/ON else: print '14CORE | IR Tracking Test Code' print '------------------------------' print 'The sensor detects black color line' GPIO.output(OutLedPin, GPIO.HIGH) # Set the OutLedPin turn LOW/OFF def destroy(): GPIO.output(OutLedPin, GPIO.HIGH) # Set the OutLedPin turn HIGH GPIO.cleanup() # Release resource if __name__ == '__main__': # The Program will start from here setup() try: loop() except KeyboardInterrupt: # When control c is pressed child program destroy() will be executed. destroy() |
Wiring TCRT5000 IR Tracking Sensor with Raspberry Pi