This project was released by Petr Šídlo and uses an Arduino Pro Mini and Optical sensor(s) to detect block occupation on a Digitrax system (S88 feedback bus).
The sensor operates on the principle of reflection of the infrared beam from the vehicle.
While Infrared light is not visible to humans, it is very usefull in electronic projects . An IR transmitter LED and IR receiver phototransistor is mounted between sleepers under the rails and will not disturb traffic as there are no mechanical or direct electrical connections to the track.
The basic solution is a development board Arduino Pro Mini with the controller ATMEGA328.
This project uses the Mini Pro Board (ATMEGA328 5V 16M) .
I chose this board because it has all pins are easily accessible on the circuit board including pins A6 and A7.
The Arduino Pro Mini has 14-pin digital and 8 analog pins.
Pin assignments are as follows:
- 0 and 1 – for PC communication – recording the program and debug
- 2 – LOAD / PS bus S88-N
- 3 – CLOCK bus S88-N
- 4 – DATA IN bus S88-N
- 5 – DATA OUT bus S88-N
- 6 -13 – power IR LEDs 1-8
- A0 – A7 – voltage on the phototransistor 1-8
- IR LEDs are used in devices L-934F3BT
- LED Avg. 3 mm, 2.6 – 3,6mW / sr @ 20 mA (Uf = 1,20V), transparent blue, 30deg, 940nm
- IR phototransistors used: L-932P3BT phototransistor Avg. 3mm, 30V, 940nm, 30deg
- For RJ 45 connectors are standard networking components
- Note that the connector is marked differently than the connector pins 8-8LP.
- Auxiliary power is supplied through the protection of the Schottky diode 1N5817
(For this reason the auxiliary supply voltage is 5.4 V, because the voltage drop on the diode is about 0.4 V)
Functionality & Description
We read the state of the phototransistor as an Analog input.
Analog input uses 10 bit AD converter.
We evaluate the voltage of the phototransistor , which is in the range 0-5 V and converts it into numeric values 0 – 1023.
The measurement ( detection) is performed in two steps. In the first step , the transmit IR LED is off , and measures the voltage on the transistor . This will reveal the amount of stray light from the surroundings.
Then the lights IR LED and phototransistor measurement is repeated .
If there is a significantly increase in the amount of light hitting the phototransistor , it means that in the vicinity of the sensor is the object from which the reflected infrared beam . It therefore does not matter whether it is a lot of ambient light obtrusive ( the proximity of a lamp or window ) or little ( tunnel) .
To detect HO trains, we experienced a problem when the vehicles had a high floor- to overcome this problem this solution uses two diodes in series. The resulting resistance of two diodes is 51 Ω with a current of 30mA. For smaller scale you could use a diode with a resistance of 100 Ω . When using two LEDs luminous flux was really great . When used in the tunnel ceiling it is necessary to use black , otherwise it will be detected. Or use only one sensor diode.
We use tubing (heatshrink tubing) on the phototransistor so that transistor only measures the reflected light and is shielded from the sides of the diodes.
The program is written in three versions for different lighting conditions.
For Simple measurements: S88_IR_v110
S88_IR_110 program is designed for incandescent lighting. The program waits for the pulse LOAD and then triggers the measurement. It takes the measurement sensors 1 to 8 If the voltage at the phototransistor when lit IR LEDs 3 × smaller than when off diode, and is evaluated as busy. If the voltage is higher, so it is evaluated off.
Among lighting up / switching off IR LED and phototransistor to begin measuring the delay is 2-3 ms to stabilize the situation in the controller ATMEGA328.
After successive readout values of all 8 sensors measurement result is stored in the variable state.
When other pulse LOAD is a state variable content is copied to the variable data.
At each pulse the CLOCK data bits of the variable data is sent successively to the bus S88-N, and at the same time are stored in the variable data bits from the preceding module S88.
For Incandescent lighting use S88_IR_v120
S88_IR_120 program is designed for incandescent lighting . Measurements are made continuously , waiting on the pulse LOAD . The measurement results are stored in a variable field partialState [ 5 ] , which holds 5 consecutive measurements .
When evaluating the results of counting the number of busy and free time. If the number of results occupied by 3 or more , so the final result is busy , otherwise it is off . The final result is stored in the variable state . Another running program is the same as the program S88_IR_110 .
For fluorescent lighting : S88_IR_v130
S88_IR_130 program is designed for fluorescent lighting . The problem is that fluorescent lights will flash at a frequency of 100 Hz . It is therefore important that measurements are unlit and lit IR LED conducted with the same phase shift glow lamps .
The program is designed so that it reads the system time and the controller is saved. Then performed a series of eight measurements, the LED off. Followed by waiting for the next period , that is 10 ms. Waiting is set to 20 ms , because of a series of eight measurement lasts for about 17 ms and the beginning of the next subsequent period, the time of 20 ms. Then, in the same rhythm carry out eight measurements with the light diode.
Evaluation of the results are the same as those in S88_IR_120 , ie 3 of the fifth
When debugging a program switched communication over a serial line and it is possible to get your listing to monitor any information from the Arduino .
When tuning is necessary to be very careful, because there are three interconnected power sources.
- Source 1: Power supply of S88 – N bus
- Source 2: Auxiliary power supply of 5.4 V
- Source 3: Power from USB programmer connected to your computer.
Incorrect wiring may ( and probably will ) to destroy the Arduino USB port on your computer or DCC controller.
Complete Project File: S88_IR_10_sensor