Shop OBEX P1 Docs P2 Docs Learn Events
Sharp GP2D120XJ00F Analog Distance Sensor — Parallax Forums

Sharp GP2D120XJ00F Analog Distance Sensor

chriswuchriswu Posts: 2
edited 2011-08-01 19:05 in Accessories
I have a question about the Sharp analog sensor. I am working on a project which needs to be able to differentiate between different distances through an analog input. However, when I plugged in the sensor to my Basic Stamp 2, I got a digital input like this:
digitalio.png


This is the code I entered:

' {$STAMP BS2}
' {$PBASIC 2.5}

'IN15.......Sensor I/O

DO
DEBUG HOME, ? IN15
PAUSE 20
LOOP

How can I read the analog sensor value? Is there a way to read it without wiring an RCTIME circuit or an adc?

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-08-01 16:00
    Yes, it's the analog sensor; the Stamp has no "analog in" pin.
    You need a analog to digital converter (ADC) to pull this off.
    It goes between the sensor output and the/a Stamp input.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-08-01 16:02
    It's possible that you could use a comparator (quad comparator) and establish several thresholds and monitor them.
    No ADC, no RCTIME.
    How's that?
  • chriswuchriswu Posts: 2
    edited 2011-08-01 17:57
    With thresholds, I assume I would lose my capability to moniter the specific value from the sensor, and instead get a ballpark idea? Also, an observation I had when testing the sensor was that the sensor gave a detect signal around 4 cm. The sensor is supposed to sense distances from 4-30 cm in analog form, so one would think that the detect signal would come around 30 cm. Any idea how this happens?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-08-01 18:53
    Yes, none of the Stamps or the Propeller has an "analog in" pin like the PICaxe and the "open source" products.

    Your sensor output varies with the distance to the subject, the closer the subject the greater the output voltage.
    There's an output voltage when objects are too close (< 4cm), too.

    So, you could use one comparator to know that it's at least "x".
    With two comparators you could configure a "window comparator" and establish that the subject is between "x" and "y".
    Or you could make several overlapping "window comparators".
    Or you could have a series of comparators with gradually increasing thresholds and make an ADC on the cheap (much like a bar-graph display.)
    It depends on what you need.

    If you require the range, all points in between, then you'll have to use an ADC if you're going to use a Stamp.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-08-01 19:05
    PJ,

    The MoBoStamp-pe -- technically a BASIC Stamp, but without the 24-pin form factor -- has four 10-bit analog input channels. The Propeller Backpack has two sigma-delta ADC channels, and there's an object available to use them. The Propeller QuickStart board also has provisions onboard for sigma-delta ADC.

    -Phil
Sign In or Register to comment.