Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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:
- 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.
- 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.
- */
- const int NUM_SENSORS = 5;
- const int IR_LED_PIN = 2; // IR LEDs control pin
- const int IR_RECEIVER_PINS[NUM_SENSORS] = {A0, A1, A2, A3, A4}; // Phototransistor connected to analog pins A0, A1, A2, A3, A4
- void setup() {
- Serial.begin(9600);
- pinMode(IR_LED_PIN, OUTPUT);
- digitalWrite(IR_LED_PIN, HIGH); // Turn on the IR LEDs
- }
- void loop() {
- for (int i = 0; i < NUM_SENSORS; i++) {
- int sensorValue = analogRead(IR_RECEIVER_PINS[i]);
- Serial.print("Sensor ");
- Serial.print(i + 1);
- Serial.print(" Value: ");
- Serial.println(sensorValue);
- }
- Serial.println();
- delay(500); // Wait 500ms between readings
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement