I nearly forgot I bought these little sensors. The TCRT5000 is a reflective infrared sensor, it’s a small plastic holder with an IR led and a photo transistor. The IR led emits invisible IR light, when an object is placed in front of it the light is bounced back to the phototransistor. The TCRT5000 has 4 pins and is very easy to connect to an Arduino. You can download the datasheet here to see the pinout.
The collector (C) of the phototransistor is connected to the digital pin on the Arduino, the emitter (E) is connected to ground. The anode (A) of the IR led is connected to a 100ohm resistor, the other end of the resistor goes to 5V. The cathode of the led goes to ground. The range of these little sensors is not big and from testing I learned that they are very sensitive to the light present in the room. The range is only a couple of centimetres. The best thing about them is that they are very cheap, I bought 5 of these from Yourduino for 2$. They can be used to make an encoder or to sense objects that are really close 🙂
Here is the sketch that I used to try them out:
/* http://www.bajdi.com TCRT5000 sensor connected to Arduino Uno TCRT5000 pins: (see datasheet http://www.vishay.com/docs/83760/tcrt5000.pdf ) C = Arduino digital pin 2 E = GND A = 100 ohm resistor, other end of resistor to 5V C = GND */ const int tcrtPin = 2; // connected to the TCRT5000 C pin const int led = 13; // the number of the LED pin // variables will change: int tcrtState = 0; // variable for reading the TCRT5000 status void setup() { // initialize the LED pin as an output: pinMode(led, OUTPUT); // initialize the tcrt5000 pin as an input, and turn on the internal pullup resistors: pinMode(tcrtPin, INPUT); digitalWrite(tcrtPin, HIGH); } void loop(){ // read the state of the tcrt5000: tcrtState = digitalRead(tcrtPin); // check if the tcrt5000 sensor detects something. // if it is, the tcrtState is LOW: if (tcrtState == LOW) { // turn LED on: digitalWrite(led, HIGH); } else { // turn LED off: digitalWrite(led, LOW); } }
http://i7.photobucket.com/albums/y254/keeble/IMG_0826.jpg
I recorrect some connection, and I upload your sketch and the LED keep blinking. Can you help?
i would like it to detect a line and not the distance can you help me whit wat u should change?
See here: http://www.bajdi.com/category/line-following-robot/