Help with Sharp distance sensor

I need help getting a Sharp distance sensor working with the 3pi.

Following the example in this website for 3pi Wall Follower, I’ve connected a Sharpe 2Y0A21 10-80cm range sensor to the 3pi. I’m hoping to experiment with the Sharp sensor to see how well it senses various objects depending on their size, distance, reflectivity/color of surface etc. for possible use in a hockey-bot. Thus, I’ve only connecting what the example uses as the LEFT wall sensor.

So, I removed the 3pi jumper for the ADC7 to the user trim pot. I’ve soldered 3 wires to the Sharp sensor Red, Black, and White (ok my wire is Yellow). Then I soldered these to the 3pi board pin/holes for Vcc, Gnd, and ADC7 (respectively) as shown in in the example documentation. (I’m assuming the silkscreen label AD7 is equal to the ATmega ADC7 port.)

For software, since I want to observe the reading from the Sharp sensor, I thought I could just run the 3pi-demo-program/test.c as-is, select the trim pot test, and see (and hear) the value.

The code looks simple enough. I gave it a try but LCD display shows a value of “71” no matter what I point the Sharp sensor at, far or near. The reading never changes.

Am I missing something? The code is show below. I ran as-is from Pololu first. I tried replacing calls to read_trimpot to analog_read(7) but no change. (I turned off the tone to stop annoying me.)

void pot_test()
{
	long start = get_ms();
	char elapsed_ms;
	int value;

	set_analog_mode(MODE_10_BIT);
	print_long(read_trimpot());
	print("   "); // to clear the display

	while((elapsed_ms = get_ms() - start) < 100)
	{
		value = read_trimpot();
		
		//play_frequency(value, 200, 15);	// silence please
		
		if(value < elapsed_ms*10)
		{
			red_led(0);
			green_led(1);
		}
		else
		{
			red_led(1);
			green_led(0);
		}
	}
}

The only deviation I can see from the example wall follower is that the photo of the underside of the Sharpe (labeled “Sharp distance sensor with connected wires and double sided tape”) looks slightly different. The screw and all the layout looks identical but on my part the White and Black wires are very close and the right-most solder point (Red wire) is spaced further away. Also my part is labeled “2Y0A21” where as the example photo shows a Sharp “GP2D12”. (Hmmm. I wish I’d ordered the little cable. Says it works with the 30cm would it work with the 80cm part too?)

Also, I guess looking closely now I soldered to the outer most 3 solder points whereas the example photo almost looks like he soldered to the 3 points that are the 2nd row in from the edge.

Is that my problem perhaps? If so, can someone tell me if the 99 cent cable works for the 80cm part? My soldering skills won’t let me work at such small detail.

Thanks

Hello,

Your code is way too complicated for this kind of troubleshooting. It’s so much you didn’t even include all of it in your post. Something simple like this would be way better:

#include <pololu/3pi.h>  

int main()
{
	while(1)
	{
		print_long(read_trimpot());
		print("   "); // to clear the display
		lcd_goto_xy(0,0);
	}
	while(1);
}

- Ryan

Hello.

Our 3-pin JST cable for Sharp distance sensors works with all three Sharp analog distances sensors we sell. I don’t really understand what you’re saying about the wires on the back of your sensor, but I suspect you have something connected wrong (or a bug in your code; can you let us know what happens when you try something simpler like what Ryan suggested above?). Can you post a picture of the underside of your sensor?

- Ben

I re-soldered the Sharp sensor and the read_trimpot() now works! It gives values in the range of 2 to about 620 (depending on distance to an object) as mentioned in the sample project. I’m running Ryan’s simple loop code.

I’ve experimented with various surfaces - white paper, black paper, white plastic, mirrored, etc. White paper seems to be detected the best (higher numbers and detectable at longest distances).

My next puzzle: Even aimed at a large (12 inch square) box side I get a reading of 0 until the sensor is about 22 cm (9 inches) away. Does anyone else have experience with the 10-80cm Sharp sensor over the longer distances? I’d expect some reading between 20 to the spec max of 80cm.

Do I need a better circuit than just direct connect to the ADC7 port? Or maybe my solder joints are just too terrible? (See photos … and be ready to ‘gasp’.) Or maybe all my soldering, re-soldering heated the sensor too much and altered it?

(I’m ordering the 3-pin cable as making tiny solder joints is a challenge. I have 2 other Sharp sensors: another 10-80cm plus 4-30cm one. I try those once I get my 3-pin cable.)

Other suggestions? Inputs?




Hello.

Well your picture makes it clear what was wrong before. Your yellow and red wires were soldered to the completely wrong places. Once you apply power to the wrong place, there is a good chance that something will break on the sensor. I suggest you wait and compare the results with the other sensor you got that didn’t have power supplied backwards. If it is okay, probably something about the sensor is broken.

Your soldering is pretty bad, especially the part of the wire that looks like it is about to touch the resistor. Generally, you want to keep wires are far apart as possible to avoid shorts. Here was my soldering job:

I’m still not particularly happy with it. The wires could have been wrapped around the pins, the insulation could be a lot closer (especially on the middle wire), the wires could have been trimmed better after I was done soldering, and there could have been about a quarter less solder.

- Ryan

Yep. I’m retiring from the solder business when it comes to tiny geometries.

If it’s not too much trouble you might add a brief note in your wall follower example guide, under Construction. Just after your sentence “Prepare the two distance sensors by soldering three wires to the three leads as shown in the picture.” you could add “Be sure to solder to the row of 3 solder points shown in the photo and NOT to the 3 solder points closer to the edge of the connector.” … or such.

OR, EVEN BETTER, for 99 cents, I’d recommend the 3-pin cable part to people. Seems like a worthwhile investment to make sure your $10-13 sensors work properly and don’t get damaged.

So, just to confirm, you’d say that the 10-80cm sensor connected directly to the AD7 port will indeed give readings for a wall etc. out closer to the 80cm max distance (if not fried or poorly soldered) in your experience?

Thanks

Hello.

I feel like the solder locations are pretty clear from the picture. The “3 solder points closer to the edge” are really just 1 point that would be slightly reasonable to solder to and the 2 pads of a resistor. I will add the suggestion of the cable to that document. Good idea.

I just tested a 80cm Sharp sensor we had lying around. The ADC was never reading zero and was responding to objects moving all the way up to 80cm. If you look at the output graph of the sensor on its product page, you will see that a reading of zero not very common (only happing when the sensor is completely covered).

- Ryan

I think the soldered picture above is interesting since i’ve ordered my 2nd sensor from amazon and the connector is difficult to attach and when attached has the red wire going to the pin that the authors above indicate should be the Vo and not the Vcc.
image