How to get DC motor to alternate polarity

Hello, I am having trouble getting the Andruino to operate a DC motor in both directions. I have attempted several labs using the H Bridge and some without. But the only way I can get the motor to spin is to directly connect one side of the DC motor to the 5v terminal and the other to the GND terminal. Here are the different labs I tried.

int motorPlus = 10;
int motorMinus = 11; (one side of the motor is plugged directly to pin 10 and
and the other in pin 11. Note, I can add an led light
void setup() { by moving one of the jumper wires over one spot, adding
pinMode(motorPlus,OUTPUT); the light. This means that the power is flowing through the
pinMode(motorMinus,OUTPUT); the LED then through both sides of the motor and then
} back to the Andruino. The LED flashes at 2 second interval
but the motor will not spin.
void loop(){
//AntiClockwise
digitalWrite(motorPlus,HIGH);
digitalWrite(motorMinus,LOW);
delay(2000);
digitalWrite(motorPlus,LOW);
digitalWrite(motorMinus,HIGH);
delay(2000);

}

I have also tried using an H bridge but it fails as well. As stated the only way I can get the motor to spin is to directly connect it to the 5v pin and GND pin. Please help

Post a link to the datasheet for your H-Bridge.

If you have connected things correctly then the code looks like it should work.

...R

Simple setup, one pin to one side of the motor, the other pin to the other side of the motor. LED will blink but motor will not spin. Again, motor works if jumpers are plugged into 5v and GND. So I am lost.

The digital pins can only provide very low currents, far too little for a motor. You cannot run motors directly from them and you may already have damaged the pins you've tried it with.

You said you tried with an H-bridge which is what you need. What H-bridge was it and where is the code you used with that? What happened?

Steve

H bridge is the way to go , there are usually examples to go with them too

Hello, I have the below code and configuration on a Andruino UNO3.

int motor1 = 2;
int motor2 = 3;

void setup() {
pinMode(motor1,OUTPUT);
pinMode(motor2,OUTPUT);
}

void loop(){
//AntiClockwise
digitalWrite(motor1,HIGH);
digitalWrite(motor2,LOW);
delay(5000);
digitalWrite(motor1,LOW);
digitalWrite(motor2,HIGH);
delay(5000);

}

I am getting 4.99v and -4.99v. But it barely spins the motor (literally only a couple of mm) but when I hook the motor directly to the 5v and GND pins it spins the motor just fine. Any thoughts?

Please post links to the motor driver, the motor and post a hand drawn (not Fritzing) wiring diagram.

Never power a motor or servo from the Arduino 5V pin. You can destroy the Arduino that way.

Right now it is a simple config... pin 2 to breadboard then to one side of the motor, pin 3 goes to breadboard then to the other side of the motor.

Using the following code:
int motor1 = 2;
int motor2 = 3;

void setup() {
pinMode(motor1,OUTPUT);
pinMode(motor2,OUTPUT);
}

void loop(){
//AntiClockwise
digitalWrite(motor1,HIGH);
digitalWrite(motor2,LOW);
delay(5000);
digitalWrite(motor1,LOW);
digitalWrite(motor2,HIGH);
delay(5000);

}

You can also destroy the Arduino doing this:

motor works if jumpers are plugged into 5v and GND

Please Google "arduino motor control" for tutorials before you destroy all your equipment.

Do not double post.

As I said in your last thread How to get DC motor to alternate polarity - Motors, Mechanics, Power and CNC - Arduino Forum YOU CANNOT DRIVE MOTORS DIRECT FROM THE DIGITAL PINS.

Which part of that is too difficult to understand?

Steve

Jason791:
Simple setup, one pin to one side of the motor, the other pin to the other side of the motor.

You are not seriously connecting Arduino I/O pins directly to a motor, are you? You will grossly overload your Arduino and may already have caused permanent damage.

You MUST control a motor through a h-bridge that is designed to provide the current required by the motor.

...R

Ok, I have configured with a H Bridge like shown in the attachment, The code for the Arduino is this:

const int motorPin1 = 2; // Pin 14 of L293
const int motorPin2 = 3; // Pin 10 of L293
void setup() {
//Set pins as outputs
pinMode(motorPin1, OUTPUT);
}
void loop() {
//This code will turn Motor forward for 2 sec.
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
delay(3000);
//This code will turn Motor reverse for 2 sec.
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
delay(3000);
}

But when I hook it up I am only getting .41 volts and .02 volts as it switches polarity.

Jason791:
Ok, I have configured with a H Bridge like shown in the attachment, The code for the Arduino is this:

const int motorPin1 = 2; // Pin 14 of L293
const int motorPin2 = 3; // Pin 10 of L293
void setup() {
//Set pins as outputs
pinMode(motorPin1, OUTPUT);
}
void loop() {
//This code will turn Motor forward for 2 sec.
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
delay(3000);
//This code will turn Motor reverse for 2 sec.
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
delay(3000);
}

But when I hook it up I am only getting .41 volts and .02 volts as it switches polarity.

What are you using to measure? You are measuring a pulsing signal.

Paul

Your code does not match your diagram. The pin numbers are all mixed up. What do you actually have connected and where?

The supply ground and the Arduino ground must be connected. And both motorPins need to be set as OUTPUT.

Steve

Steve, do you have a schematic that I can use to hook up a DC motor. The goal of this project is to get a DC motor to move a wire about 3cm in one direction... Pause. then move it the other direction then pause... I have tried several setups using an H bridge but none of them work

thanks in advance

Jason

Image from Reply #11 so we don't have to download it. See this Simple Image Guide

...R

Very likely, the wimpy L293D and/or the motor power supply can't handle the current required by the motor.

But since you can't be bothered to post any details, that is just a guess.

Jason791:
Steve, do you have a schematic that I can use to hook up a DC motor.

The schematic you posted is fine. All you need to do is wire it up exactly like that and write code that corresponds to it. Then provided your power supply and your DC motor are suitable to be used with an L293D it will work.

Steve