The TCRT 5000 IR sensor is an infrared reflective sensor module that includes an infrared emitting diode and a phototransistor. It is designed to detect the presence of an object within a specific distance by reflecting infrared light off the object and measuring the intensity of the reflected light. This sensor is widely used in applications such as line following robots, object detection, and proximity sensing.
Pin Number | Name | Description |
---|---|---|
1 | Vcc | Power supply (3.3V to 5V) |
2 | GND | Ground connection |
3 | OUT | Digital output signal (active low) |
4 | EN | Enable pin (optional use) |
5 | AO | Analog output signal |
// Define the TCRT 5000 sensor output pin
const int sensorPin = 2;
void setup() {
// Initialize the sensor output pin as an input
pinMode(sensorPin, INPUT);
// Begin serial communication at 9600 baud rate
Serial.begin(9600);
}
void loop() {
// Read the sensor value
int sensorValue = digitalRead(sensorPin);
// Print the sensor value to the Serial Monitor
Serial.println(sensorValue);
// Wait for 100 milliseconds before reading again
delay(100);
}
Note: The above code assumes that the TCRT 5000 sensor's OUT pin is connected to digital pin 2 on the Arduino UNO. The code reads the digital output from the sensor and prints it to the Serial Monitor. If the sensor detects an object, it will print 0
(since the output is active low); otherwise, it will print 1
.