Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Train Detectors - IR reflection, 38 khz using microcontrollers

1641 views
12 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    November 2006
  • 61 posts
Train Detectors - IR reflection, 38 khz using microcontrollers
Posted by Villy on Wednesday, February 21, 2007 6:43 PM

I have been working on a design for a microcontroller based train detector that can be installed underneath the track (in the cork roadbed).  This detector uses a microcontroller to drive an infra-red emitter with a coded 38 khz signal, detects the signal with an off the shelf IR 38khz receiver, the output of which is decoded and validated by the microcontroller.  An additional feature is the ability to adjust the sensitivity after the unit is installed, the adjustment being stored in the microcontroller's flash memory.

 The unit is immune to spurious sources of IR - including other sources of 38khz ir (such as a tv remote control).  Total cost to build is about $US7.00.

 Picture, schematics and program can be found at

members.shaw.ca/Villy.Madsen

 

Villy 

 

 

  • Member since
    December 2005
  • From: East Granby, CT, USA
  • 505 posts
Posted by jim22 on Wednesday, February 21, 2007 10:08 PM

Sounds neet.  What are  you using for a microcontroller?

Jim (aerospace software developer) 

  • Member since
    November 2006
  • 61 posts
Posted by Villy on Wednesday, February 21, 2007 11:22 PM
AMTEL AVRtiny45 - although it's overkill - the tiny25 has got more than enough memory (the whole program occupies less than 500 bytes).  Take a peek at the web site for code, part's list etc.
  • Member since
    December 2005
  • From: East Granby, CT, USA
  • 505 posts
Posted by jim22 on Thursday, February 22, 2007 9:56 PM

I checked out your web-site and took a peek at the code.  I like the assembler instruction set.  I've been using Motorola and Texas Instruments micro's.  The TI, which is a DSP, has a miserable instruction set to try to read.  I programmed both in C (and some assembler where needed).  Both of these are devices with full pin-outs for exteral address and data bus, so much more complicated to wire than what you're using.

The TI DSP was used to commutate a pair of brushless DC motors with Hall sensor rotor position sensing for the Airbus A380 aircraft.  Ever since I've had this weird urge to put a brushless DC motor in an HO locomotive with a DSP to drive it and blue-tooth wireless control via a PDA.

Jim 

  • Member since
    July 2006
  • From: Colorado
  • 707 posts
Posted by joe-daddy on Friday, February 23, 2007 2:32 AM
 Villy wrote:

I have been working on a design for a microcontroller based train detector that can be installed underneath the track (in the cork roadbed).  This detector uses a microcontroller to drive an infra-red emitter with a coded 38 khz signal, detects the signal with an off the shelf IR 38khz receiver, the output of which is decoded and validated by the microcontroller.  An additional feature is the ability to adjust the sensitivity after the unit is installed, the adjustment being stored in the microcontroller's flash memory.

 The unit is immune to spurious sources of IR - including other sources of 38khz ir (such as a tv remote control).  Total cost to build is about $US7.00.

 Picture, schematics and program can be found at

members.shaw.ca/Villy.Madsen

Villy 

Interesting.  Here is a link to my blog where I have evaluated and discussed four different approaches to block detection including IR.  http://wwwjoe-daddy.blogspot.com/2007/01/lessons-learned-block-detection-choices.html 

I appreciate the creativity and the engineering here!

Joe Daddy 

My website and blog are now at http://www.joe-daddy.com
  • Member since
    November 2006
  • 61 posts
Posted by Villy on Friday, February 23, 2007 8:44 AM

Thanks for your comment Joe.

I think that my approach resolves many (if not all) of the problems associated with the use of the "sensor" approach to train detection - except one!  That is the issue of determining whether or not there is a train (or a disconnected car) sitting in the area between the sensors...

 

The only solution to that is current detection - with load resistors on each car - as your blog points out.  In this particular case, I developed the sensors in order to solve the problems that you mentioned with IR based detectors.  I had bought one of Mr Paisley's circuit boards to manage a 14 ft train track mounted on a pony shelf.  A train running back and forth is not great - but it's better than no train at all!! <G>.   I couldn't run the train during the day because the sunlight (windows behind the pony shelf) would flood the detectors - etc etc etc.

The under the track reflection approach works well - and the wiring is really not visible unless you are standing right beside the shelf -  on a regular layout one could run the wiring underneath the layout.

There are some cars that seem to have absolute IR absorbtion material for underbody - the detector does see them, but it's not solid - in spite of all of the tuning that I have done.  If I increased the sensitivity anymore, the sensor is always on...

In the event, the old fashioned current detector approach is still the way to go if you want the most reliable detection. It's the only way that (if everything works) actually tells you that there is a car(s) in the block.  Everything else is basically only telling you that it saw something at the particular point where the sensor is located.   In my particular case, that's all I need, and I'm not really up to drilling tiny holes on dozens of wheel sets.  Not at this time anyway...

Villy 

 

 

 

  • Member since
    November 2006
  • 61 posts
Posted by Villy on Friday, February 23, 2007 9:33 AM

