gp2d12 problem

hi i tried to interface gp2d12 sensor with my arduino board..what i could see in the serial monitor is values ranging from 912 to 916 and nothing more...its not making any difference between with and without obstacle what could be the possible reason for tat?i also tried putting a capacitor in parallel to reduce noise..pls help me.

It would probably help if you posted:

1) your schematic for how you hooked it up. 2) a link to a datasheet for the sensor. 3) your code.

Otherwise it's a bit difficult to help.

I for instance does not have a clue to what a 'gp2d12' is.

Hi, there is it a sharp infrared ranger? ?
If all wires are hooked up correctly and properly grounded?

I see a potential problem in the datasheet: average power consumption: 33mA, this is straining the arduino to the max.
Should use a exernal powersupply to power this thing.

THe voltage at 10cm seems to be the max value of 2.6V soit should be considered to change the voltage ref to 3.3 volt with a wire between 3.3V out and ARef pin

look at playground code:

 Function that reads a value from GP2D12 infrared distance sensor and returns a value in centimeters.

 This sensor should be used with a refresh rate of 36ms or greater.

 Javier Valencia 2008

 float read_gp2d12_range(byte pin)

 It can return -1 if something gone wrong.


float read_gp2d12_range(byte pin) {
      int tmp;

      tmp = analogRead(pin);
      if (tmp < 3)
            return -1; // invalid value

      return (6787.0 /((float)tmp - 3.0)) - 4.0;