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
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.5 the other way?