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.
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.