Reference > Brix for Arduino
2.03.001 - IR Train Detector

Description
Brick 2.03.001 is an infra red (IR) based sensor that is designed to detect passing LEGO® trains and monorail trains. It's an active sensors that works day and night. It detects passing trains by emitting IR light and detecting the amount that is reflected back.
Specifications
  • Operating voltage: 4.8V - 5.0V
  • Wave length: 940nm
Pinout
The IR train detector has a cable with a 3 pin connector:
Operation
It's important to power the sensor with the proper voltage; the sensor is designed to operate at 4.8 - 5.0V. When you power the sensor with a higher or lower voltage, it might still work but it will not have an optimal sensitivity. For example, when you power the sensor with 3.3V, it will be so sensitive that it will be saturated by the ambient IR of the sun light rending its signal useless to detect passing trains.
The output signal of the sensor is a voltage ranging between 0 and the input voltage (~5V). The output voltage increases with the amount of detected IR light. So high output values correspond with passing trains, while low voltages indicate the sensor is not detecting any objects.
Troubleshooting Tips
The 940nm wavelength is outside the visible spectrum so you cannot see whether the sensor is emmiting light with the naked eye. However, most digital cameras are sensitive to 940nm light so you can use, for example, a cell phone camera to check if the sensor is emitting IR or not.
Example - Wiring
This is a wiring diagram using an Arduino Nano type board.
Example - Code
The following Arduino code will read the data from the sensor and print it in the serial monitor.
//--------------------------------------------------------------------------------------------------
// demo-2-03-001.ino
//
// Description: Demo to control a 4DBrix 2.03.001 train detection sensor.
//
// Author: Lowa
// Created: 16-Jun-2017
// Copyright (C) 2017, 4DBrix LLC.  All rights reserved.
//
// Please feel free to use this example for personal, non-commercial use only, provided you keep the
// copyright message intact.  Have fun !
//--------------------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------------------
int sensorPin;                                // The control pin for the sensor
int value;                                    // The returned value of the sensor


//--------------------------------------------------------------------------------------------------
// Initialization process
//--------------------------------------------------------------------------------------------------
void setup() {

  // Start the serial communication
  Serial.begin(9600);                         // Use the default Arduino baud rate

  // Configure the sensor
  sensorPin = 0;                              // Analog pin 0  will be used to read the sensor signal
  pinMode(sensorPin, INPUT);                  // Define pin 0 as input pin

}


//--------------------------------------------------------------------------------------------------
// Processing loop
//--------------------------------------------------------------------------------------------------
void loop() {

  // Read the sensor output
  value = analogRead(sensorPin);

  // Print the sensor output in the serial monitor
  Serial.print("Sensor: ");
  Serial.println(value);

  // Wait 0.1 seconds for the next measurement
  delay(100);
  
}


//--- End-of-File-----------------------------------------------------------------------------------