Let's Make Robots!

Arduino Bot has a mind of its own??

    My bot seems to have a mind of its own. code seems to be working but at times it react to an object thats not there??? its set to find a better path after coming within 30 cm of an object but sometimes theres nothing there and it looks for a better path? can this be from the ping returning false values, or i think it might be from the 9v battery draining quickly. Any ideas?? Thanks oh, I'm using Arduiino Duemilanove. Code is attached

Object_Avoidance_Servo_Ping_Led.pde5.62 KB

Comment viewing options

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

Can you post some side views?  It looks like your ping))) sensor is blocked by the bumper.  I'm sure you didn't build it that way. 

It not, check out this pic, i thought that was the problem too but nope. Thanks 


I see your point.  Thanks for the pic.  Maybe looking at the readings the ping))) is giving you would be more helpful?  I would suggest increasing the delays and having it return the readings via serial connection (xbee?).  The delays will give you time to coorelate the reading with the position.

Cant afford an xbee right now, i saw on the another forum somebody said echos might be causing an error to maybe add a 50 ms delay between pulses from the ping? wat do you think? http://arduino.cc/forum/index.php/topic,58378.0.html

A pause after each range pulse would be good. 10 ms may be adequate.

Another thing I just noticed is that you are "rolling your own" servo controls. Why not just use include the servo library and use those commands?

How wud I add this delay btw pulses.. thinking of adding the line delay(10) after nodanger() and before "else" in the loop mayb? not using the servo library b/c im not too familiar with it yet, more comfortable doing it manually. still learning programming

added "delay(10);" after "readdistance();" got it working right, finally!

OK, I'm pretty new at this level of knowledge of the Arduino, but I think this is something to try.

Your code uses analogWrite for PWM on pins 10 (leftSpeedPin) and 11 (rightSpeedPin).  The Arduino Duemilanove has six pins that work with PWM. This post was pretty informative. PWM uses different processor timers for different pins.

Pin 10 uses Timer 1 and pin 11 uses Timer 2. Timer 2 is also used by pin 3, if you use analogWrite on that pin. Since it is OK (in fact, good) to have your two motors run at a shared frequency for PWM, you will use less resources if you move leftSpeedPin to pin 3.

Now both of your PWM pins will use Timer 2. This should free up some timer resources, and may help.

I have to run now. Can you try this and see if it help? I'll try to check back later.

Maybe someone more knowledgable than I can assist too.

I tried switching the pins around like this:

#define servoPin     13         // Servomotor on pin D12.

  #define pingpin      12         // Ping ultrasonic sensor on pin D13.

  #define redled        11         // 2 drive motors, motor driver SN754410NE

  #define whiteled      10


  #define leftSpeedPin   5       // Left motor speed control

  #define leftmotorpin1  2        // Left motor direction 1 

  #define leftmotorpin2  4        // Left motor direction 2


  #define rightmotorpin1 7        // Right motor direction 1

  #define rightmotorpin2 8        // Right motor direction 2

  #define rightSpeedPin  6       // Right motor speed control

It had the same problems, i tried putting left speed pin to pin 3 and same thing. darn

With both the Sharp IR sensor on my SHR+ bot and the EZ4s on my current project I occasionally receive high values randomly. With the SHR it stops and looks around, just like yours. The programming with the EZ4s just make a servo twitch. Both are driven by PICAXEs. I'll be watching this thread expectantly.