FreeDuino (Arduino) BOOT to Turn Left & Right

Discussion in 'Embedded Systems and Microcontrollers' started by mkbutan, Oct 28, 2012.

  1. mkbutan

    Thread Starter Senior Member

    Sep 30, 2008
    270
    16
    Hi
    Few Days back I brought an FreeDuino (ARDUINO) board ATMEGA 328P
    I manage to Move MY first Assembled CAR with the free codes online (https://www.sparkfun.com/products/9457) (http://bildr.org/2012/04/tb6612fng-arduino/)
    but I am not using this Motor Driver (1A Dual TB6612FNG) but using L293D Motor Driver

    I would like to move it Forward then Right-Forward , Left-Forward , Reverse Then Right-Reverse , Left Reverse or any other direction but it should come back to its Original PLACE from where it STARTED.

    Code ( (Unknown Language)):
    1. //motor A connected between A01 and A02
    2. //motor B connected between B01 and B02
    3.  
    4. int STBY = 10; //standby
    5.  
    6. //Motor A
    7. int PWMA = 3; //Speed control
    8. int AIN1 = 9; //Direction
    9. int AIN2 = 8; //Direction
    10.  
    11. //Motor B
    12. int PWMB = 5; //Speed control
    13. int BIN1 = 11; //Direction
    14. int BIN2 = 12; //Direction
    15.  
    16. void setup(){
    17.   pinMode(STBY, OUTPUT);
    18.  
    19.   pinMode(PWMA, OUTPUT);
    20.   pinMode(AIN1, OUTPUT);
    21.   pinMode(AIN2, OUTPUT);
    22.  
    23.   pinMode(PWMB, OUTPUT);
    24.   pinMode(BIN1, OUTPUT);
    25.   pinMode(BIN2, OUTPUT);
    26. }
    27.  
    28. void loop(){
    29.   move(1, 255, 1); //motor 1, full speed, left
    30.   move(2, 255, 1); //motor 2, full speed, left
    31.  
    32.   delay(1000); //go for 1 second
    33.   stop(); //stop
    34.   delay(250); //hold for 250ms until move again
    35.  
    36.   move(1, 128, 0); //motor 1, half speed, right
    37.   move(2, 128, 0); //motor 2, half speed, right
    38.  
    39.   delay(1000);
    40.   stop();
    41.   delay(250);
    42. }
    43.  
    44. void move(int motor, int speed, int direction){
    45. //Move specific motor at speed and direction
    46. //motor: 0 for B 1 for A
    47. //speed: 0 is off, and 255 is full speed
    48. //direction: 0 clockwise, 1 counter-clockwise
    49.  
    50.   digitalWrite(STBY, HIGH); //disable standby
    51.  
    52.   boolean inPin1 = LOW;
    53.   boolean inPin2 = HIGH;
    54.  
    55.   if(direction == 1){
    56.     inPin1 = HIGH;
    57.     inPin2 = LOW;
    58.   }
    59.  
    60.   if(motor == 1){
    61.     digitalWrite(AIN1, inPin1);
    62.     digitalWrite(AIN2, inPin2);
    63.     analogWrite(PWMA, speed);
    64.   }else{
    65.     digitalWrite(BIN1, inPin1);
    66.     digitalWrite(BIN2, inPin2);
    67.     analogWrite(PWMB, speed);
    68.   }
    69. }
    70.  
    71. void stop(){
    72. //enable standby  
    73.   digitalWrite(STBY, LOW);
    74. }


    I have 2 DC Gears Motors on a cheese on pin 8,9 ,11 & 12
    with FREEDUINO Board

    But don't know what to do with pin no 3 & 5 ??? & pin no 10 ???
    which is for Speed control & standby respectively ..


    can any one guide me how to code for the above requirement
    Thanks in advance
     
    Last edited: Oct 28, 2012
  2. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    You can hook those to the en pins of the L293 The L293 can be used
    the same way as the one the code was made for
     
    mkbutan likes this.
  3. mkbutan

    Thread Starter Senior Member

    Sep 30, 2008
    270
    16
    Thanks
    be80be for your ans.
    you mean to say that the pin no 3 & 5 of the ARDUINO to pin no 1 & 9 to the L 293 respectively & pin no 10 ???
    which is for standby .....
     
Loading...