Skip to content

In Which Carbot May Look Sharp

November 14, 2014

14-11-14 sharp
The arduino version of carbot used two ultrasonic sensors facing front and right to detect obstacles and maintain its distance from the arena wall. I had to do timing gyrations to keep them from interfering with each other and to respect their need for a 50ms breather between pings. I have, however, a Sharp 2Y0A02 infrared rangefinder that may simplify things for the olduino version. The Sharp sensor has 3 pins like the ultrasonic: ground, 5V, and signal, but the difference is that instead of a digital ping/response sequence on the signal pin, the Sharp sensor presents a continuous analog voltage on the signal pin that reflects how far the nearest obstacle is. The voltage ranges from under .5V for something over 150cm away up to near 3V for something under 20cm.

The code on the arduino was the following

int looksharp(){ //query the sharp ir sensor 
  int aread=analogRead(sharppin);
  int scm=11832/aread;
  cout <<"Sharp sez "<<aread<<" meaning "<<scm<<" cm"<<endl;
  return scm;
}

a 3V signal from the sensor would have returned something like 600 from analogRead() and the distance would be taken as 19cm which is about right.

The olduino lacks an analog input function, of course, so i have to do something different. I could either use a comparator IC with the reference voltage set to trigger at my distance threshold, or I could hoke something up with a schmitt trigger. It may come down to what I have in my parts supply.

Update: I do have the odd schmitt trigger IC in my bin, e.g. a 74hc14 nand gate. Looking at it, it has a nominal On threshold voltage around 2.4V and an off threshold of 1.4V. That means as my input voltage went above 2.4V, indicating right around 20cm the inverter would show 0 output which is fine but it wouldn’t go to 1 again unless my input voltage fell below 1.4V at around 40cm. It’s not crazy but it’s not what I want for either forward or side facing sensor. I could jigger my sensor voltage with a divider or something but the basic hysteresis characteristic of the schmitt trigger just doesn’t fit what i need. Also I think those thresholds would vary from one sample to another.

I think it comes down to either a comparator IC like an LM393 or a specific ADC like the Microchip MCP3202. I don’t have either of those to hand.

From → Uncategorized

Leave a Comment

Leave a comment