DC motors on the wheels and my Arduino robot can't move on a straight line

Hi everyone.

I'm trying to make an obstacle avoiding robot. I have two wheels with DC motors connected to an L298N which, on its turn, is connected to an Arduino Uno.

The Arduino can have the wheels spin one direction or the other, or not at all.

The thing is that I can't get my robot to move on a straight line since one motor always seems to spin slightly quicker than the other.

I tried to solve this by coding, trying to adjust the spinning velocity of each motor/wheel, but with no success. I still can't have my robot move on a straight line.

I suppose, I can use Continuous Rotation Servos but I need to know. Is there a way to solve my problem keeping to the DC motors?

Thanks!

Did you use a set of pins with the same PWM frequency. Pin 5 and 6 are ~1000Hz, and the others are ~500Hz.

If that alone doesn't help, try swapping the motor drivers. The L298 is an old chip with a high dropout voltage. One might be worse than the other. Leo..

robotron: I tried to solve this by coding, trying to adjust the spinning velocity of each motor/wheel, but with no success. I still can't have my robot move on a straight line.

Normally, something that can't think for itself, or has no built-in rule or algorithm to closely follow a particular path ........ well..... is not going to be able to follow that path. Or at least will deviate from the desired path after a certain amount of time.

If you want the robot to go relatively straight without any special guidance, then a trial and error approach might be needed --- where you keep offsetting the input (a bit at a time) on one of the wheel motors, until the robot goes more or less straight. It might then go straight for some amount of distance.

But..... also, going straight is one thing. And going straight in the "correct direction" is another thing. For example, just say that one wheel is slower to move than the other (at the beginning), and then a control system eventually equalises the wheel velocities. But the initial difference in velocity (before the equalisation occurs) could mean that the robot starts moving off in the wrong direction.

A common problem with motors. Two seemingly identical motors having the same voltage applied to each will not turn at the same speed because of several mechanical and electrical differences, such as friction, brush wear, rotor balance, and on and on and on... In order for your platform to travel a straight line you will need feedback from each motor so that motor speed can be determined. When the controller knows the speed of each motor it can make adjustments via PWM to each motor to keep them both at the same speed. One method would be to establish a "set point" for a particular speed and let the controller adjust both motors to maintain that set point. You can then change the speed of the platform by just changing the set point.