Go Down

Topic: L293d motor controller problems (Read 1 time) previous topic - next topic

waynek

This is the last hookup and program I tried..  from  http://itp.nyu.edu/physcomp/Labs/DCMotorControl
But I also want to be able to change the motors (2) directions via program, not via discrete switch..
Thanks again  Wayne
const int switchPin = 2;    // switch input
const int motor1Pin = 3;    // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 4;    // H-bridge leg 2 (pin 7, 2A)
const int enablePin = 9;    // H-bridge enable pin
void setup() {
    // set the switch as an input:
    pinMode(switchPin, INPUT);

    // set all the other pins you're using as outputs:
    pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);
    pinMode(enablePin, OUTPUT);
   // pinMode(ledPin, OUTPUT);

    // set enablePin high so that motor can turn on:
    digitalWrite(enablePin, HIGH);
  }
void loop() {
    // if the switch is high, motor will turn on one direction:
    if (digitalRead(switchPin) == HIGH) {
      digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
      digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high
    }
    // if the switch is low, motor will turn in the other direction:
    else {
      digitalWrite(motor1Pin, HIGH);  // set leg 1 of the H-bridge high
      digitalWrite(motor2Pin, LOW);   // set leg 2 of the H-bridge low
    }
  }

HazardsMind

Your code looks fine, so it is possible that your switchPin is in the wrong pin. Or, it could be your wiring is somehow wrong. Double check everything, and do a simple test. Get rid of the IF statement and just have the motor commands.

Isolate the problem.
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

waynek

Yep tried that..  got rid of the if statements in the following  lines of code
this seemed to work   digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
                               digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high

but this didnt:      digitalWrite(motor1Pin, HIGH);  // set leg 1 of the H-bridge high
                         digitalWrite(motor2Pin, LOW);   // set leg 2 of the H-bridge low

motor wouldnt run at all with the last two lines of code.

HazardsMind

#8
Feb 25, 2013, 07:23 pm Last Edit: Feb 25, 2013, 09:31 pm by HazardsMind Reason: 1
Ok so if motorPin2 is HIGH, it runs and if motorPin1 is HIGH, it does not. Sounds to me like a wiring issue. Try this, bypass the arduino altogether(disconnect it) and just put a jumper to one of those input pin on the L293d. I think they already have pull down resistors inside, so by just putting one input HIGH, the motor should run depending on whichever input is high.

Make sure your motor pins are 3 and 4, and not 4 and 5.
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Go Up