Shop OBEX P1 Docs P2 Docs Learn Events
Range on IR Object Detectors — Parallax Forums

Range on IR Object Detectors

BootsyBootsy Posts: 22
edited 2010-02-08 22:28 in BASIC Stamp
Hello all!
I'm working on building a small, autonomous robot capable of detecting objects. It moves quite quickly, so I'd like it to be able to "see" objects about a meter away, so it can do a graceful turn rather than smashing into it, backing up and trying again : ). However, using the IR LED and Detector setup, I haven't been able to get a range of more than about twenty cm. I've heard of ranges over five feet, how can I achieve that?

Thanks!

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-01-28 05:07
    Sharp IR sensors will range to 80cm and the Ping))) will do more I think.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • BootsyBootsy Posts: 22
    edited 2010-01-28 14:31
    Yeah, but how do I connect them or code them differently to achieve greater range?
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-01-28 14:59
    The 'ping' sensor is good from a few centimeters to 10 feet. 5 feet is quite a distance for IR-reflection -- sound reflection as used by the 'ping' would probably be better, backed up by close detection of IR-reflection.
  • ercoerco Posts: 20,256
    edited 2010-01-28 18:45
    Eleven different IR sensors at http://www.junun.org/MarkIII/Store.jsp (and·five different sonar sensors). I'd love to see a side-by-side comparison of range & features vs price.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • BootsyBootsy Posts: 22
    edited 2010-01-28 21:12
    In the Basic Stamp application notes, they show how to make a serial data transmission through IR with a range of 10 ft. So, IR reflection should be good to slightly less than 5. I've made the circuit and code exactly like in the notes. Has anyone had any success at moderate ranges for IR object detection. I'd rather not use the PING just on a basis of cost and simplicity.
  • ercoerco Posts: 20,256
    edited 2010-01-29 01:16
    Neither traditional IR nor sonar is totally foolproof. An object's size, shape, location, texture, and angular orientation (normal, perpendicular, 45 degrees) will drastically affect the reflection of the IR or ultrasonic signal. You may want to use both on a fast-moving robot to cross-check each other for reliability.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • BootsyBootsy Posts: 22
    edited 2010-01-29 01:20
    True enough, however the 20cm range I have is drastically and unexpectedly different from the approximate 120cm (4 ft) range I should be able to attain. I'm just wondering why and how to fix it.
  • FranklinFranklin Posts: 4,747
    edited 2010-01-29 04:17
    You could start by showing us your circuit your part numbers and attaching your code to a post.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • BootsyBootsy Posts: 22
    edited 2010-01-30 06:13
    Right. Sorry, that would have been a good way to start. I'll have them up soon. It's exactly like what's described in the SumoBot manual; code, circuit and all. You can download the manual from the Parallax product page. Either way, I'll post it soon.
  • CampeckCampeck Posts: 111
    edited 2010-01-30 07:21
    erco said...
    Neither traditional IR nor sonar is totally foolproof. An object's size, shape, location, texture, and angular orientation (normal, perpendicular, 45 degrees) will drastically affect the reflection of the IR or ultrasonic signal. You may want to use both on a fast-moving robot to cross-check each other for reliability.

    Don't forget color for IR!
  • BootsyBootsy Posts: 22
    edited 2010-01-30 15:58
    While I'm putting together my diagram, has anyone tried this sort of detection themselves? If so, what sort of range did you get?
  • BootsyBootsy Posts: 22
    edited 2010-02-05 13:15
    Okay, reverting to good 'ol ascii:

    P1
    (220 O Resistor)
    (IR LED)
    VSS

    P6
    (Detector)
    VSS
    |
    VDD


    And here's the code snippet:
    ' {$STAMP BS2}                               ' Target = BASIC Stamp 2
    ' {$PBASIC 2.5}                              ' Language = PBASIC 2.5
    
    ' -----[noparse][[/noparse] I/O Definitions ]---------------------------------------------------
    
    LMotor     PIN     13                        'Left Motor
    RMotor     PIN     12                        'Right Motor - all wheel commands must be backward for this one only
    
    lpwr       PIN     10                        'Power out to the left QTI
    lin        PIN     9                         'Left QTI in
    rpwr       PIN     7                         'Power out to the right QTI
    rin        PIN     8                         'Right QTI in... Does anyone know what QTI stands for?
    
    IrLedLS    PIN     1                         'Left IR LED
    IrSenseLS  PIN     6                         'Left IR detector
    
    IrLedRS    PIN     2                         'Right IR LED
    IrSenseRS  PIN     5                         'Right IR detector
    
    IrLedB     PIN     0                         'Rear IR LED
    IrSenseB   PIN     3                         'Rear IR detector
    
    irledfl    PIN     4                         'Front Left IR LED
    irsensefl  PIN     11                        'Front Left IR detector
    
    irledfr    PIN     15                        'Front Right IR LED
    irsensefr  PIN     14                        'Front Right IR detector
    
    ' -----[noparse][[/noparse] Constants ]----------------------------------------------------------
    
    IrFreq     CON     38500                     ' IR LED transmit frequency
    
    ' -----[noparse][[/noparse] Variables ]----------------------------------------------------------
    
    IRBits     VAR     Byte                      'State of IRs
    irfl       VAR     IRBits.BIT0               'front left
    irfr       VAR     IRBits.BIT1               'front right
    irls       VAR     IRBits.BIT3               'left side
    irrs       VAR     IRBits.BIT4               'right side
    irb        VAR     IRBits.BIT5               'rear
    irb2       VAR     IRBits.BIT6               'rearv2
    irb3       VAR     IRBits.BIT7               'rearv3!
    
    IRBackupBits VAR   Byte
    irfl2      VAR     IRBackupBits.BIT0
    irfr2      VAR     IRBackupBits.BIT1
    irls2      VAR     IRBackupBits.BIT2
    irrs2      VAR     IRBackupBits.BIT3
    irb4       VAR     IRBackupBits.BIT4
    
    lintense VAR Word
    rintense VAR Word
    lintenseb VAR Bit
    rintenseb VAR Bit
    temp  VAR Word
    cycle VAR Word
    
    ' -----[noparse][[/noparse] Initialization ]-----------------------------------------------------
    
    DEBUG CLS, "IR DETECTORS", CR,               ' Display heading
               "  FL    FR    Left   Right   Back   LLight   RLight", CR,
               "-----  ----   ----   -----   ----   ------   ------", CR
    
    ' -----[noparse][[/noparse] Main Routine ]-------------------------------------------------------
           main:
    FOR temp=1 TO 103
    
      GOSUB checkleft
      GOSUB checkright
      GOSUB checkfleft
      GOSUB checkfright
      GOSUB checkrear
    
      Read_Line_Sensors:
      HIGH LPwr                                 ' activate sensors
      HIGH RPwr
      HIGH LIn                                  ' discharge caps
      HIGH RIn
      PAUSE 1
      RCTIME LIn, 1, lintense                      ' read left sensor
      RCTIME RIn, 1, rintense                      ' read right sensor
      LOW LPwr                                  ' deactivate sensors
      LOW RPwr
    
      LOOKDOWN lintense, >=[noparse][[/noparse]1000, 0], lintenseb           ' 0 = black, 1 = line
      LOOKDOWN rintense, >=[noparse][[/noparse]1000, 0], lintenseb
    
      DEBUG CRSRX, 2, BIN irfl,                 ' Display object detect bits
            CRSRX, 9, BIN irfr,
            CRSRX, 17, BIN irls,
            CRSRX, 23, BIN irrs,
            CRSRX, 32, BIN irb,
            CRSRX, 41, DEC lintenseb,
            CRSRX, 50, DEC rintenseb
    '  IF temp<50         THEN
    '  HIGH rled
    '  ELSE
      IF temp>101        THEN
      temp=1
    '  ENDIF
    '  LOW rled
      ENDIF
    NEXT
    
    checkfleft:                                'Check the front left IR
      FREQOUT IrLedFL, 1, IrFreq
      irfl = ~irsensefl
      IF irfl=1 THEN
        PAUSE 4
        FREQOUT IrLedFL, 1, IrFreq
        irfl2 = ~irsensefl
        IF irfl2=0 THEN : irfl=0 : ENDIF
      ENDIF
    RETURN
    
    checkfright:                               'Check the front right IR
      FREQOUT irledfr, 1, irfreq
      irfr = ~irsensefr
      IF irfr=1 THEN
        PAUSE 4
        FREQOUT IrLedFr, 1, IrFreq
        irfr2 = ~irsensefr
        IF irfr2=0 THEN : irfr=0 : ENDIF
      ENDIF
    RETURN
    
    checkright:                                'Check the right IR
      FREQOUT IrLedRS, 1, IrFreq
      irRS = ~IrSenseRS
      IF irrs=1 THEN
        PAUSE 4
        FREQOUT IrLedRS, 1, IrFreq
        irrs2 = ~irsenseRS
        IF irrs2=0 THEN : irrs=0 : ENDIF
      ENDIF
    RETURN
    
    checkleft:                                 'Check the left IR
      FREQOUT IrLedLS, 1, IrFreq
      irLS = ~IrSenseLS
      IF irls=1 THEN
        PAUSE 4
        FREQOUT IrLedLS, 1, IrFreq
        irls2 = ~irsenseLS
        IF irls2=0 THEN : irls=0 : ENDIF
      ENDIF
    RETURN
    
    checkrear:                               'Check the rear IR
      FREQOUT IrLedB,  1, IrFreq
      irB = ~IrSenseB
      IF irb=1 THEN
        PAUSE 2
        FREQOUT IrLedB, 1, IrFreq
        irB2 = ~irsenseB
        IF irB2=1 THEN
          PAUSE 2
          FREQOUT IRLedB, 1, IrFreq
          irB3 = ~irsenseB
          IF irb3 = 1 THEN
            PAUSE 2
            FREQOUT irledb, 1, IrFreq
            irb4 = ~irsenseB
            IF irb4=0 THEN : irb=0 : ENDIF
          ELSE
            irb=0
          ENDIF
        ELSE
          irb=0
        ENDIF
      ENDIF
    RETURN
    



    I know I don't depict which connection goes to which on the detector, but rest assured that it is connected properly.
  • Rick BrooksRick Brooks Posts: 67
    edited 2010-02-07 12:57
    Bootsy,

    With your setup, you should be able to get about 40cm of range.· Remember that your sensors are looking at reflected IR light and a lot of power is lost in the reflection process.· If you had an ideal target (100% reflected IR) you may be able to get substantially more range.

    I am assuming that you are using PNA4602 sensors and QEC113 IR LEDs.

    Step 1 optimize the frequency.· It is my experience that each IR LED and sensors works best at one frequency.· Do frequency runs for each IR/sensor pair and choose the frequency that gives the maximum reliable range.· This is a time consuming process.· You will notice that the results do not come close to the expected Bell curve that you may be expecting.

    Step 2 switch to the BS2SX.· It is a faster chip and does a much better job of reproducing the 38kHz signal which gives slightly improved results.

    Step 3 increase the power of IR beam generated.· Using a 220 ohm resistor with the IR LED limits the current to 15 ma.· To get more distance, increase current.· Remember that the BS2 pins cannot generate much more current, so use a transistor to increase drive current.· I like to use MOSFETs for this.· In early experiments, I have driven a QEC113 with about an amp of current and have seen two to three meters detected range.· Just keep the total power low (one reading every 15 or 20 msec works) and the QEC113 will survive.· My test setup with 1 amp drive worked for over a week continuously before I got tired of running it.

    One more note, beware of outside IR influence (sun light).· The PNA4602 has built in AGC circuitry that limits sensitivity based on total IR power detected.· When there is a lot of IR, the gain is reduced, so the detected distance is drastically reduced.· Basically, don't run them outside and stay away from windows on bright, sunny days.

    ·· Rick Brooks
  • BootsyBootsy Posts: 22
    edited 2010-02-08 03:43
    Thanks, Rick.

    I was hoping I wasn't at max range already. Those are indeed the parts I am using, I think they're the only ones for sale by Parallax. As much as testing each pair's ideal frequency will be time consuming, I'm hopeful it'll work. Just so it doesn't take days, do you have any recommendation as to low and high ends and steps to go up by?

    Thanks for the tip about outside light, I'll make sure to limit that. I was careful not to aim at windows or other sources because I assumed it would pick it up as a false signal. I didn't realize there was a gain built in for ambient conditions.

    As for inserting a transistor, do you have any recommendations as to part numbers? Also, do I keep a resistor in, or can I chuck it?

    Thank you very much for your helpful response.
  • Rick BrooksRick Brooks Posts: 67
    edited 2010-02-08 22:28
    Bootsy,

    Let the stamp do most of the work for the freq run.

    I normally start out with a range of 36kHz to 42kHz and 100 Hz·steps at about 10 inches distance.· At each frequency, run the freqout ten times (pause about 10 msec between readings) and debug the frequency and number of hits.· You will be looking for tens.· If you get all tens, move the object farther away.· Start limiting the frequency range and reducing length of the steps while moving the object.· After about five or six runs you should be down to 1 Hz steps.··A single (or a few) frequencies normally stand out from the rest.

    Presently I'm using IRFD024 FETs for the IR LED drivers.· They are small and mounted directly beside the IR LEDs.· The FET gate can be driven directly from the Stamp pin.· Use a small resistor to limit currect to the IR LED to whatever level you need.· I use a 15 to 30 ohm resistor dirven by an adjustable voltage regulator.· The sensing range is controlled by the voltage from the regulator.

    ·· Rick Brooks

    Post Edited (Rick Brooks) : 2/9/2010 12:53:33 AM GMT
Sign In or Register to comment.