sharp GP2Y0D805Z0F arduino code

Hello guys,

I am new in this Arduino world. I have a sharp GP2Y0D805Z0F sensor, however, I cannot find any code that works. The sensor has a specification distance that goes from 0.5 to 5 cm.
I have tried the following code, but I don't understand why the output is in volts and not in cm. Is there a way to convert the volts into cm. Sorry if I lack technical knowledge, I am just starting at this.

int IRpin = 0; // Analogeingang
double value, volts;
void setup()
{
Serial.begin(9600);
}
void loop()
{
value = analogRead(IRpin);
volts = value*5.0/1024.0;
Serial.println(volts);
delay(50);
}

Hello guys,

I am new in this Arduino world. I have a sharp GP2Y0D805Z0F sensor, however, I cannot find any code that works. The sensor has a specification distance that goes from 0.5 to 5 cm.
I have tried the following code, but I don't understand why the output is in volts and not in cm. Is there a way to convert the volts into cm? Sorry if I lack technical knowledge, I am just starting at this.
Code: [Select]

int IRpin = 0; // Analogeingang
double value, volts;
void setup()
{
Serial.begin(9600);
}
void loop()
{
value = analogRead(IRpin);
volts = value*5.0/1024.0;
Serial.println(volts);
delay(50);
}

Hello
take a look here.

The output is in volts because of the code that you wrote. An analogue input measures a voltage in 1024 steps. You convert the measurement to volts.

Looking at the datasheet of the sensor, the sensor provides either high or low, not a linear voltage indicating distance. So its output indicates presence or no presence of an object inside its range.

The datasheet is available here: https://www.pololu.com/file/0J284/GP2Y0D805Z0F.pdf

It is not very clear but it seems to produce negative-going pulses, the width of which indicates the distance. I think you would read the pulse with "unsigned long pulseWidth = pulseIn(DataPin, LOW, timeout);". The default timeout is 1,000,000 microseconds (1 second) so you should probably pick something shorter. Some experimenting should allow you to determine the distances associated with various pulse lengths.

Hello Arduino Forum. I hope you can help me with a question. I have a project where I need to measure the distance from an RGB colour sensor to a reflective surface. I want to vary the distance of the surface to see how it affects the reading of the colour sensor. I am using this one TCS34725 RGB Color Sensor For Arduino - DFRobot.

I have looked for all type of sensors including the sharp GP2Y0A21YK0F which has a 10 to 80cm distance measuring range. I need a sensor that has a range from 0.5 cm to a maximum of 5 cm, adafruit used to have one but it has been discontinued.
Polulu has a sharp GP2Y0D805Z0F Digital distance sensor, that from what I gather this is only to detect the presence of objects within that range, not to measure the distances. Is there a sensor that I can use for this type of measurement? Or is there a code that I can use to adapt the Polulu sensor to measure the distances?

Thank you all for your time! Sorry If any of my questions are silly, but I am new in this arduino world

Don't cross post; reported.

@asds98

Other posts/duplicates MERGED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.