Pages: [1]   Go Down
Author Topic: L293d motor controller problems  (Read 960 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

L293d motor controller problems.  I am trying to build a circuit using the L293d h-bridge. I need bidirectional control of two small dc motors. I have tried circuit after circuit from the internet, and the best I have done is to get control in one direction only.  Most of the circuit and programs I have tried had problems. My final goal is to use an  arduino nano with my homebuilt L293 chip. I was originally trying to get it to work with a Uno, but for some reason the serial com port kept changing and dropping out, which is another matter.  Right now Im trying to get it to work with a mega.  But for some reason, any of the programs.  The below code seems to only respond to:  digitalWrite(motor1Pin1, LOW);   // set pin 2 on L293D low
                                                                                digitalWrite(motor1Pin2, HIGH);  // set pin 7 on L293D high
I can't get the motors to reverse! 
Does anyone have or know of a TESTED circuit diagram AND corresponding program that works, forward, and reverse.
I have spent many hours trying to get this to work.  Please don't suggest a bought motor shield, as I am working with students, and each student needs to pay for parts, and we need to keep the cost as low as possible,
Thanks for ANY help!
one of the programs include:
void loop() {
  // if the switch is high, motor will turn on one direction:
  if (digitalRead(switchPin) == HIGH) {
    digitalWrite(motor1Pin1, LOW);   // set pin 2 on L293D low
    digitalWrite(motor1Pin2, HIGH);  // set pin 7 on L293D high
  }
  // if the switch is low, motor will turn in the opposite direction:
  else {
    digitalWrite(motor1Pin1, HIGH);  // set pin 2 on L293D high
    digitalWrite(motor1Pin2, LOW);   // set pin 7 on L293D low
  }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48569
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am trying to build a circuit using the L293d h-bridge.
Code is useful AFTER you have a proper circuit. You haven't shown a circuit yet, so reviewing the code is premature.
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 86
Posts: 3487
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this, and make SURE everything is properly connected. Also post your full code.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please excuse my ignorance, but Im very rusty in electronics, just getting back into after way to many years. 
I have seen this circuit also. I know Im asking a lot but if I could see what pins go to which specific pins on the arduino, AND a program that works with that specific circuit configuration, It would be GREAT.
Thanks so much for your reply.
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 86
Posts: 3487
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have to post your code so far. The problem might be the code and not with the circuit. Any two I/O pins will do, but pins labeled as PWM will allow you have control of the speed.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
    }
  }
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 86
Posts: 3487
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 86
Posts: 3487
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: February 25, 2013, 03:31:32 pm by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Pages: [1]   Go Up
Jump to: