Pages: [1]   Go Down
Author Topic: turning right/left using arduinoduemilanove+l293d  (Read 1061 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey

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!

Code:
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()
{
   turn_right();
}
/************************************
forward means *t1=HIGH and *t2=LOW
*************************************/
void turn_right()
{
  
  digitalWrite(rt1,LOW);//right motor bckward
  digitalWrite(rt2,HIGH);
  digitalWrite(lt1,HIGH);//left motor forward
  digitalWrite(lt2,LOW);
  
  //digitalWrite(pwm2,HIGH);
  //digitalWrite(pwm,HIGH);
  analogWrite(pwm,127);
  analogWrite(pwm2,127);
  
  delay(100);//so that the condition for stopping is not reached before it even starts turning
 while(1)
  {
    if(condition for stopping the turning)//
    return;
  }
  
}

//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

analogWrite(blahblah_pin,xyz)

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24433
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24433
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thats what ive done:

<quote>
analogWrite(pwm,127);
analogWrite(pwm2,127);
</quote>
« Last Edit: December 26, 2009, 02:33:24 pm by k2s » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Coventry UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

k2s,

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.

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24433
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://www.thinklabs.in/resources/wp-content/uploads/2009/06/10-large-300x225.jpg
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: