Inaccurate data from sharp distance sensor.

Hello there.

I'm just a noob at electronics. This is very literally my first morning using an Arduino and doing anything electronics related.
Having said that I do have a programming background so I'm not completely lost.
Now that you know who you're dealing with... here's what I'm trying to do.

Project Description:

I have an Arduino UNO and a Sharp GP2Y0A02YK0F Distance Sensor. I downloaded the following library (and imported): GitHub - jeroendoggen/Arduino-GP2Y0A21YK-library: Arduino library for the Sharp GP2Y0A21YK IR Distance sensor

This is the code that I have in my sketch: (based on an example that's included with the library)

#include <DistanceGP2Y0A21YK.h>
//#include <DistanceGP2Y0A21YK_LUTs.h>

DistanceGP2Y0A21YK DistanceSensor;
int distance;

void setup() {
  // put your setup code here, to run once:
  // this is where you initialize your hardware and get it ready for operation.
  Serial.begin(9600);  //defining the speed of the serial communications
  DistanceSensor.begin(0);
  }

void loop() {
  // put your main code here, to run repeatedly: (until the arduino is reset or powered off)
  distance = DistanceSensor.getDistanceCentimeter();
  Serial.print("\nDistance in centimers: ");
  Serial.print(distance);  
  delay(500); //make it readable
}

Problem:

I'm not confident that the data I'm getting back is accurate. Reason being, right now, I have it lying on it's back facing up towards my ceiling as I program it. I keep getting values ranging from 9-14 cms.
If I cover both lenses with a stack of paper or my fingers I still get a similar range back.

I'm wondering if I've set this thing up correctly?

I have some pictures of my breadboard / Arduino set up. I've attached it below.

Basic Description of Breadboard setup:

Incase it's not clear from the picture, the distance sensor has 3 wires, yellow, black and red. the yellow is what i'm assuming is sending the voltage data... and that is being passed into input A0 on my Arduino. The rest of the wires I have is to the the power from the Arduino and supply it to the sensor.

If you need more details about the breadboard set up please just let me know.

Thanks.

cpama:
Hello there.

I'm not confident that the data I'm getting back is accurate. Reason being, right now, I have it lying on it's back facing up towards my ceiling as I program it. I keep getting values ranging from 9-14 cms.

Use a multimeter to measure the voltage while waving a sheet of paper up and down.
This will tell you if the sensor is working correctly.

You should see approx 2 V difference from min to max range.

Note that this sensor only works correctly over a limited distance range. Too close or too near and the results are inaccurate. See the voltage / distance graph in the data sheet. Also note that all readings are ambiguous.

I just dug up a brand new HC-SR04 out of my "junk box" so I'm going try again using that sensor instead to see how differently it behaves. Unfortunately I don't have a multi-meter yet as i'm just starting out with this new hobby...
Thanks everyone for taking the time.

So I replaced the sensor with HC-SR04 and now the numbers are making more sense.
Thanks everyone.

cpama:
see how differently it behaves. Unfortunately I don't have a multi-meter yet as i'm just starting out with this

First thing you should buy.

Wall mart or halfords .

Fiver is much better than nothing, they all have 10 meghom impedence these days.
Much better than i had when starting out, they costed a fortune.