Skip to content

In Which I Am Sharply Disappointed

November 22, 2014

I have the Sharp Infrared Distance Sensor hooked up via the MCP3002 Analog to Digital Conversion chip. All of the individual pieces seem to work but the overall results are disappointing.  There are two issues: range and noise.
14-11-22 sensor

  • The range issue is a result of the way the sensors work.  Essentially, they have an LED in one “eye” which bounces IR off the target and back to the sensor in the other “eye”.  The LED is angled in a bit so that when an obstacle is about 20cm(8″) from the sensor, it gets peak light and gives the highest voltage – further away and the voltage drops off.  Unfortunately, a CLOSER obstacle reads the same as one further away.  The reading at 12 cm is about the same as the reading at 22cm.  If I pick a trigger voltage of  2V, I may be 30 cm from the obstacle or 10cm.  The only thing I can see working is to use this sensor for the forward facing distance and keep it more than 10cm back from the front of the car.

14-11-22 sharp diagram

    • The noise issue was a surprise to me but apparently the sharp sensors are notorious for it.  The 2.0 v trigger voltage that I’m planning on can easily spike to 2.5V every few readings.   The best results came from putting a 10uF cap across the signal with a 560 ohm resistor in parallel.  I find that resistor shockingly low but it does seem to improve things although I still see the 2V signal spiking to 2.25V.  I may look for another sensor or try measuring 3 times and throwing out the highest value.

sharp via mcpBy the way, the output shows the raw data as 16 bits from the ADC (say F98D on the first line).  The reading is actually in the bottom 10 bits 018D which is 397 and converted to a voltage as 397/1024*5.  I think that this is the first time I’ve ever used the floating point math and printing for anything other than testing floating point math and printing.  The code looks like this:

void main(){// exercise the sharp sensor
unsigned char c00,c01;
unsigned int tenbits;
float voltage;
	out(4,0x80); PIN4=0x80; //make sure slave select is high
	while(1){
		digitalWrite(7,LOW); //lower slave select
		c00=spixfer(0x68);
		c01=spixfer(0);
		digitalWrite(7,HIGH); //raise slave select
		tenbits=(c00&0x03)*256+c01;
		voltage=(float)tenbits/1024.0*5.0;
		printf("channel 0 sez %cx %cx or %d or %f Volts\n",c00,c01,tenbits,voltage);
		delay(1000);
	}

Oh, also by the way, I have thought about implementing a 16 bit float which would have a decent range but only 3 decimal digits of precision. “half” floats are used in graphics for storage but they’re not used directly for calculation. My implementation would have the range of an int but could represent small non integers – perfect in this case.

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: