Shop OBEX P1 Docs P2 Docs Learn Events
Distance sensor GP2D02 — Parallax Forums

Distance sensor GP2D02

DrewDrew Posts: 9
edited 2004-11-27 19:59 in BASIC Stamp
I have made some progress constructing a minesweeping robot, but ive ran into a wall and cant detect the problem, lol.

I cant get my distance sensors to work. Im using this example promixity code, but i get nothing. it either says 'object detected' or 'object not detected'. no matter if an object is their or not.

here is my code:


IR_detect VAR Bit
LOW 14

loop:

IR_detect = IN15
IF IR_detect = 0 THEN not_detected

DEBUG HOME, "Output is high, no object detected."
GOTO loop

not_detected:

' This time, add a space to the end of this debug
' command. This will keep both strings the same
' length and make the display better.

DEBUG HOME, "Output is low, object is detected. "
GOTO loop


Where might i be going wrong?

Regards,

Andrew

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-11-25 00:34
    Drew -

    Presuming you're using the Sharp GP2D02 as the subject line of this post would indicate, you will need to modify your program quite a bit. The GP2D02 is a digital device, not an analog one. As such you will need to use SHIFTIN to retrieve the distance sensed. Here is a web page with all the details, including a link to some sample code for the Stamp BS-II near the end of that web page:
    http://www.acroname.com/robotics/parts/R19-IR02.html

    Here is the link to the sample code, in case you miss it:
    http://www.acroname.com/robotics/info/examples/GP2D02-4/GP2D02-4.html

    You may have been confusing this GP2D02 sensor with the GP2D05 which has a distance theshold you can set manually, and then obtain a pass-fail (logic 0 or 1) result. Your program would indicate it was expecting a pass-fail result, rather than an actual distance.

    Regards,

    Bruce Bates
  • DrewDrew Posts: 9
    edited 2004-11-25 03:35
    Bruce,

    Thank you very much for that link. I tried the sample code and it worked! Im lost on how i might modify that code so it would enable to detect an object within a range of 2 to 5 cm's?

    Any ideas would be great.


    Thanks,

    Andrew
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-11-25 04:39
    Andrew -

    That is awfully close for any of the Sharp I/R Rangefinders. The GPD2D120 will come in as close as 4 cm but that the closest any of them will sense. If that will work for you, here is a link to that sensor:
    http://www.acroname.com/robotics/parts/R146-GP2D120.html

    Why do you feel you need to sense such a close distance? That is well within the range of mechanical "whiskers", which would probably be a lot cheaper in the long run. At worst, you're talking one or two micro-switches and a feeler or bumper wire.

    Regards,

    Bruce Bates
  • DrewDrew Posts: 9
    edited 2004-11-25 21:08
    Bruce -

    I should correct myself, I need it to detect objects at a distance of 10 cms. I believe the specs allow between 10 - 80 cm. Im unsure how i could incorporate SHIFTIN commands to do this.

    Thank you again,

    Drew
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-11-26 01:44
    Drew -

    Presuming you have the sample program (GP2D02.BS2), the SHIFTIN is already being done in a subroutine ( read02: ) near the end of the program. One byte (8 bits) of data is read in from the sensor and stored in a variable named "val02". After the execution of the SHIFTIN the variable val02 will now contain the distance in centimeters of any object it "sees" within the limits indicated in the GP2D02 data sheet.

    Presently the sample program is set up to take 100 successive readings and display those results on the DEBUG terminal. I've no idea where you want to go from there. If this doesn't answer your question, please restate the question differently.

    Regards,

    Bruce Bates
  • LarryLarry Posts: 212
    edited 2004-11-26 05:30
    The trouble with the Sharp sensors is that the output of the sensors peaks at about 4 inches and falls off in either direction, so you can't realy tell if the object is inside or outside of that range.

    It might be a good idea to use a diferent sensor as well to help make that judgement. I suggest you try The IS471 sensor to help with that determination. It will detect objects out to about a 5" range. In fact, depending on what exactly you are trying to detect, it could be used by itself. Just be aware that it is a proximity, not a range sensor.

    Bruce has a point that to get better help, you need to define better what it is you are trying to do.

    find info on the IS471 at www.junun.org

    Larry

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • DrewDrew Posts: 9
    edited 2004-11-27 19:59
    I fixed my problem. You gentlemen are great!

    Thank you very much for both of your help!

    Andrew
Sign In or Register to comment.