Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to use: Sharp GP2Y0A21YK Distance Sensor

Status
Not open for further replies.

Robo

Junior Member level 3
Joined
Jan 21, 2005
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
327
sharp gp2y0a21yk

I've just bought the distance sensor, but I'm not sure how to use it. I understand that the closer the sensor is to the wall, the higher the output voltage will be. But what do I do with the output voltage so that I can program my robot to avoid hitting walls? (By the way I'm using board of education with BasicStamp 2 module)
I know somehow I need to use an ADC to obtain the digital signal. But how do I let my board of education to "read" the digital signal?

My initial thought is that I connect the output wire to one of the P0 to P15 ports (let say P0), and I program with BasicStamp with the following pseudocode:
if P0 > 2.5V
turn left
else
continue going forward

However, I don't think my BOE will detect what the output voltage is at P0. Anyone has any idea? Thanks.
 

gp2y0a21yk circuit

I think what you are going to do is use analog sig nal from output of GP2 to detect that your robot shold turn or not, right?

If you want to do like that, you just put your signal through comparator circuit (like opamp with one pin connected to reference voltage), so, you can detect if level of output signal voltage exceed than referrence voltage.

By the way, This will neglect benefith of distance measurae feature, which is the ability of this sensor. So, to make this sensor useful for your money, I think connect it to ADC is the best idea.

This is my idea :)
Hope it can help
 

gp2y0a21yk

Thanks for replying:)

But how can my Board of Education reads the voltage (let say 3V)? Does BOE have input port so that I can connect the 3V to the input port to let BOE knows there is 3V at the port? Thanks.
 

sharp distance meter

On your Board of Education you have all 16 I/O pins next to the breadboard.
These pins can be used to read signal(s) from external devices such as your distance meter. They can also control 8-bit (or more) A/D converter which can be fed directly from your d-meter. With 8-bit A/D you will have 256 different signals which can be used to control movement of your robot with much greater precision than a two-stage method.
 

gp2y0a21yk op amp

Thanks.

For simplification, I'll just use the 2-stage method instead of ADC for now. For the following pseudocode: (Assume I connect the sensor voltage reading to P0)

'Turn left when voltage at P0 is greater than 3V (robot too close to the wall)
if (P0 > 3)
turn left

'Otherwise continue to go forward (nothing is blocking in front of robot)
otherwise
go straight

How should I write the "if (P0>3)" line using BasicStamp? Let say I input 2V as the sensor reading to P0, I don't think simply writing "if (P0>3)" will return a false statement right? What should that line be? Thanks.
 

sensor charp code basic stamp

Remember that you will have only 2 possible readings: anything below 0.5V (or so) will be logic '0', anything above 2.5V (or so) will be logic '1'.
For this reason you should use a comparator to allow only these two levels to the PIN xx : '0' or '1'.

So in BasicStamp the line will be:
IF (IN xx=0) THEN .... this way
or
IF (IN xx=1) THEN .... the other way
 

gp2y0a21yk sharp

It always run Loop2, followed by Loop. The two "if then" don't seem to work... any idea? Thanks for helping!

Here is my BasicStamp code:

'{$STAMP BS2}

counter VAR Word
DEBUG "Go Robo!"

Loop2:
LOW 1
HIGH 2
LOW 3
LOW 4
PAUSE 5000
IF (0 = 0) THEN Loop

Loop:
LOW 1
HIGH 2
LOW 3
HIGH 4
PAUSE 5000
IF (0 = 1) THEN Loop2

'PAUSE 5000

END
 

how to use gp2y0a21yk

Have you checked/measured the voltage on "0"? It looks like the "0" is in logic H and keeps you in loop2...
 

    Robo

    Points: 2
    Helpful Answer Positive Rating
usar sharp gp2y0a21yk

Yup, got it:) Thanks IanP!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top