Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The TCRT5000 is a reflective photosensor that consists of an IR LED and a phototransistor in a single package. Here's a simple Arduino code to read the sensor's output and display it on the Serial Monitor:
- To wire the TCRT5000 sensor, connect its anode (IR LED's longer leg) to the IR_LED_PIN (pin 3) on the Arduino and the cathode (IR LED's shorter leg) to ground. Connect the collector (phototransistor's flat side, longer leg) to the IR_RECEIVER_PIN (analog pin A0) on the Arduino, and the emitter (phototransistor's round side, shorter leg) to ground. Add a pull-up resistor (typically 10kΩ) between the IR_RECEIVER_PIN (analog pin A0) and the 5V pin on the Arduino.
- This code will continuously read the sensor's output and print the readings on the Serial Monitor. The sensorValue will vary depending on the amount of infrared light reflected by the object in front of the sensor.
- */
- const int IR_LED_PIN = 3; // IR LED connected to pin 3
- const int IR_RECEIVER_PIN = A0; // Phototransistor connected to analog pin A0
- void setup() {
- Serial.begin(9600);
- pinMode(IR_LED_PIN, OUTPUT);
- digitalWrite(IR_LED_PIN, HIGH); // Turn on the IR LED
- }
- void loop() {
- int sensorValue = analogRead(IR_RECEIVER_PIN);
- Serial.print("Sensor Value: ");
- Serial.println(sensorValue);
- delay(500); // Wait 500ms between readings
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement