Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 279
Joined: Fri Jan 06, 2012 7:46 pm

Reading TCRT5000 ir sensor

Thu Dec 19, 2013 1:57 pm

Hi.

I have some ir sensors that I'm trying to read, for use in a line-following robot. I have tried a few configurations and am using a thick black line on a piece of paper as a test sample.

I have the ir led connected to GND & 5V (via 470R resistor), the emitter to GND, and the collector to 3v3 via 10K resistor and pin 7 (GPIO4) via 1k resistor.

I am using a bit of Python script, using interrupts to detect a change on pin 7.

I have some results, of sorts. A change is registered when I move the sensor closer to the paper (around 1cm, but very finnicky) but I can't detect any change between black and white paper.

I realise that the sensor is 5v and returns an analogue value but some people seem to have had success using them, although with not enough detail for me to 'copy &paste'. I have ordered some different sensors that come packaged on a small pcb for easy connection, but I thought I may as well try these bare ones while I'm waiting. I think I have reached the limit of my patience at the moment, so I thought I'd see if any of you guys can shed any light on the problem.

Thanks, Daz.
Last edited by Forris on Sun Dec 22, 2013 6:58 am, edited 1 time in total.

User avatar
exartemarte
Posts: 373
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: Reading TCRT500 ir sensor

Fri Dec 20, 2013 11:43 pm

Forris wrote:Hi.

I have some ir sensors that I'm trying to read, for use in a line-following robot. I have tried a few configurations and am using a thick black line on a piece of paper as a test sample.

I have the ir led connected to GND & 5V (via 470R resistor), the emitter to GND, and the collector to 3v3 via 10K resistor and pin 7 (GPIO4) via 1k resistor.

I am using a bit of Python script, using interrupts to detect a change on pin 7.

I have some results, of sorts. A change is registered when I move the sensor closer to the paper (around 1cm, but very finnicky) but I can't detect any change between black and white paper.

I realise that the sensor is 5v and returns an analogue value but some people seem to have had success using them, although with not enough detail for me to 'copy &paste'. I have ordered some different sensors that come packaged on a small pcb for easy connection, but I thought I may as well try these bare ones while I'm waiting. I think I have reached the limit of my patience at the moment, so I thought I'd see if any of you guys can shed any light on the problem.

Thanks, Daz.
Did you mean TCRT5000? If so, that's just an ir led/phototransistor pair in a plastic housing. Let's assume that's what you've got and that it's all connected up correctly.
To start with I would simplify the monitoring arrangements. Instead of using interrupts to detect change, just write a loop that continuously monitors the port and tells you whether it is high or low. With the configuration you have described you should expect low when the sensor is over white and high when it is over black. If you have a multimeter it might also be useful to measure the voltage at the output.

Using similar arrangements (with students) I have found that non-functioning sensors are usually down to one of four things:
1. Failure to turn on the led, especially if it's under program control.
2. Too much ambient light. Although they are infra-red devices they are sensitive to ambient light to some degree - try shading with something opaque.
3. Distance from the surface being sensed - about 1cm generally works well.
4. The nature of your black line - some black markers and felt-tips reflect almost as much infra-red as a white surface. I have found that laser-printed black on white paper works well, as also do black whiteboard markers. Black pvc insulating tape also seems to work.

If, after you've checked out all of the above, your sensor only returns 1's (meaning the phototransistor isn't turning on) you could try increasing the illumination by reducing your led current-limiting resistor, say to 220 or 330 ohms. You could also reduce the collector resistor, say to 3.3K or 4.7K; I generally use 10K, but that's on 5-6v systems - I haven't tried it with 3.3v.

Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 279
Joined: Fri Jan 06, 2012 7:46 pm

Re: Reading TCRT500 ir sensor

Sat Dec 21, 2013 6:38 pm

Thanks for taking the time to give such a lengthy reply. I'll hopefully manage to steal a few hours peace & quiet next week to give your suggestions a try. I'll post back if I get any further.

Cheers, Daz.

JonA
Posts: 3
Joined: Sat Feb 01, 2014 6:34 pm

Re: Reading TCRT5000 ir sensor

Sat Feb 01, 2014 6:54 pm

I've only just joined this forum, but read your post today when I was looking for online info on the TCRT5000 sensors, as I received some I'd bought from EBay today and was testing them. I don't know if you've already got yours working (assuming they're the same item), but in case not, I suspect you're not driving the IR LED with enough current. The datasheet I found specifies a maximum forward current of 60mA (ie more than you would normally expect for an LED) and a forward voltage of 1.25V. This suggests a series resistor of much less than your 470R with 5V. I've been successfully testing mine (just looking for High/Low results) with a 100R series resistor from 5V and they work, detecting the difference between white and black at a range of about 1cm. (I'm using a 4K7 resistor to pull the collector up to 3V3.) Hope this helps.

User avatar
exartemarte
Posts: 373
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: Reading TCRT5000 ir sensor

Sat Jun 07, 2014 8:55 pm

I finally got around to playing with an actual TCRT5000, after buying a handful on eBay. On 5v, with a 220 ohm resistor for the LED, a 10K pull-up for the phototransistor, and the output feeding directly into an Arduino digital input, I got consistent black white detection. My test piece is laser-printed black on white paper; it also detected my (dark) desk top as black and my finger as white. It was completely unaffected by my desk lamp, even close up, but that is fluorescent and probably doesn't emit much UV.

I think this quite a neat and convenient little package, and I'm planning to use some in a line follower. My only reservation is that the housing is a touch over 0.2in wide, so you can't stack them side by side on 0.1in prototype board without a bit of Dremelling...

jfaraudo
Posts: 1
Joined: Sat Feb 20, 2016 5:46 pm

Re: Reading TCRT5000 ir sensor

Sat Feb 20, 2016 5:50 pm

We succeed reading TCRT5000 ir sensor with a simple python script using the following configuration: GND connected to 220 Ohm resistor, Out connected to a 100KOhm resistor, input directly to 5V . The reading of the GPIO gives 1 or 0 depending on the distance and material, etc.

Return to “Automation, sensing and robotics”