Let's Make Robots!

Sharp IR and voltage drops in large systems

I don't know why I decided to put a Sharp IR (GP2Y0A21) in K-9.  Probably because it's smaller than the HC-SR04 that I'm so much more used to.  In any case, I got a general system assembled and decided to test it using essentially the same branching that I used on Maus.  It seems to go into its obstacle avoidance routine at random.  It definitely reacts when it "sees" something, but also often when there's nothing in front of it.  What I'm wondering is could the "Analogness" of the sensor be what's killing me?  Is a spike the motors are throwing off letting pumping too many V through the sensor and causing a false higher reading?  As an example:


if(analogRead(IRpin)<250){

  k9Forward();

}

else{
lookAroundForLeastObstructedPath(notARealFunction);
}

in the main loop.  Is it a battery/motor/power thing or is there something else I'm not getting about this sensor that everyone but me knows about?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

You know that Sharp sensors need a 10uF cap soldered on the sensor's board over the power pins, right? And you may also want to add another cap over the signal and ground pins to smooth out the "analogness" and keep it from oscillating too much. I think I remember this cap being something between 0.1 and 1uF, you need to experiment to find the best value for your sensor, as not all sensors are the same.

Cheers!

I suspected something like that, but didn't know it.  Thanks Gabriel!

My implementation was going to use an averaged queue of the values of the IR reading through a set of several loops so it didn't tie the processor up with a function and run into something while it executes the function. My concern was that a single false reading would be high enough to throw off the running average and leave me in the same boat. The question then becomes how often are the spikes occurring and how long of a queue would I use? The problem with getting that data is that running a serial line to the micro isn't feasible while it's running, and it never seems to have the problem when it's on the bench running to serial.

I can't offer much advice on if the sensor itself has any weird quirks, but maybe you should try implementing a simple averaging function to minimise the effect of any false readings from noise, etc.