Reading LOW and HIGH from a Sharp GP2D150 with Arduino UNO

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

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?

what I'm doing wrong

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

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.

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.

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.

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)

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: Distance Sensor - Sharp GP2D150A

Thx for any help...

Bjoern

A closer view of the cabeling: Distance Sensor - Sharp GP2D150A

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.

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

Updated the cabeling.

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

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

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?

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!!