Yeah, the instruction set is fairly clean.

 

There are a few gotcha's - some of the instructions are not executed the same across the entire family of processors (so what else is new)...  Also once you are into the bigger (more IO) processors - the really expensive ones that cost $5 or $6 or even $7 a shot (I couldn't resist!), the IN and OUT instructions don't work for all IO ports. IO is memory mapped - actually everything is mapped into the memory address space - even though there are a couple of dedicated instructions IN and OUT for io.  It only works up to (afair) 0x60. (6 address bits).  After that it's down to using store and load instructions.

A nice regular instruction set like the VAX or PDP ones would be nice - but then they would no longer be able to claim that almost all instructions execute in one tick - and all the rest in two....

 I wrote up a short program that generates a pseudo-random bit stream - a 32 bit linear feed back shift register.  I haven't calculated it's top frequency yet - that might be an interesting exercise.  I'll post the code this weekend.  I tried to re-do it in C - and it didn't work (although it would work for a 15 bit LFRS) .  Looking at the disassembled code, it appears that the compiler is handling the named variables correctly - but I'm not so sure that the intermediate calculations are being handled using longs (hence I suspect why 15 bits is ok - and 17 isn't).

If I get bored, I may play around with that a little this weekend.  I also built a signal controller  using an ATmega88 to control a couple of 3 lamp signals.  It ties in to the four sensors.  I needed the extra pins - certainly not the increased memory that this chip has.  Real difficult wiring job - decoupling circuit on the various hot connections, (a couple of VCC pins, 2 gnd pins and VRef for the ADC) and six dropping resistors for the lamps (I replaced the bulbs with T1 leds - looks a lot nicer too) - and the connectors (totalling 14 pins) for the lamps and sensors....

I am starting to draw up some specifications for a fancy DC throttle -

PWM, settable throttle response (and PWM frequency) for up to say 8 locomotives, air brake emulation (i.e. use it up and you have no brakes!) and any other idiotic things that I can think up.

 

I had wanted to put a couple of three analogue meters on the thing, but I am balking at what the suppliers want for these things... I will probably settle for a couple or three 10 segment bar graphs.  The biggest issue is pin count.  I started to think about using latches with the bar displays but in the end decided that it was probably cheaper to use a second microcontroller.  ATMel does have a 40pin (dip) one that has 32 usable IO pins.  It might do the job, but it would have to wait until the finances will support an order to digikey again.... (need I say that they really like me there <G>).  I do have 3 of the 28 pin versions - I could use one of those to emulate a latch.  - it would be cheaper than buying the latches!

Lot's of things to try out - and not enough time to do it in... Only nine years left to retirement!

 

Villy 

 

 

 

 

  • Member since
    September 2003
  • From: NJ
  • 414 posts
Posted by jackn2mpu on Friday, February 23, 2007 1:09 PM

Villy:

As to the problem of room light (whether by sunlight or man-made), it's not a problem when using a narrow band emitter and detector setup. That's what I used for detection some years back on one of my HO layouts. I just ran a straight dc signal, no 38KHz or other frequency stuff. Why complicate things? Some amplification stages and TTL logic, and it worked a charm.

As for detecting cars/trains between detectors, why not have the emitter shine across the rail diagonally to the sensor farther down the line? Should work okay on straight track. I seem to remember someone doing that in a recent model mag, can't remember which one. 

Ex aerospace engineer here (BSEE).

de N2MPU Jack

Proud NRA Life Member and supporter of the 2nd. Amendment

God, guns, and rock and roll!

Modeling the NYC/NYNH&H in HO and CPRail/D&H in N

  • Member since
    November 2006
  • 61 posts
Posted by Villy on Friday, February 23, 2007 2:16 PM

Jack :

 Any CW signal emitted by a IR emitter is going to be subject to washout by sunlight or roomlight.  In order for it not to occur, you would have to either pick a frequency that is not present in ambient light - or use some sort of anl that would cause the rx to ignore the ambient signal.  As you are well aware, this works great when using fm, but I would classify it as only marginally effective when using am, cw or ssb.  I think that we could equate non-modulated ir with cw.  The standard IR detectors worked most of the time - except that I had to shield them quite carefully from direct sunlight.  I tried a 38khz ir signal - but that doesn't really work because most of the rx for this will ignore a continous 38 khz ir signal - which is good (my compact florescent lamp generates enough iri (infrared interference) to trigger the ir rcvrs until the agc kicks in).  So the end result was to go with a 38 khz ir signal with some intelligence on it - random 0s and 1s and then checking for that result on the rcvr.  I had started to do it with TTL and linears - 5x the component count and more money.... (rough guess - I gave up on that approach after the 4th ssi cmos chip).

I built a cmos based controller for the first ATV repeater in Edmonton Alberta back in the late 70's.  Three or four timers (it also server as an audio only repeater), a diode programmable IDer etc.  It would have been an awful lot easier with a microcontroller.  (The total part cost is only about $7 - and a significant part of that is for the connectors!).  My first effort in that area was for the first FM repeater in Thunder Bay Ontario - VE3YQT.  The was in the early 70's and used TTL - CMOS was so much cooler....

