TCRT5000 5 Channel Module

Mar 31st, 2023
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The 5-channel TCRT5000 module has five TCRT5000 reflective photosensors on a single board. Here's a simple Arduino code to read each sensor's output and display it on the Serial Monitor:
  4. To wire the 5-channel TCRT5000 module, connect its VCC pin to the 5V pin on the Arduino and the GND pin to the ground. Connect the module's IR LED control pin (usually marked as "LED" or "IR") to the IR_LED_PIN (pin 2) on the Arduino. Connect the analog output pins of each TCRT5000 sensor on the module (usually marked as "AO1", "AO2", "AO3", "AO4", "AO5" or "A1", "A2", "A3", "A4", "A5") to the corresponding IR_RECEIVER_PINS (analog pins A0, A1, A2, A3, A4) on the Arduino.
  6. This code will continuously read each sensor's output and print the readings on the Serial Monitor. The sensor values will vary depending on the amount of infrared light reflected by the objects in front of the sensors.
  7. */
  9. const int NUM_SENSORS = 5;
  10. const int IR_LED_PIN = 2; // IR LEDs control pin
  11. const int IR_RECEIVER_PINS[NUM_SENSORS] = {A0, A1, A2, A3, A4}; // Phototransistor connected to analog pins A0, A1, A2, A3, A4
  13. void setup() {
  14.   Serial.begin(9600);
  15.   pinMode(IR_LED_PIN, OUTPUT);
  16.   digitalWrite(IR_LED_PIN, HIGH); // Turn on the IR LEDs
  17. }
  19. void loop() {
  20.   for (int i = 0; i < NUM_SENSORS; i++) {
  21.     int sensorValue = analogRead(IR_RECEIVER_PINS[i]);
  22.     Serial.print("Sensor ");
  23.     Serial.print(i + 1);
  24.     Serial.print(" Value: ");
  25.     Serial.println(sensorValue);
  26.   }
  27.   Serial.println();
  28.   delay(500); // Wait 500ms between readings
  29. }
Add Comment
Please, Sign In to add comment