Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save gurdeepsinghiet/b6c32fc1618e64501da44ef0ba7c3085 to your computer and use it in GitHub Desktop.

Select an option

Save gurdeepsinghiet/b6c32fc1618e64501da44ef0ba7c3085 to your computer and use it in GitHub Desktop.

Revisions

  1. @EinsteinUnicorn EinsteinUnicorn revised this gist Oct 14, 2014. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion 2WD Arduino with Bluetooth
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    /* Becky Button. This code is made such that the motor 1 (m1p1 m1p2) is on the left and Motor 2 (m2p1, m2p2) is on the right.
    I will be posting an instructables soon on how to make this work, with all of the schematics and such.*/



    int m1Pin1 = 3; // pin 2 on L293D IC
    int m1Pin2 = 4; // pin 7 on L293D IC
    int enablePinm1 = 5; // pin 1 on L293D IC
    @@ -51,7 +56,7 @@ void loop()
    flag=1;
    }
    }
    // if the state is '2' the motor will turn left
    // if the state is '2' the bot will turn left
    else if (state == '2') {
    digitalWrite(m1Pin1, HIGH); // set pin 2 on L293D high
    digitalWrite(m1Pin2, LOW); // set pin 7 on L293D low
  2. @EinsteinUnicorn EinsteinUnicorn created this gist Oct 14, 2014.
    63 changes: 63 additions & 0 deletions 2WD Arduino with Bluetooth
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    int m1Pin1 = 3; // pin 2 on L293D IC
    int m1Pin2 = 4; // pin 7 on L293D IC
    int enablePinm1 = 5; // pin 1 on L293D IC
    int m2Pin1 = 6;
    int m2Pin2 = 7;
    int enablePinm2;
    int state;
    int flag=0; //makes sure that the serial only prints once the state

    void setup()
    {
    // sets the pins as outputs:
    pinMode(m1Pin1, OUTPUT);
    pinMode(m1Pin2, OUTPUT);
    pinMode(m2Pin1, OUTPUT);
    pinMode(m2Pin2, OUTPUT);
    pinMode(enablePinm1, OUTPUT);
    pinMode(enablePinm1, OUTPUT);
    // sets enablePin high so that motor can turn on:
    digitalWrite(enablePin, HIGH);
    digitalWrite(enablePin, HIGH);
    // initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
    }

    void loop()
    {
    //if some date is sent, reads it and saves in state
    if(Serial.available() > 0){
    state = Serial.read();
    flag=0;
    }
    // if the state is '0' the DC motor will turn off
    if (state == '0') {
    digitalWrite(m1Pin1, LOW); // set pin 2 on L293D low
    digitalWrite(m1Pin2, LOW); // set pin 7 on L293D low
    digitalWrite(m2Pin1, LOW);
    digitalWrite(m2Pin2, LOW);
    if(flag == 0)
    {
    Serial.println("off");
    flag=1;
    }
    }
    // if the state is '1' the bot will turn right
    else if (state == '1') {
    digitalWrite(m1Pin1, LOW); // set pin 2 on L293D low
    digitalWrite(m1Pin2, HIGH); // set pin 7 on L293D high
    if(flag == 0){
    Serial.println("Motor: right");
    flag=1;
    }
    }
    // if the state is '2' the motor will turn left
    else if (state == '2') {
    digitalWrite(m1Pin1, HIGH); // set pin 2 on L293D high
    digitalWrite(m1Pin2, LOW); // set pin 7 on L293D low
    if(flag == 0){
    Serial.println("Motor: left");
    flag=1;
    }
    }
    }