Arduino-GP2Y0A21YK-library
Arduino-GP2Y0A21YK-library copied to clipboard
Can't get any results
I can't seem to get this thing to work, at all.
What Happens: Serial monitor reports any input as minimum input (255 raw, 10cm with Centimeters, 1246 mV). In my glances through your source, these are the "Defaults" if it doesn't find actual information.
What I've tested: I used this site: http://bildr.org/2011/03/various-proximity-sensors-arduino/ Wired it up as stated, which is the same wiring this needs. Go to serial monitor, and the values change as I move things in front of the table.
My first thought is that I was wiring it wrong, but even after trying every single other pin (Both analog and digital, for good measure) on my Arduino Uno (R3), I had no changes from this code.
My second thought was that the pin was listed wrong in this code (As the example uses pin "A0" and the link above uses the pin "0") so I changed that to "0" and still have had no change.
If I look at the LED in just the right angle, I can see the faint red from it, so the sensor is working. There's just something wrong somewhere else. Any help would be greatly appreciated.
I had a quick look in to the code. I added: "setEnabled(true);" in the begin function (here: https://github.com/jeroendoggen/Arduino-GP2Y0A21YK-library/blob/master/DistanceGP2Y0A21YK/DistanceGP2Y0A21YK.cpp#L51)
I think that I forgot to add that line when adding the "setEnabled" feature: https://github.com/jeroendoggen/Arduino-GP2Y0A21YK-library/blob/master/DistanceGP2Y0A21YK/DistanceGP2Y0A21YK.cpp#L205
I am not 100% sure that this will fix you issue. This code was written with the old PROGMEM syntax and needs an update to the new syntax... http://arduinoetcetera.blogspot.be/2013/07/using-program-memory-progmem.html
An other idea would be to use this library: https://github.com/jeroendoggen/Arduino-distance-sensor-library
Second library did the trick. Thanks!