Using an IR Sensor (TCRT 5000) with Arduino
Using IR Sensor (TCRT 5000) With Arduino
An infrared (IR) sensor is a type of sensor which detects and sends out a signal in response to infrared radiation. The TCRT 5000 is an infrared sensor that can be used to detect presence, proximity or obstacle detection. By using an Arduino and the TCRT 5000, you can create projects such as line following robots, obstacle avoiding robots, etc.
Parts Required
- TCRT 5000 - 1
- Arduino Board - 1
- Breadboard - 1
- Jumper Wires
- LED - 1 (optional)
- 220Ω Resistor - 1 (optional)
Circuit Diagram
The circuit diagram for using TCRT 5000 with Arduino is shown below.
Description
The TCRT 5000 consists of an LED and a phototransistor mounted facing each other. When there is no object between them, the LED emits infrared radiation which is detected by the phototransistor. If a white surface is between the LED and the phototransistor, the infrared radiation is reflected back to the phototransistor, causing it to turn ON. The circuit diagram above shows how to connect the TCRT 5000 to an Arduino board. The emitter pin of the sensor is connected to the ground pin of the Arduino. The collector pin is connected to 5V through the 220Ω resistor and also to the digital pin 7 of the Arduino board. The output pin is connected to the digital pin 8 of the Arduino board.
Program Explanation
The program below reads the output from the TCRT5000 and prints it on the Serial Monitor. The program continuously reads the status of the digital pin 8 and prints the value on the Serial Monitor.
// Code for Using TCRT 5000 with Arduino
int ledPin = 7; // LED pin connected to digital pin 7
int outputPin = 8; // Output pin connected to digital pin 8
void setup()
{
pinMode(ledPin, OUTPUT); //pin 7 as output
pinMode(outputPin, INPUT); //pin 8 as input
Serial.begin(9600);
}
void loop()
{
int status = digitalRead(outputPin); // Read the status of pin 8
Serial.println(status); // Print the status on serial monitor
delay(500); //wait for 500ms
}