Need help programing Sparp IR for finding range

Hello i’m still a noob at the BASIC Bot Board and 28 pin chip (not pro).
I really don’t know were to start when trying to program to find range. The range is ~1" to 12" and the sensor is against a flat pieace of aluminum and will all ways be directly in front of it (no angles). The sensor will be used as a positioning thing for a servo in my robot.

Could someone post some code that you know works or give some links to where i could find some? I read a bit about using this sensor as a range sensor and theres a little math involved, so im guessing that the program is somewhat sphisticated.

Thanks!

Bane[/list]

Sharp makes a lot of IR sensors, which one are you referring to?

Sharp GP2D12 IR Sensor

my bad :confused:

bane

Ive had a similar problem and learned that, the ADIN command is a good way to find range. Also, the DEBUG command, will send the program to your debug window when you click run.
for example,

something var byte

main
    ADIN 19, something
    debug [DEC something,19]
    pause 500
goto main

if you put this in your IDE and click debug, and then the ‘run’ icon you will see numerical values start to appear in the window. The farther away an object is, the lower the number will be. After that, you can use an IF, THEN command to control the servo, for example,

if something > 200 then
gosub "this is where you put your subroutine to control the servo."
endif

Here’s some info on the GP2D12

maslab.csail.mit.edu/2002/wiki/S … D12_E.html

I’ve implemented two of them on my 'bot. ‘C’ code, 'tho.

Alan KM6VV