| Author |
Message |
Robo
Joined: 22 Jan 2005 Posts: 27
|
22 Jan 2005 0:28 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.
|
|
| Back to top |
|
 |
Taro
Joined: 28 Jun 2001 Posts: 147 Helped: 3
|
22 Jan 2005 3:31 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
|
|
| Back to top |
|
 |
Robo
Joined: 22 Jan 2005 Posts: 27
|
22 Jan 2005 3:52 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.
|
|
| Back to top |
|
 |
IanP
Joined: 05 Oct 2004 Posts: 6490 Helped: 1542 Location: West Coast
|
22 Jan 2005 4:13 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.
|
|
| Back to top |
|
 |
Google AdSense

|
22 Jan 2005 4:13 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
Robo
Joined: 22 Jan 2005 Posts: 27
|
22 Jan 2005 5:40 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.
|
|
| Back to top |
|
 |
IanP
Joined: 05 Oct 2004 Posts: 6490 Helped: 1542 Location: West Coast
|
22 Jan 2005 8:54 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
|
|
| Back to top |
|
 |
Robo
Joined: 22 Jan 2005 Posts: 27
|
28 Jan 2005 8:03 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
|
|
| Back to top |
|
 |
IanP
Joined: 05 Oct 2004 Posts: 6490 Helped: 1542 Location: West Coast
|
28 Jan 2005 8:38 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...
|
|
| Back to top |
|
 |
Robo
Joined: 22 Jan 2005 Posts: 27
|
30 Jan 2005 7:21 usar sharp gp2y0a21yk |
|
|
|
|
| Yup, got it:) Thanks IanP!
|
|
| Back to top |
|
 |