• Build logs, Tutorials and Hacks

    Thursday, October 9, 2014

    Motor Driver Test on an Arduino

    Introduction


    There are prolly a billion tutorials for this and mine is prolly not the best but I am writing it anyways. Here is a piece of arduino code that can be used to test if your motor driver is connected correctly.



    Connections


    I am assuming that the motor driver L293D or L298 has been connected such that the Enable pin is high by default i.e. connected to VCC. In the next tutorial I will put up a circuit like how I think should be done. None the less, the direction 1 pin is connected to 12 pin of the Arduino and direction 2 pin is connected to 13 pin of the arduino.



    The Code


    The code is as follows:

    [code]
    /*!
    * \file motorTest.ino
    * \author Inderpreet Singh (google.com/+InderpreetSingh)
    * \license GPL2(see license.txt)
    *
    * \section Description
    *
    * \section HISTORY
    * v1.0
    *
    * \description This arduino firmware is used to test L293D motor Drivers
    * Change the Motor driver pins at the beginning and the rest
    * will work automatically.
    *
    * I put a lot of time and effort into our project and hence this copyright
    * notice ensures that people contribute as well as each contribution is
    * acknowledged. Please retain this original notice and if you make changes
    * please document them along with your details.
    *
    * The latest copy of this project/library can be found at:
    * https://github.com/inderpreet/
    *
    */
    // ----------------------------------------------------------------------------

    // Pin 13 has an LED connected on most Arduino boards.
    // give it a name:
    int led = 13;

    // L298D Pins
    int D1=12
    int D2=13
    //int D3=
    //int D4=
    //int E1=
    //int E2=

    // Direction Routines
    void motorStop(void){
    digitalWrite(D1,LOW);
    digitalWrite(D2,LOW);
    }

    void motor1CK(int t){
    digitalWrite(D1, LOW);
    digitalWrite(D2, HIGH);
    delay(t);
    motorStop();
    }

    void motor1ACK(int t){
    digitalWrite(D2, LOW);
    digitalWrite(D1, HIGH);
    delay(t);
    motorStop();
    }
    // the setup routine runs once when you press reset:
    void setup() {
    // initialize the digital pin as an output.
    pinMode(D1, OUTPUT);
    pinMode(D2, OUTPUT);
    }

    // the loop routine runs over and over again forever:
    void loop() {
    motor1CK(5); // Rotate motor Clockwise for 5 seconds
    motor1ACK(5); // Rotate motor Anticlockwise for 5 seconds
    }
    [/code]

    copy and paste the code in the arduino IDE and upload. Test and lemme know.


    Cheers

    No comments:

    Post a Comment