Shop OBEX P1 Docs P2 Docs Learn Events
Infaread LED & Detector System — Parallax Forums

Infaread LED & Detector System

Roy CarlsonRoy Carlson Posts: 46
edited 2007-10-30 16:35 in General Discussion
I have a home project where I will need to detect 8 sections of my model railroad hidden stagging tracks to make sure there isn't a train blocking the turnout at each section.· If the section is blocked I want to light a LED on the panel display so that I would know to move the train on that section of track.

Can I use the SX28 Proto Board·to send and read the INFR LED pulses to 8 separate detector sections and then turn on a separate section of 8 standard RED LEDS or do I need other chips to help keep the current drain within range?

I have thought about using the Piezo Vibra Tab·under the sections of track instead of the across the track IFR beams but was concerned about false indications due to vibrations of trains on neighboring tracks.

I didn't want to go the current drain indicator route that most model railroad layouts use as I use DCC in N Scale and wanted clean track power throughout the layout.

I think I can use the infaRed detectors for the hidden section as they are not visible from the layout and I don't have to worry about various room lighting conditions.· A simple blocked section of track by any part of the train would light the red LED to indicate the blocked section.

I would welcome any suggestions from those in the know as I have found reading post on this site a true education that could never be learned via books or schooling.

Roy

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


·

