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?
https://shop.pimoroni.com/products/pololu-carrier-with-sharp-gp2y0d805z0f-digital-distance-sensor-5cm?variant=31546927841363&currency=GBP&utm_source=google&utm_medium=cpc&utm_campaign=google+shopping?utm_source=google&utm_medium=surfaces&utm_campaign=shopping&gclid=CjwKCAjwgOGCBhAlEiwA7FUXkkvZCf-_Tn7m0Mnq13JSL7Z9mnP3qZt_8oHSoScjyNINkgv6vQ6EFhoCm_oQAvD_BwE

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.

Please take a few moments to Learn and Use The Forum

It will help you get the very best out of the forum in the future.

  • Your OS and version can be valuable information, please include it along with extra security you are using. Antivirus etc.

  • Always list the version of the IDE you are using and the board version if applicable.

  • Use quote or add error messages as an attachment NOT a picture.

  • How to insert an image into your post. ( Thanks @sterretje )

  • Add your sketch where applicable but please use CODE TAGS https://drive.google.com/file/d/1vF0OE4HozgyW_3oFENjem8DCrbrNoZ88/view?usp=share_link

  • Add a SCHEMATIC were needed even if it is hand drawn

  • Add working links to any specific hardware as needed (NOT links to similar items)

  • Remember that the people trying to help cannot see your problem so give as much information as you can

COMMON ISSUES

  • Ensure you have FULLY inserted the USB cables.

  • Check you have a COMMON GROUND where required. ( Thanks @Perry)

  • Where possible use USB 2.0 ports or a USB 2.0 POWERED HUB to rule out USB 3.0 issues.

  • Try other computers where possible.

  • Try other USB leads where possible.

  • You may not have the correct driver installed. CH340/341 or CP2102 or FT232 VCP Drivers - FTDI

  • There may be a problem with the board check or remove your wiring first.

  • Remove any items connected to pins 0 and 1.

COMPUTER RELATED

  • Close any other serial programs before opening the IDE.

  • Ensure you turn off any additional security / antivirus just to test.

  • There may be a problem with the PC try RESTARTING it.

  • You may be selecting the wrong COM port.

  • Avoid cloud/network based installations where possible OR ensure your Network/Cloud software is RUNNING.

  • Clear your browsers CACHE.

  • Close the IDE before using any other serial programs.

  • Preferably install IDE’s as ADMINISTRATOR or your OS equivalent

ARDUINO SPECIFIC BOARDS

  • CH340/341 based clones do not report useful information to the “get board info” button.

  • NANO (Old Types) some require you to use the OLD BOOTLOADER option.

  • NANO (ALL Types) See the specific sections lower in the forum.

  • NANO (NEW Types) Install your board CORE’s.

  • Unless using EXTERNAL PROGRAMMERS please leave the IDE selection at default “AVRISP mkII”.

  • Boards using a MICRO usb connector need a cable that is both DATA and CHARGE. Many are CHARGE ONLY.

CREATE editor install locations.

  • On macOs ~/Applications/ArduinoCreateAgent-1.1/ArduinoCreateAgent.app/Contents/MacOS/config.ini

  • On Linux ~/ArduinoCreateAgent-1.1/config.ini

  • On Windows C:\Users[your user]\AppData\Roaming\ArduinoCreateAgent-1.1

Performing the above actions may help resolve your problem without further help.

Language problem ?

Try a language closer to your native language:

Thanks to all those who helped and added to this list.

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