0

A simple DC motor switch... that doesnt work! Why?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

A simple DC motor switch... that doesnt work! Why?

by kucza on Mon Mar 23, 2009 6:34 pm

Hi!

Im kind of new with the Arduino...

I have run into some problems with my little code.. I trying to get a DC motor run back and forward with 2 buttons.

Im using a H-bridge L293NE.

I have wired it like this http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg

Motor Logic Pin 1 to pin 2 on the Arduino
Motor Logic Pin 2 to pin 3 on the Arduino

And here is my code

Code: Select all | TOGGLE FULL SIZE
int backPin = 2;      // back input
int forwardPin = 3;   // forward input
int motor1Pin = 4;    // H-bridge leg 1 (pin 2, 1A)
int motor2Pin = 5;    // H-bridge leg 2 (pin 7, 2A)
int enablePin = 9;    // H-bridge enable pin

void setup() {
  // set the back/forward pins as an input:
  pinMode(backPin, INPUT);
  pinMode(forwardPin, 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 (digitalRead(backPin) == HIGH) {
    digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
    digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high
  }
 
 if (digitalRead(forwardPin) == HIGH) {
    digitalWrite(motor1Pin, HIGH);   // set leg 1 of the H-bridge high
    digitalWrite(motor2Pin, LOW);  // set leg 2 of the H-bridge low
  }
  else {
    digitalWrite(motor1Pin, LOW);  // set leg 1 of the H-bridge low
    digitalWrite(motor2Pin, LOW);   // set leg 2 of the H-bridge low
}

}


But my problem is that when i meassure between the two motor terminals, i get 5V in one direction, but only 2.5V in the other direction!

The 5V is correct, but why is it only pushing out 2.5v the other way?

What am i doing wrong?
kucza
 
Posts: 2
Joined: Mon Mar 23, 2009 6:29 pm

Re: A simple DC motor switch... that doesnt work! Why?

by franklin97355 on Mon Mar 23, 2009 8:46 pm

Have you tried testing with just wire bringing the chips pins high and low and see what the voltages are? That's where I'd start.

franklin97355
 
Posts: 21431
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: A simple DC motor switch... that doesnt work! Why?

by westfw on Mon Mar 23, 2009 9:18 pm

Motor Logic Pin 1 to pin 2 on the Arduino
Motor Logic Pin 2 to pin 3 on the Arduino

and "Ground" too, right? You MUST have share ground.
westfw
 
Posts: 1595
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: A simple DC motor switch... that doesnt work! Why?

by phil.drummond on Mon Mar 23, 2009 9:34 pm

Warning - I'm really new at this, but I can see something weird...
With reference to this page, your "IF / ELSE" syntax might be off.
And to expand on the Ground issue, the two circuits, motor bridge and Arduino need to be sharing the same +5 and GND source.
phil.drummond
 
Posts: 126
Joined: Sun Feb 08, 2009 4:57 pm

Please be positive and constructive with your questions and comments.