Sharp GP2D120XJ00F Analog Distance Sensor
chriswu
Posts: 2
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:
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?
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
You need a analog to digital converter (ADC) to pull this off.
It goes between the sensor output and the/a Stamp input.
No ADC, no RCTIME.
How's that?
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.
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