Comments

  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-10-26 19:02
    The SX28 should be able to easily handle the task you describe except possibly for driving the IR emitters directly. However, if class N trains are as small as I think they are, the SX can probably drive the emitters directly.

    What you are describing can probably be done fairly easily without a microcontroller at all! A 555 could modulate the IR emitters while 8 modulated IR detectors look for reflections (or loss of signal) caused by the presence of a train.

    - Sparks
  • Roy CarlsonRoy Carlson Posts: 46
    edited 2007-10-26 20:59
    Sparks,

    I like your idea but I am clueless as to how to go about doing this on a breadboard.· I could probably figure out how to set up the 555 chip but would I need a 555 clock for each of the 8 Infred LED emmitters or do I drive them all with the same 555 hz signal?

    If this can be done, then how do I wire up the 8 detectors such that when the infared beam is broken/blocked, I can light a remote LED to indicate the blocked section of track?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    ·
  • ZootZoot Posts: 2,227
    edited 2007-10-27 21:04
    If you use an external 555 will you will still need to gate the output from the 555 with, say, a NAND so you can select which LED is emitting. If all the LEDs are far apart, you could run them all at once.

    But you can easily use the SX interrupt to run IR emitters (multiples at different times). In SX/B your interrupt would be something like:

    INTERRUPT 77_000 ' 38_500 hz * 2

    And the Interrupt handler just switches a pin on and off:

    Interrupt_Handler:
    IRledPin = ~IRledPin
    RETURNINT

    You can wire the output of that pin to all your IR LED anodes, then tie each IR cathode individually through a resistor to a different SX pin. Which ever cathode pin is LOW rather than HIGH or INPUT, will light that IR led with the 38_500hz frequency. Then read a corresponding input pin for that detector OR just tie the detector outputs to your display LEDs.

    The trick on the SX with the former approach is pins -- if you use, say, RA.3 for the 38_500hz output, and RB for 8 IR leds, and RC for 8 detectors, that only leaves with you 3 pins on SX28. With shift register(s) on those 3 pins you could run lots of display LEDs. Or get the SX48 protoboard (www.parallax.com/detail.asp?product_id=45300) which has another 2 ports.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • John CoutureJohn Couture Posts: 370
    edited 2007-10-28 00:48
    Could you modulate all of the IR LED's off of one source and then have the SX read each detector in a round robin fashion for say 100ms. It would take less than 1 second to check all of your track sections. As for the number of pins, how an 8 to 1 chip for input and an 1 to 8 for output RED signals. That way you would use only 8 pins total (4 in, 4 out). Or did I miss something obvious smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • ZootZoot Posts: 2,227
    edited 2007-10-28 01:39
    said...
    Could you modulate all of the IR LED's off of one source and then have the SX read each detector in a round robin fashion for say 100ms.

    Totally. Yes. Actually you don't even need 100ms. <1ms per LED and detector would do it. And that way you are not flooding your layout with IR when it's not needed.
    said...
    how an 8 to 1 chip for input and an 1 to 8 for output RED signals. That way you would use only 8 pins total (4 in, 4 out). Or did I miss something obvious

    Yeah, if you need more display LEDs or whatnot. If shift registers are used for LEDs, only 4 pins would be needed -- data, clock, and two CS lines (one for each bank of 8 leds, whether IR or display). But that said, at $10, an SX48 protoboard would provide plenty of pins so almost almost no external parts (except resistors) would be necessary and it has the regulator and connectors and stuff already built on.

    Regardless, say you have the modulated 38.5khz coming out one pin, then 8 pins for IR leds and 8 pins for detectors (just to pick round numbers). You only need to have one IR led on at time, which will keep current draw through the SX down, plus not give you IR "echos" and noise. Rough code might be something like this:

    IRledPin PIN RA.3 'to all anodes
    IRleds PIN RB 'to individual cathodes
    IRdets PIN RC 'to detectors
    displayLeds PIN RD '8 pretty lights -- this could also be replaced with shiftout code to a shift register and just use 3 pins to get 8 pretty lights
    
    IRcount VAR Byte 'which led/detector pair now?
    IRmask VAR Byte 'mask for detector/led pins
    IRbits VAR Byte 'stored results
    tmp VAR Byte 'work var
    
    'interrupt
    INTERRUPT 77_000
    IRledPin = ~IRledPin
    RETURNINT
    
    'main program
    Main:
    IRmask = %0000_0001 'start with RB.0/RC.0
    IRbits = %0000_0000 'clear irbits
    FOR IRcount = 0 TO 7 'loop through IRled/detector pairs
       IRleds = ~IRmask  'remember you want this IRled's cathode pin to go LOW when that LED is activated
       PAUSEUS 750 'wait .75ms -- probably don't even need this much
       tmp = IRdets
       tmp = tmp & IRmask  ' mask of just this pair's detector -- will be LOW if detection
       IRbits = IRbits | tmp  ' save to bits
       IRmask = IRmask << 1 'next pair
    NEXT
    IRleds = %1111_1111 'turn LEDs off (high) or set TRIS to inputs for this port, which would save juice
    IRbits = ~IRbits 'invert so that 1 in a bit position means DETECTED, 0 means NOT detected
    displayLeds = IRbits 'copy to display to see pretty lights
    IF IRbits = %0000_0001 THEN
      'more fun code if ONLY detector 1 triggered
    ELSEIF IRbits = %0000_0010 THEN
      'more fun code if ONLY detector 2 triggered
    ENDIF
      'etc
    
    GOTO Main
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    Post Edited (Zoot) : 10/28/2007 1:49:33 AM GMT
  • John CoutureJohn Couture Posts: 370
    edited 2007-10-28 17:39
    (grin)

    Good point. An SX48 board does have plenty of ports. ... I knew I was missing something obvious!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-10-29 20:29
    Roy Carlson said...
    Sparks,

    I like your idea but I am clueless as to how to go about doing this on a breadboard. I could probably figure out how to set up the 555 chip but would I need a 555 clock for each of the 8 Infred LED emmitters or do I drive them all with the same 555 hz signal?

    If this can be done, then how do I wire up the 8 detectors such that when the infared beam is broken/blocked, I can light a remote LED to indicate the blocked section of track?
    My thought was to detect the presence of trains using modulated IR light in a manner similar to what is commonly used as a means of obstacle sensing for mobile robots. Whether or not you can drive all of the emitters from an unbuffered 555 or SX is dependant upon how much current you need to send through them. It may not need to be much since you will not need the IR beam to shine very far. Driving all of them with a transistor from the same signal source is certainly doable.

    I envision the detection being done by a modulated IR sensor. It outputs a digital high or low signal depending on whether or not it is detecting an IR modulated signal source. You could either place an emitter on one side of the track and a detector on the other side of the track to detect a train blocking the beam path or else place them on the same side of the track to detect the beam being reflected by the presence of a train. You should be able to dim the emitters by reducing the current flowing through them to achieve the sensitivity required without falsely triggering other detectors nearby. Some light shielding might help to narrow the emitted beans the detector’s view as well.

    It is just an idea but I know that this detection scheme is used quite often on mobile robots for object detection.

    - Sparks
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-10-29 20:59
    Hello,

    You might want to experiment a bit on the sensors you use for the detectors. Although using a modulated signal can make detection more accurate and can eliminate false triggers from ambient light it may not be needed for your application. In many cases you can just use some of the reflective sensors as is. Some simple ones are the QRB1114 and QRD1114 parts. A small current limit resistor ~ 330ohm on the IR led is common. Just use two I/O pins for each sensor. One to turn it on and the other as the sense pin. You can still cycle through them and turn on each one at a time so they don't interfere with the other sensors. If you have a bunch you could use something like the 74hc138 so that 3 lines select the 8 and only one is active at a time to tell which one to turn on.

    I've seen more of the modulated IR for object avoidance, etc but usually don't see modulated IR when used in encoders or sensors for a home position. If you don't need to modulate the light is makes it much easier to put together.

    Another factor may be the color on the bottom of the trains. You may need to attach a reflective strip on the bottom to help with detection. If possible setup a small test track with some of the sensors to test your circuit and program.

    With a few more sensors scattered about you could probably calculate scale speed and automate things a bit.

    Have Fun,

    Robert
  • Roy CarlsonRoy Carlson Posts: 46
    edited 2007-10-30 16:35
    Thanks Robert,

    I ordered one of th QRD1114's to test out. If it works on the N-Scale layout (distance between railroad ties and bottom of engine then this would be better than an across the track method. If I can pulse and read each set via pairs then there shouldn't be a problem reading false infrared.

    I have 4 lengths of track with need detectors on each end so I could use something that woud pulse and read a pair on each end then move to the next pair this way all tracks could be read and I would only need a 2 byte variables to set the pulse and reads.

    What do you think about?

    L1p L2p L3p L4p R1p R2p R3p R4p = Pulse Out Left & Right Track 1
    0 0 0 1 0 0 0 1

    L1d L2d L3d L4d R1d R2d R3d R4d = Detect Pulse Left & Right Track 1
    0 0 0 1 0 0 0 0

    If I can work out the binary bits I could use a simple for x = 1 to 4 next x with some multiplyer to set the pair of bits for the pulse and detects

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    ·
Sign In or Register to comment.