Go Down

Topic: Reading LOW and HIGH from a Sharp GP2D150 with Arduino UNO (Read 1 time) previous topic - next topic

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: [Select]

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?

Grumpy_Mike

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.

robtillaart

#2
Apr 14, 2011, 11:04 pm Last Edit: Apr 14, 2011, 11:08 pm by robtillaart Reason: 1
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.
Rob Tillaart

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

Grumpy_Mike

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.

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.

#5
Apr 15, 2011, 08:20 pm Last Edit: Apr 15, 2011, 09:49 pm by bjoernhoefer Reason: 1
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: [Select]

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

robtillaart

Quote
A closer view of the cabeling: http://fritzing.org/projects/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.
Rob Tillaart

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


robtillaart

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

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

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

Go Up