Shop OBEX P1 Docs P2 Docs Learn Events
Trying to get IR sensors to work on sumo bot — Parallax Forums

Trying to get IR sensors to work on sumo bot

UncandayUncanday Posts: 28
edited 2007-05-18 06:08 in Robotics
Hello everybody....

I have a rather basic newbie question:

I'm trying to get IR sensors working on a sumobot (a few days old...) and am having serious difficulty with range. Not sure what to try next, so I thought I'd ask for suggestions.

I have two standard setup IR emitters/detectors at the front, running simple code and with two LEDs hooked up on the breadboard to give a "detect" indication for each of the sensors.

Everything kind of works, except that the range is limited to about 5 to 10 cm. No matter what I try, I can't detect anything further out than that. Any ideas? Has anybody run into this before?

Many thanks in advance for any suggestions

Regards
Duncan

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-15 05:43
    If you haven't already, download the tutorial "IR Remote for the Boe-Bot robot". I think it discusses range issues. The power output of the LED depends partly on the current through it and that depends on the series resistor used. The Stamp pins can handle currents up to about 20ma. That would involve a series resistor of about 220 ohms. I'll bet the series resistor you're using is quite a bit larger which will limit the current. Try first something like 470 ohms which will give a current of about 10ma. If you don't like that range, try 330 ohms next, then 220 ohms. Somewhere along there you will get the kind of range you want. Part of the reason for the lesser range is that it's often used to detect drop-offs and will do so quite well. If you increase the range a lot, you will lose the ability to discriminate at short range. It's like trying to make out contrast in a very bright light ... things get washed out.
  • UncandayUncanday Posts: 28
    edited 2007-05-15 07:03
    Mike,
    thanks - I'll go and find the tutorial and see if I can work something out.

    In the meantime, I've been experimenting with a few setups...

    The LED is actually driven via a 220 ohm SM resistor on the board, but I've been using the breadboard to try out a few alternate configurations. I tried going lower than 220, and then tried driving indirectly using an NPN transistor with a 1k base resistor and various combinations of current limiting resistors (including none).

    In the brightest setup, I get intermittent reflections off extraneous objects a long distance away, but I don't get much reflection from a target object (such as another sumobot...). I guess this is going to require a lot of tinkering to get right.

    Regards
    Duncan
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2007-05-15 17:01
    Hello Uncanday,

    When you say "the brightest setup" it makes me just wonder if you are possibly using visible-light red LEDS or the IR LEDs, not likely but I had to ask!

    Are you using the SumoBot Competition Kit?· If not, you might want to check out "Applied Robotics with the SumoBot" Chapter 3 on sensor management, which covers testing and tuning the IR detectors.· You can download it here:

    http://www.parallax.com/detail.asp?product_id=27403

    Try tuning your detectors against white paper or a wall first.·Since the resistor values are fixed when using the front sockets, tuning means·pulsing the IR LED at different frequencies - adjusting the FREQOUT command's freq1 argument -·until you find the frequency at which the IR receiver is most sensitive.· If you are also using a second set on the sides, you can tune the circuits by adjusting both the IRLED frequency and the resistor value.·

    Even when you know you have the IR detection working well in the range you want with white paper, the SumoBots will still be hard to see - they are designed that way, and·that is part of what makes the matches challenging and unpredictable.

    (IR Remote for the Boe-Bot is a different topic - it details how to use a BS2 and IR reciever on a Boe-Bot·to decode a universal remote with Sony protocol, so you can remotely drive the Boe-Bot via the keypad or switch program modes.· Just for fun, you can set up a SumoBot this way, and try to manually beat a SumoBot with autonomous programming.)

    Let us know how it goes,



    -Stephanie Lindsay

    Editor, Parallax Inc.
  • UncandayUncanday Posts: 28
    edited 2007-05-15 17:57
    Steph,
    thanks for the follow up.

    Just to be clear, yes, I'm using IR LEDs. I wasn't intending to imply that I could actually see the output when I referred to "brightness", I'm just inferring the brightness from the power I'm dumping into it using various setups [noparse];)[/noparse]

    And yes, I am using the Sumo competition kit. I did try doing a frequency tuning using a short program I wrote for the purpose. I'm posting from work right now so I don't have the code to hand, but I'll clean it up and post it this evening. Basically what it does is run a test using a single detector for a few seconds at a time, stepping through a sequence of frequencies. One LED is driven to indicate detection, and the other flashes briefly to indicate each stepping point. I can then use a white index card as a target and find the range limit at each step. It works ok, but needs a little refinement...

    As I said, I'll post later when I'm back at home

    Regards
    Duncan
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2007-05-15 18:03
    It sounds like you are on the right track then Duncan - that setup should give you what you need to know.··I figured there was a very, very small chance you were using the red LEDs but it has happened before so I had to ask!·
  • UncandayUncanday Posts: 28
    edited 2007-05-16 15:57
    here's my test code, minus declarations at the top of the file for brevity (which I assume will be obvious). All it does is step through a range of frequencies and allows you to do a range test for a few seconds on each. The four seconds the you have on each step is just enough to move a white 4x 6 index card around and write down the result (I set up the bot on a surface next to a ruler so I can just read off the distances)

    ' boot up warning
      HIGH LED0
      PAUSE 2000
      LOW LED0
    
      '-------------------------------------------------
      '
      ' Main loop - step through frequencies in the
      ' range 37kHz to 40kHz in steps of 200Hz
      ' Modify as necessary
      '
      '-------------------------------------------------
      FOR  fstep = 0 TO 10
    
        ' calculate the frequency we're using
        freq = 37000 + (fstep * 200)
    
        ' 200 iterations gives you about 4 seconds on each
        ' step
        FOR iter = 1 TO 200
    
          ' read sensor, display result
          FREQOUT RtIrOut, 1, freq
          irRight = ~RtIrIn
    
          IF irRight = 1 THEN
            HIGH LED1
          ELSE
            LOW LED1
          ENDIF
    
          PAUSE 20
    
        NEXT
    
        ' make sure we extinguish the LED
        LOW LED1
    
        ' indicate that we're starting the next step
        HIGH LED0
        PAUSE 200
        LOW LED0
    
      NEXT
    
    
  • UncandayUncanday Posts: 28
    edited 2007-05-17 01:47
    ...and here's some results. There's clearly a pattern here, which I think has something to do with the way the waveforms are generated. The pattern is repeatable, by the way - each of these traces is an average of 3 runs, and all of the runs looked very similar. (Range is shown in cm)

    The "high power" setup is driving the LED via a transistor hanging off the port, whereas the "normal configuration" is just plugged into the socket at the front. Doesn't seem to make much difference.

    Looking at the waveforms on an oscilloscope, I'm thinking that at 38kHz or so, the capabilities of the "FREQOUT" routine are being exceeded, and that may be an important factor here (I'm pretty sure it explains the shape of the graph). As a result, I was contemplating using a 555 timer to generate the 38kHz signal instead.

    Before I do that, though, I wanted to know if what I'm seeing is actually typical or is there something wrong with my setup? Maximum detection range I've seen for a 4x6 white index card is about 23cm.

    Many thanks in advance for any suggestions...

    Regards
    Duncan
    907 x 621 - 8K
  • UncandayUncanday Posts: 28
    edited 2007-05-17 03:00
    brief additional...

    I didn't have a 555 lying around, but I did have a 741 which I used to build a relaxation oscillator at around 38kHz (with a trimpot for tuning). After a tune up, I can now detect with that setup a 4x6 index card at ~30cm. Another sumobot at maybe ~20cm or so, heavily dependent on which way it's facing. It looks like there's definitely some mileage in using an external oscillator

    Regards
    Duncan
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2007-05-17 19:18
    Hi Uncanday,

    Sorry for the recent silence on your thread -··Andy Lindsay is really the best person to go into this·depth on the subject.· He is away teaching a Parallax Educators course for a couple days, but I will give him a heads-up when·he returns.

    Typically you can get reliable distance detection of a white wall with the typical setup with a max range of about 30-45 cm, less if you are trying to spot a SumoBot.

    If you want to try an alternative setup, you might read this thread from the Stamps in Class Mini-Projects sticky.· It might not increase your range but it will improve resolution, and it might give some insight for alternative designs:

    http://forums.parallax.com/showthread.php?p=561496

    -Stephanie Lindsay

    Editor, Parallax Inc.
  • UncandayUncanday Posts: 28
    edited 2007-05-18 04:15
    Steph,
    thanks for the info - that helps. With the standard setup, I can detect a mirror from over half a meter away, and a white 4x6 index card from max 23cm. That may well translate into detecting a white wall at 35cm or so (I don't happen to have such an item available wink.gif).

    I just bought a couple of 556 dual timers which I'm planning to use to generate cleaner squarewaves to see if I can extend the range a bit more. I'll also look at the power modulation as explained in the article you referenced. Right now, though, the main issue seems to be increasing detection range, so I'll stick to working on that first


    Regards
    Duncan
  • edited 2007-05-18 04:29
    For the time being, just a quick remote comment. If the oscillator is driving common IR LED anodes, the program should only set one cathod end of an LED circuit to output-low at a time. This will make it possible to be sure which IR LED "flashlight" caused the object detection. More when I get back to the office and examine the sumobot components more closely.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
  • UncandayUncanday Posts: 28
    edited 2007-05-18 06:08
    Andy,
    thanks for the suggestions. I had realized that I needed to only power one LED at a time, but the method of using the digital outputs on each of the cathodes and making the anodes common hadn't occurred to me. That works really well.

    Anyway, another hour or so of tinkering...

    I got the 555 oscillator working, and managed to get another 50% range just about. I also had lots of issues with spurious triggering, which I found to be due to EM coupling from the oscillator circuit itself. It turns out to be important to use a decoupling capacitor across the supply. I guess that since I'm generating a full depth square wave I should have expected that.

    One more thing I found useful is to make the detection stateful, since at the edge of range detection is intermittent. I'm observing it with an LED to indicate the output. This is what I used to test it, and it seems to make a substantial difference:

    DO
    
          irRight = ~RtIrIn
    
          IF irRight = 1 THEN
            IF lDetect < 30 THEN lDetect = lDetect + 4
          ELSE
            IF lDetect > 0 THEN lDetect = lDetect - 1
          ENDIF
          IF lDetect > 6 THEN
            HIGH LED1
          ELSE
            LOW LED1
          ENDIF
    
          PAUSE 20
    
        LOOP
    
    



    (this is just testing one sensor, with the LED powered continuously)
Sign In or Register to comment.