turning right/left using arduinoduemilanove+l293d


i was trying to make my bot just turn right using l293d and 2 dc motors at the same position(at junction of a grid)[make the right whell go backward and left wheel go forward]. This is a simple code i came up with but the problem is , my left wheel starts rotating first and my right wheel starts after a lag. plz see if there is anything wrong... thx in advance!

int pwm2=6,rt1=11,rt2=12;//right motor
int pwm=9,lt1=1,lt2=2;//left motor

void turn_right();

void setup()
  //all pins are made OUTPUT

void loop()
forward means *t1=HIGH and *t2=LOW
void turn_right()
  digitalWrite(rt1,LOW);//right motor bckward
  digitalWrite(lt1,HIGH);//left motor forward
  delay(100);//so that the condition for stopping is not reached before it even starts turning
    if(condition for stopping the turning)//

//just read above, turn left and go forward functions will be easy if i figure out turn_right

my question is that in the function turn_right, once i give the command


does the blahblah_pin keep sending the pwm signal till the rest of the program... ie.. till while(1) condition is dissatisfied?

or do we have to keep calling the turn_right func repeatedly from loop?

analogWrite is a one-off - the setting is kept until the next analogWrite

so how do i implement pwm with arduino to control two motors simultaneously? can u help me with the code?

also if its a one off line.. then my wheels should move alternately.. in my case.. they both move simultaneously but the right wheel starts moving after a lag of about 3-4 secs

so how do i implement pwm with arduino to control two motors simultaneously?

Two consecutive "analogWrite"s to different pins.
The execution time between the two writes will (in a mechanical motor scale of things) be miniscule, and you won’t notice that the motors don’t quite start instantaneously.

thats what ive done:

analogWrite**(pwm**,127); analogWrite(**pwm2**,127);

i even tried using just one pwm pin which is connected to both the enable pins of the l293d. still same problem


Are you using geared motors?

If you are it's possible that you are suffering from backlash from the gears in the gearbox. 3 to 4 seconds is a bit much for backlash but something you can easily check out.

-- Martyn.

yes i am using geared motors.. what is backlash and how do i get rid of it?

3 or 4 seconds isn’t backlash.
It sounds more like your processor is resetting and then restarting.
You may need some decoupling/suppression - have a look at Grumpy Mike’s tutorials.

i dunno the model specifications.. got it in an iTRIx workshop.. heres a pic if its of any help


yea i think u may be right.. i found that tutorial...


ill try and implement it tom morn..

also.. do you think this can be averted by using two batteries? 1 for the arduino and the other for the motors?

thank you everyone.. i used two batteries and voila.. its all good..w00t