I got out of the hardware side years ago - mostly IT security these days - that's good because it is getting harder and harder for my eyes to focus on the tiny things that we are using these days.

Octal tube sockets were a lot more visible than an 8 pin bug (and lets not even go there for the SM stuff on 50 thou centres!)

 

Villy  - VE6SQ

 

 

  • Member since
    September 2003
  • From: NJ
  • 414 posts
Posted by jackn2mpu on Friday, February 23, 2007 2:57 PM

Villy:

Cool - another ham here. I work mostly VHF/UHF now, with HF just coming available as of today to this Codeless Tech courtesy of the FCC. But will always be a VHF/UHF man at heart.

I was just posting what worked for me. IIRC, the light wavelength I worked with was 420nM, matched transmitter/receiver pairs from Digi-Key back in the early 80's. And all my breadboarding was done in daylight, or what passed for such in the lab I worked in at RCA Astro (lunch time project). Maybe I got lucky. The only problem I had with the system was with lightning flashes that came through the windows at work. Would drive my system batty. Worked fine at home. I also fashioned waveguides, if you will, to limit the encroachment of light from the sides.

de N2MPU Jack

Proud NRA Life Member and supporter of the 2nd. Amendment

God, guns, and rock and roll!

Modeling the NYC/NYNH&H in HO and CPRail/D&H in N

  • Member since
    November 2006
  • 61 posts
Posted by Villy on Saturday, February 24, 2007 2:07 PM

Jack

 

I think that you put your finger on it.  The "waveguides" and probably running a lot more power to your LEDs than I was.  More power is always better - and of course the peak power of the lightning bolts would be far far greater than anything you could afford <G>.   The other point of course is how technology has changed.  Another project I was thinking about led me to think about using some data latches.  A little more thought and research led me to the conclusion that it was cheaper and simpler to just use a second micro.

I programmed a linear feedback shift register into a micro.  If I had bought the cheapest micro it would have cost me less than $1.50. (the ones I have cost me $2.50).  The noise chip that I was looking for has been out of production for over a decade - and cost over $7.00 when it was still available.  (I was trying for some steam sounds - it may still work, but it's not high on my list of priorities right now!!

 

Villy 

  • Member since
    September 2003
  • From: NJ
  • 414 posts
Posted by jackn2mpu on Sunday, February 25, 2007 6:13 AM
 Villy wrote:

Jack

 

I think that you put your finger on it.  The "waveguides" and probably running a lot more power to your LEDs than I was.  More power is always better - and of course the peak power of the lightning bolts would be far far greater than anything you could afford <G>.   The other point of course is how technology has changed.  Another project I was thinking about led me to think about using some data latches.  A little more thought and research led me to the conclusion that it was cheaper and simpler to just use a second micro.

I programmed a linear feedback shift register into a micro.  If I had bought the cheapest micro it would have cost me less than $1.50. (the ones I have cost me $2.50).  The noise chip that I was looking for has been out of production for over a decade - and cost over $7.00 when it was still available.  (I was trying for some steam sounds - it may still work, but it's not high on my list of priorities right now!!

 

Villy 

Exactly - ran the leds at max power and multi-stage amplification to comparators on the receiving end to turn the signal to TTL level. I used LM2311 comparators which are open collector, so I could just as easily use TTL or CMOS.

I could use micros, and I have the programming chops, but going my route with discrete parts is quicker and easier for me. Money is not a problem.

As to your sound chip problem, you might want to look at using the chip that was in the old Commodore 64 (and maybe the 128 as well) computers. I know the machines and the chips haven't been around for awhile, but you might be able to pick up something on eBay or at a hamfest. I know it's a bit cold for hamfests right now, at least the outside ones, but keep your eyes open. 

de N2MPU Jack

Proud NRA Life Member and supporter of the 2nd. Amendment

God, guns, and rock and roll!

Modeling the NYC/NYNH&H in HO and CPRail/D&H in N

  • Member since
    November 2006
  • 61 posts
Posted by Villy on Sunday, February 25, 2007 9:36 AM

Jack

you realize of course, that our entire conversation boils down to a discussion of an old Amateur Radio argument..  Bottom line is of course - what works for you works - and what works for me works!!

I don't think that I ever had so much fun as I did as a teenager - with a 40M inverted Vee on the roof, using a mostly homebrew transmitter - most of which I had to rewire to cut down the TVI (I think that every stage in it had pretensions of being an oscillator).  Working Europe on CW was just such a rush (we were living in Northern Ontario at the time). I had to work hard to get Europe, and working Australia on 15 was even more of a rush. 

My current super duper Kenwood TS-8xx something or other  probably doesn't have 50 hours on it. - It just isn't as much fun any more...

I think in my case operating a layout isn't the point - the point is getting the layout to the point where it is workable - with as much in the way of homebrew and home designed techno stuff as is reasonable (and reasonable isn't necessary important!) is the point...

Thankfully - as Amateur Radio does,  this hobby has lots of room for all sorts of addictions! <G>

 

Villy 

 

 

 

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!