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