Model Railway Car Detector

 

 

Updates and corrections in red italics!

The car detector sits under the track and works by reflection.  The sensitivity of the unit is settable – using a plug in “calibration box” – which consists of three connectors, a couple of LEDs (and dropping resistors), a momentary contact push button switch, a potentiometer and a toggle switch.

 

The sensor itself is set up for active high (i.e. a high means that a train is passing) to properly interface with existing circuitry.  This is easily changeable.  You can build the unit for less than $10. 

 

Start up cost is a little more of course – a USB programmer can be purchased for about $US50. I will add a page with a suggested list of startup items – with part numbers for DigiKey (www.digikey.com) and prices…

 

The prototype of Car Detector was built using a ATMEL ATtiny45 microcontroller.  The 45 is overkill – a ATtiny25 will work just at well at a saving of about $1.00 per sensor.  These two chips are identical except for the amount of memory on each (there is also an 85 available).   The parts list specifies the ATtiny25.

 

Total price for the detector runs about $US7 and the Calibration Unit will cost about $US20 (pots, switches and knobs are expensive!)  Of course you only need a single calibration unit!

 

The schematic has been updated to include a 10k pullup resistor and a .1mfd capacitor in the lead that is used to switch the microcontroller into calibrate mode.  I have had problems that seem to be related to the microcontroller erroneously going into calibrate mode.  This only seems to happen when it is connected to my shuttle controller and I am using the ISP (In System Programming) function to reprogram it.  I suspect that it would not be an issue if I were using a separate power supply for the sensors.

 

Schematic for the Train Detector         and a gif version

Source Code for the Train Detector

Parts List for the Train Detector

Calibration Unit Schematic                  and a gif version

Calibration Unit Parts List

Picture of Sensor connected to calibrator

Picture of a Sensor built into a section of HO cork roadbed.  Note for this picture – a tie must be (re)moved from the track, the IR rcvr is too large to fit between the ties.  The top if the IR Rcvr’s small dome sticks up just proud of the track ties.  The emitter sits between the ties (it just fits) and is tilted very slightly toward the receiver.  The edge of the emitter closest to the Rcvr is touching the road bed.

 

This shows a later variant of the sensor.  It isn’t obvious in the photo, but the only components that stick up above the top of the cork road bed are the IR emitter and the IR receiver.  The top of the emitter is just below the top of the ties on code 100 track.  The round part of the IR receiver is just proud of the top of the ties.

 

 The emitter body itself (which is transparent) doesn’t really show up in the photo – just the innards!  Note the exposed 2.2K resistor – I left it there so I could swap it out if necessary – it wasn’t.  The 8 pin dip socket is to allow me to reprogram the microcontroller – which hasn’t been required. The reason that I put it in was that I had the output sense of the first example inverted – i.e. it was high when it should have been low.  The microcontroller is to the left of the resistor.  Wiring between the socket and the microcontroller is with some very very thin (40 gauge ??) self fluxing wire that I have left over from 20 years ago.  It was made by Vector and a “wiring pencil” was used to wrap it around the pins.  Apply a hot (750 degree) iron and solder right through the insulation.  I haven’t been able to find anyone in the United States that supplies this wire anymore.  Vero in the UK advertises something that looks the same, but I haven’t tried it.

 

 

Still to come

-         a simple little detector circuit to tell you if everything is working (note a below). 

-         Instructions on the use of the calibration box. 

 

     Notes:

a)    If you decide to order some things – then order enough for an extra IR receiver circuit and an extra red led. 

b)    The 2.2 K dropping resistor specified for the IR Emitter works for me.  To be on the safe side, I would order some additional resistors from 470 ohms through 4.7k.  You might have to tweak the value of that dropping resistor.

c)     The code available here is configured to supply an active low when a car is detected.  I will post code for an active high if someone asks.  (Alternatively a couple of resistors and an NPN transistor will do the level conversion).

 

 

If you have any questions or ideas, drop me a note at

 

Villy.Madsen@shaw.ca

 

2007-03-04