Let's Make Robots!

How do you program a sharp gp2d120 sensor?

I'm not finding any information on the net to explain how to program the gp2d120 with an arduino.  I have seen stuff in other codes but don't understand any of it.  So what I'm wondering is how do I actually tell it what to do at a certain distance.  I understand that it use a certain amount of volt for different distance but wasn't sure how you actually put that in a code.   I have everything I need to get started on my robot and hoping I can just figure this sensor out so I can post it up on here.  If someone know a tutorial for me that would be awesome. 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Edgee's picture

If you hook your sensor up to the arduino then change the pin in this arduino code to the right pin, upload to your board then click the serial monitor button in your arduino ide then you will be able to see what is being given back from the sensor.  

 

http://arduino.cc/en/Tutorial/Graph

 

Once you know all of that is working and  you want to see it as a graph then download processing from:

http://www.processing.org/

 

here and run it with the code supplied in that example.  

Chris the Carpenter's picture

The real problem here is geography! I just did a quick member check... OF COURSE you are having these problems...

Sedgwick County?!?!?!?  --Well, there's your problem...

Move up to Manhattan where it's normal! --But then again, you do have The Yard there... I guess that's a good thing!

lol, yep you better believe it. 
Chris the Carpenter's picture
Forget about the fact that you are using a sensor. This is just an analogue device. Learn about ADC inputs, not sensors.
Edgee's picture

a basic progrtamming guide.

 

 

May do that tonight.  

that be a good idea, not really any good ones out there for actually writing codes for robotics.
ericski's picture

I may be missing your question but it sounds like you want something that looks like this:

 

void loop()

{

   int distance = readSensor();

   if ( distance > 10 )

   {

      doSomethingDifferent();

   }

   else

   {

     doNormalStuff();

   }

}

I was thinking about something like that but wasn't sure if it would understand if I would put 10 and it would take it as 10cm.  Sorry I'm very new with sensors.  So would that be just about how to do it then.  Also do you really have to have a bypass capacitor or would it be ok without it.
rik's picture

Do you know what an Analogue to Digital Convertor is and does? Do you know how  to use one in an Arduino program?

If so, apply all that to the G2D120.

If not, wait for another hero to come along. Sorry.