L293D H-Bridge problem

Ok heres the problem, no matter what I do I can't get the H-bridge to work properly.

I've triple checked my connections, here is the test code i'm using


  // h bridge test
 
  const int switchPin = 12;    // switch input
  const int motor1Pin = 7;    // H-bridge leg 1 (pin 2, 1A)
  const int motor2Pin = 6;    // H-bridge leg 2 (pin 7, 2A)
  const int ledPin = 13;      // LED
  const int enablePin1 =8;    // Enable motor 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(ledPin, OUTPUT);

    // set enablePin high so that motor can turn on:
   
    digitalWrite(enablePin1, HIGH);
 
    // blink the LED 3 times. This should happen only once.
    // if you see the LED blink three times, it means that the module
    // reset itself,. probably because the motor caused a brownout
    // or a short.
    blink(ledPin, 3, 100);
  }

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

  /*
    blinks an LED
   */
  void blink(int whatPin, int howManyTimes, int milliSecs) {
    int i = 0;
    for ( i = 0; i < howManyTimes; i++) {
      digitalWrite(whatPin, HIGH);
      delay(milliSecs/2);
      digitalWrite(whatPin, LOW);
      delay(milliSecs/2);
    }
  }

What’s the schematic? Code

What’s the schematic? Code seems fine at first glimpse.

Since I’ve yet to figure out

Since I’ve yet to figure out how to post pics I’ll just describe it. 

 

Pin 1 of L293 goes to pin 8 on Arduino

Pin 2 "   "        "      to pin 7       "

Pin 3                      to Motor +

Pins 4 and 5 to ground

pin 6                       to Motor -

Pin 7                      to Pin 6

Pin 8                      to battery Pos 

Pin 9 thru 15 unused

Pin 16 to  +5vdc on Arduino

Arduino, L293, battery all on same ground plane

 

Hope thats clear

how exactly it does not

how exactly it does not work properly? Are you getting any motion at all?

It on moves in one direction

It on moves in one direction when the switch is pressed it stops.

Everything looks pretty much

Everything looks pretty much good.

I would try following:

I’m not sure about your switch circuit, but if you connect it strait between arduino pin and ground, you should add

digitalWrite(switchPin, HIGH); after pinMode(switchPin, INPUT); to enable internal pullup resistor.

Most probably you do not really need enable pin on L293D, so you could just connect it to battery +

Cannot think about anything else so far. btw what kind of motors are you using? And if you could take a photo of your setup it would help us a lot.

 

I’m not sure about your

I’m not sure about your switch circuit, but if you connect it strait between arduino pin and ground, you should add

digitalWrite(switchPin, HIGH); after pinMode(switchPin, INPUT); to enable internal pullup resistor.

 

Thanks for the tip.

 

what kind of motors are you using?

I’m using motors from a cheap walmart rc truck, they ran on 2 AA batteries and have caps across they’re + and -solder points.

How do I post pics?

How do I post pics?

See this help page for how

See this help page for how to post pictures.

https://www.robotshop.com/letsmakerobots/node/22529

I would suggest to connect

I would suggest to connect all 4 GND pins (4,5,12,13) . Don’t know, if they are internally connected or not, nor if this can cause any problems.

What kind of battery and motor you’re using? Switching a motor from full speed forward to full speed reverse isn’t wise. That could result in a voltage drop, that could cause a controller reset. Better use PWM and ramp the motor down to zero, reverse direction, than ramp up to full speed.

I haven’t gotten that far

I haven’t gotten that far yet! PWM is still confusing me as far as how to impliment it. I know it’s probally very simple but this is my first attempt at robot building.

 

I’ll get a picture up later this evening.

 

SubMicro

PWM is simple to use with an

PWM is simple to use with an Arduino. Just connect the Enable pin from the motor driver to an PWM capable pin (3,5,6,9,10,11). Use AnalogWrite(pwmval); to control the electrical power for the motor. A pwmval of 0 stops the motor, a pwmval of 255 runs the motor with fullspeed. Any pwmval between will result in a different speed between stop and full speed.

A ramp function can be used to accelerate the motor to a desired speed in a given time.

I’m writing on a PWM tutorial currently. Hope to get it finished this weekend.

 

Great I could use a tutorial

My_H-Bridge_bb_0.jpg

Great I could use a tutorial on PWM

Well I can't find the usb cable for my camera so here is something anyway!