Pages: [1]   Go Down
Author Topic: Reading LOW and HIGH from a Sharp GP2D150 with Arduino UNO  (Read 1157 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I'm a starter. *g*

I have a Arduino UNO which should drive a RC with distance sensors so I've bought a Sharp Distance Sensor (GP2D150) which will give me a Digital HIGH or LOW - if a Distance is reached...

The Datasheet is available at: http://www.w-r-e.de/robotik/data/dist/gp2d150a.pdf

Wire-MAP (Pins like in the datasheet):
Pin 1 - Vo - goes to Digital 7 at Arduino
Pin 2 - GND - goes to GND at Arduino
Pin 3 - Vcc - goes to 5V at Arduino

Code:
int distpin = 7;
int val = 0;

void setup()
{
  pinMode(distpin, INPUT);
  Serial.begin(9600);
}

void loop()
{
  val = digitalRead(distpin);
  Serial.println(val);
  delay(1000);
}

If I look at the Serial monitor - i'll only get 0 - no matter how far or near I'm holding any object...


Any suggestions, what I'm doing wrong?
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34568
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what I'm doing wrong

1) The sensor is broken.
2) You have misidentified the pins.
3) It isn't quite wired up correctly.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you connected a 12K resistor like on page 2 of the datasheet?

you could do a delay(50) in setup to skip over "unstable output" see page 3

You might connect a LED + 220 Ohm resistor between output of the sensor and GND, to check the sensor.
« Last Edit: April 14, 2011, 04:08:48 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34568
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Have you connected a 12K resistor like on page 2 of the datasheet?
If not adding:-
 digitalWrite(distpin, HIGH);

directly after:-
pinMode(distpin, INPUT);

will activate the internal pull up resistor.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thx for all your answers.

i'll try your advises later this evening and give you feedback - so somebody later can find the right clue.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Same result...

I've added a 12K Resistor (10K+1K+1K - Because I don't got a 12K) - to the Vo - this was missing when I've tried...

I've also added the code you've mentioned (see new code below)

Code:
int distpin = 7;
int val = 0;

void setup()
{
  pinMode(distpin, INPUT);
  digitalWrite(distpin, HIGH);
  Serial.begin(9600);
  delay(50);
}

void loop()
{
  int val = digitalRead(distpin);
  Serial.println(val);
  delay(500);
}

If I look at the serial monitor I only see 1,1,1 But - no 0 - not matter what distance - this is why I've set the input to HIGH - right?

Before posting i was looking at some example code and read the values with analoge in - where i can see that the sensor(s)'s working (0,9 Volts or less - depending on the distance) - so the sensor should work.

I've also bought a second sensor - which will be needed in future - and get the same results so the possibility, that the sensor is damage is very low...


The LED with a 220 Ohm resistor does'nt blink or anything...

A closer view of the cabeling: http://fritzing.org/projects/distance-sensor-sharp-gp2d150a/


Thx for any help...


Bjoern
« Last Edit: April 15, 2011, 02:49:42 pm by bjoernhoefer » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote

If I see correctly you added the 12 K between the VO and the Arduino pin. That is not correct, you should add the 12K between the VO line and VCC (5V) and the VO should connect directly to the Arduino pin.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://fritzing.org/projects/distance-sensor-sharp-gp2d150a/

Updated the cabeling.

If I connect it as illustrated - the led stops to shine...
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that should mean the line is not 1 anymore.
What does your sketch return?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the serial monitor only shows 0,0,0

no matter what distance an object is...

strange thing...

if i disconnect the GND - it turns to 1,1,1 - but no 0...

The LED stops shining, when i connect the Vcc or the Vo.

I also see no IR "light" (throu my mobile phone camera - which i was able to see, when it was connected to the analog ports...)

any suggestions?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SOLVED!!!

I've connected the VCC to the 5V Port - and it started working!!


In a few minutes I will upload the correct cabeling to the fritzing homepage.
http://fritzing.org/projects/distance-sensor-sharp-gp2d150a/

Thanks to all for helping me out!!
Logged

Pages: [1]   Go Up
Jump to: