Hello! I just plugged in my sharp IR sensor in my arduino. I soldered on the connectors, so it may not be a good connection if that will help troubleshoot! I user this function to calculate the output of the sensor into cm.
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;
}
And I can see it works. I just put my hand in front of it and moved it farther away, or closer to the sensors. It gave me almost correct numbers.
But sometimes, I just get weird symbols that I can't even type with my keyboard.
like a square and many others! Could the possibly bad soldering be the problem?