PROBLEM about REAL TIME

Hi guys,

motor(inA1, inA2, 1); //motor 1 rotate 1
motor(inB1, inB2, 1); //motor 2 rotate 1

I use this code to control 2 motors to make a car go ahead.

BUT 2 motors don't run at the same time: motor 1 runs first and a short time later motor 2 runs. That makes my car can not go straight ahead

I need a help! Anyone have solution for this problem?

I use this code to control 2 motors to make a car go ahead.

You call that function to control the motors. But, we have no idea what that function does. So, all we can say is that you need to fix that function to do what you want.

godivaPrima: I think it's far more likely that the motors aren't running at the same speed and/or that the tyres aren't exactly the same circumference. The fact that one motor fires up an infinitesimally tiny moment later than the other, I really don't see as an issue.

The space time between motor 1 and motor 2 is about from 0,1s to 0,5s, I guess. I think that's not a tiny moment. Maybe the problem is the speed as you said. I'll check it. Thanks for your suggestion

You really need to supply a bit more information. The two lines of code you posted tell us nothing. How are the motors hooked up? Directly to the Arduino (I hope not!)? If motors are hooked up to a driver is it an H bridge or a simple on-off transistor?
A diagram of how things are ACTUALLY hooked up, not how you think it is hooked up, would be helpful or a photo showing all the connections clearly.
Also, what is the power source for the motors? PLEASE don’t tell us it is a 9 Volt battery!

PaulS: You call that function to control the motors. But, we have no idea what that function does. So, all we can say is that you need to fix that function to do what you want.

Thanks for your ideas! Here is my function. It just takes responsbilities to control the direction of motors' rotation. I don't think it is the cause.

void motor(byte in1,byte in2,byte direction) { switch(direction) { case 0: //Stay digitalWrite(in1, LOW); digitalWrite(in2, LOW); break; case 1: //Rotate 1 digitalWrite(in1, HIGH); digitalWrite(in2, LOW); break; case 2: //Rotation 2 digitalWrite(in1, LOW); digitalWrite(in2, HIGH); break; } }

Due_unto: You really need to supply a bit more information. The two lines of code you posted tell us nothing. How are the motors hooked up? Directly to the Arduino (I hope not!)? If motors are hooked up to a driver is it an H bridge or a simple on-off transistor? A diagram of how things are ACTUALLY hooked up, not how you think it is hooked up, would be helpful or a photo showing all the connections clearly. Also, what is the power source for the motors? PLEASE don't tell us it is a 9 Volt battery!

6 volt (4 1,5-volt battery) actually!

I'll post all my project.

Thank you!

I don't see anything that would cause a noticeable delay, but try reversing the sequence and start motor B first. If motor A still starts first, you've eliminated software as the cause.

As a rule, you can't count on two motors running at the same speed without some feedback.