Infrared Crossing Signal Detector
PIC 12F683

Revised 04-08-08

The objective of this project is to design and construct a controller that will operate a pair of crossing signals.  When a train passes by the infrared sensor #1, Signal #1, that is normally green, will turn yellow for 10 seconds before turning back to green.   At the same time Signal #2, which is normally green, will turn red for 10 seconds before turning back to green.  The 10 second time period will begin only after the last car has passed the infrared sensor.

Two identical controllers will operate the two sets of lights.  The second set of signals is labeled Signal #3 and Signal #4 and are triggered by infrared sensor #2.

The signal lamps will be controlled by NPN Darlington transistors that will support 12 volts at 1/2 amp without a heat sink.

This circuit utilizes a PIC 16F684 microcontroller and Pulsed Infrared Sensors. (click here for more information on these sensors)

Note that reed switches or other sensors could easily be substituted for the IR sensor.

Overview:
The microcontroller produces pulses at 38 kHz  on pin #11 which drive an infrared LEDs through a 220 ohm current limiting resistors.  The IR LED is placed such that the IR sensor (PNA4602M) cannot "see" the IR unless it is reflected by a passing train. 

When a train passes by the sensor a pulse from the PNA4602M is detected and the signal lights are changed as described above.  Once the train is detected  the microcontroller begins to monitor the sensor and resets the lights to their initial setting only after no additional pulses from the train are received for 10 seconds.  This assures that the entire train has passed the sensor before the crossing lights change.

Schematic 16F684 
The signal LEDs are in the lower left.  They are labeled appropriately in the schematic.  Note that the current limiting resistor between the LED and the 12 volt power supply is marked "??K" as this value must be determined by the end user.

 

If the power supply is noisy the following filter, composed of C3 and R8, is suggested to clean up the pulses from the detector.   Note that the additional 100 mfd electrolytic cap in the schematic above (C3) may make this filter unnecessary in most applications.

 

Software
'3-19-08 Crossing Signal Control - manages two sets of two lights
' for Dave S.
'4-4-08 - revising to ignore noise and false hits
' capacitor added between ground and IR sensor output pin to filter out noise
' used 100 mfd or 220 mfd electrolytic on board
DEFINE DEBUG_REG PORTA
DEFINE DEBUG_BIT 4 ' PIN 3 on 16f684
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 1 ' Set Debug mode: 0 = true, 1 = inverted

'define PULSIN_MAX 555
ansel = 0
cmcon0 = 7
Include "modedefs.bas"

IR_Sensor var portc.2 'pin 8
Signal1_Green var porta.5 'pin 2
Signal1_Yellow var porta.2 'pin 11
Signal2_Green var portc.4 'pin 6
Signal2_Red var portc.3 'pin 7

temp var word

trisc = %00000100
trisa = %00000000

debug 13,10,13,10,"Crossing Controller IR",10,13,"(C) 2008 - d. bodnar - ver 1.1x",13,10,"TrainElectronics.com",13,10
hpwm 2, 127,38000 '50% duty cycle @ 38kHz portc.5 - pin 5

Start:
'debug "Start", 10,13
high signal1_green
high signal2_green
low signal1_yellow
low signal2_red

if ir_sensor=1 then
for temp = 1 to 3
debug "temp= ",#temp, 10,13
if ir_sensor=0 then start 'make sure it was not a false signal
next temp
goto GotGoodHit
Endif
goto start
GotGoodHit:
debug "got good hit", 10,13
low signal1_green
low signal2_green
high signal1_yellow
high signal2_red

StayHere:
for temp=1 to 50000
if ir_sensor=1 then
debug "saw rehit", 10,13
goto stayhere
endif
next temp
debug "train has passed... pausing", 10,13
pause 10000
debug "Returning to top", 10,13

goto start:

 
Circuit Board

The control unit is made up of two boards.  The first board contains the power supply circuit, the microcontroller and the interface for the infrared sensors.

The sensor connects through the four wires that go to the right.  The secondary board connects through the six wires that go to the left.  Power is supplies through the red and black wires at the bottom.  The blue and white wires go to the PC's serial port for testing.  They will not be on the finished circuit.

A good bit of rework was needed on the bottom of the board to accommodate this circuit.

The second board supports the four TIP 101 Darlington transistors that power the signal lights and the screw connectors that connect to the signals.  The negative terminal of each connector is marked in black.  If LEDs are used in the signals proper polarity must be observed.

Red, Green and Yellow LEDs were used for testing. 

The connections for the signal lamps are clearly marked on the terminals.  Note the black on the top of these terminals indicating the negative connection.

The back of the secondary board is shown here.

 

The two completed units are shown below.  There are LEDs temporarily installed for testing.  Their current limiting resistors are on the positive leads.  The wires at the top (red and black) are for DC power.  The sets of 4 wires at the bottom go to the sensors.

The completed sensors are shown here.  The IR emitter is in the small brass tube at the top.  The IR sensor is behind a piece of red Plexiglas inside of the plastic pipe.

If you look carefully you can see the sensor behind the cover.  The connections at the bottom of the sensor are soldered to a quick connect.  Note that the connector has been filed down on the corners to fit through the plastic pipe.  The easiest way to extend the length of the sensor cable would be to get two more 4 conductor quick connects - they are from All Electronics (part # CON-440) The positive lead of the sensor is marked with a silver + and should go to the connector's red lead.