Can't Get Motor to Work, Tried Everything

Hello, I am new to Arduino but not to programming. I have got LEDS to blink in patterns and thats about it. I've been trying for days to get a DC motor or servo motor to work correctly. The closest I have got is a servo to twitch and vibrate while plugged into my Arduino Uno directly, no shield. I purchased a Sainsmart Motor Shield in hopes that it would make it easier to drive motors. Unfortunately I have had more luck using the Arduino alone. I have tried so many different things to be able to control a motor searching all over the web. Ultimately I would like to build a simple robot.

My question concerns the motor shield. It did not come with any instructions and I can't find a straight answer online.
Which ports on the Sainsmart motor shield correspond to which Arduino pins? Whenever I plug both leads of my dc motor into all combinations of the holes on the shield, nothing happens. Also, the leads are very loose in these holes, how am I suppose to do anything with the leads falling out?

Here is the latest code I have used:

void setup() {

//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin

}

void loop(){

//forward @ full speed
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins the motor on Channel A at full speed

delay(3000);

digitalWrite(9, HIGH); //Eengage the Brake for Channel A

delay(1000);

//backward @ half speed
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 123); //Spins the motor on Channel A at half speed

delay(3000);

digitalWrite(9, HIGH); //Eengage the Brake for Channel A

delay(1000);

}


Any help will be greatly appreciated.

Sainsmart Motor Shield Image.jpg

Arduinaught1:
Whenever I plug both leads of my dc motor into all combinations of the holes on the shield, nothing happens. Also, the leads are very loose in these holes, how am I suppose to do anything with the leads falling out?

Don't go poking things in random holes, the motors go into the screw terminal blocks, they should be labeled, the bare end is inserted into the opening then the top screw is tightened down to hold the wire securely.

That motor controller looks like the adafruit motor controller shield v1.2. You should be able to find all the info you need by searching for that instead of sainsmart. I'd be willing to bet it uses the same library.

If the connections between motor and Arduino shield are not really fastened and get loose while the shield and Arduino are powered your electronics can be fried due to the back EMF, caused by the inductance of a motor.

When a powered motor gets unconnected this back EMF can rise to values which destroy the still connected device (shield, Arduino).

So always either use screw terminals to connect a motor or solder it.

Looking at the attached image you have the shield v1 which is meanwhile substituted by v2.
Here is a detailed instruction, how to use v1 shield:

Addit:
pls use code tags </> when posting a code.
Reading the forum rules is also a good idea.

Motors need power, enough power, and the Arduino 5V supply is not enough. So do you
have a power supply able to power the motor shield?

Thanks for the help.

I didn't know that there were screws along the sides. I was plugging the wires from my DC motor into those holes next to each screw. So, I'm suppose to put a wire into the holes where the screws are and then screw the screw back into the hole while the wire is still in there to use that terminal? I could somehow touch the wire to the screw too such as soldering, right?

As for the servo motor, I connected it as shown in the picture I uploaded and ran the code I posted below.

I have the Arduino plugged into USB from my computer and nothing happens. I installed the Adafruit Motor Shield library and this code is from the "Motor Party" example. What am I doing wrong? I have a 9V battery I could connect to either the Arduino or Motor Shield, will this help?

[/// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

#include <AFMotor.h>
#include <Servo.h> 

// DC motor on M2
AF_DCMotor motor(2);
// DC hobby servo
Servo servo1;
// Stepper motor on M3+M4 48 steps per revolution
AF_Stepper stepper(48, 2);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor party!");
  
  // turn on servo
  servo1.attach(9);
   
  // turn on motor #2
  motor.setSpeed(200);
  motor.run(RELEASE);
}

int i;

// Test the DC motor, stepper and servo ALL AT ONCE!
void loop() {
  motor.run(FORWARD);
  for (i=0; i<255; i++) {
    servo1.write(i);
    motor.setSpeed(i);  
    stepper.step(1, FORWARD, INTERLEAVE);
    delay(3);
 }
 
  for (i=255; i!=0; i--) {
    servo1.write(i-255);
    motor.setSpeed(i);  
    stepper.step(1, BACKWARD, INTERLEAVE);
    delay(3);
 }
 
  motor.run(BACKWARD);
  for (i=0; i<255; i++) {
    servo1.write(i);
    motor.setSpeed(i);  
    delay(3);
    stepper.step(1, FORWARD, DOUBLE);
 }
 
  for (i=255; i!=0; i--) {
    servo1.write(i-255);
    motor.setSpeed(i);  
    stepper.step(1, BACKWARD, DOUBLE);
    delay(3);
 }
}]

Arduinaught1:
So, I'm suppose to put a wire into the holes where the screws are and then screw the screw back into the hole while the wire is still in there to use that terminal? I could somehow touch the wire to the screw too such as soldering, right?

No, the wire end goes in the opening, the screw on the top ( 90 degrees from the wire inserted) gets turned to lock down the wire.

and ...

pls read what @MarkT said:
You need more than 5V and you must not power it via the Arduino board!

You need at least 12V from an external power supply for the motor shield.
The amps are determined by the connected motor.

So - if the motor datasheet tells you, its max. current will be something like 1A - your power supply has to deliver at least 1A (normally I add 10-20% extra, when I buy a suitable power supply).

A 9V battery won't be able to give you the required power, maybe just for a very limited period of time.

rpt007:
You need at least 12V from an external power supply for the motor shield.
The amps are determined by the connected motor

The motor shield can run on a wide voltage range 4.5 to 25 volts.

The MOTOR should be selected not to exceed the current capability of you driver. (0.6 amps for the l293d or 1.2A peak).
The power supply should be capable of providing the current needed for peak draw.

If you have a motor rated for 5v then do not run it at 12. Run it at 5, just not from the arduino regulator.

for (i=0; i<255; i++) {
servo1.write(i);

No bueno

Arduinaught1:
I have the Arduino plugged into USB from my computer and nothing happens.

I have a 9V battery I could connect to either the Arduino or Motor Shield, will this help?

Powering arduino with USB is ok.

But, from what I can see at : ....click here...

On pages 39 and 49,

There is a JUMPER. Normally, I would remove the jumper. When the jumper is removed, it would allow me to use the USB or the DC power jack to continue to supply power to the arduino, and (at the same time) allow me to connect a DIFFERENT power supply for powering the motors. Where do we connect that DIFFERENT power supply? - It would be connected across the terminal block that says "+M GND" (lower-left terminal block on page 49, right next to the jumper - but make sure the jumper is removed). I believe that the jumper to be removed is JP1. The diagram also has a label called 'JP2', but that 'JP2' is probably a mistake.

The servo I am using is an FS90R continuous rotation servo

It says that it is rated at 6V and draws 550MA. I've powered the arduino from a dc wall supply and still nothing.
I'm pretty sure it is a power issue at this point, but I'd like to know if the code is the problem. Is the code I posted correct for running this servo plugged into servo port 1 as shown in the picture I uploaded.
If the code is fine, What type of power supply do I need to run this servo based on its specs in the URL I provided?

Thanks, the feedback has been very helpful

Did you carefully read the manual and can you exclude wiring problems now?
If yes, and the powering is ok, then you might have fried the driver by your first attempts to connect the motor (which one, servo, DC, stepper .. by the way?) through the holes.

Hope not, but re-reading your first post ...

I've done away with the motor shield and went back to making a circuit to power a dc motor on my breadboard. Here is the tutorial I am using:

I am using the code from the manual except I have taken out the serial element and just declare pin 3 and analogWrite pin 3 as 255 in the loop just to see if I hooked up everything correctly.

When I build this circuit, again, nothing happens. I tried powering the Arduino Uno through the USB and then the USB cabel. I uploaded a picture of the transistor I am using. The manual says to use a PN2222 transistor, could this be the reason why it is not working?

Here is the specs for my dc motor:

Since the only thing that is different with my circuit from the manual is the transistor, I assume this is the problem. Are transistors that different from one another?

the motor you show has a stall current pf 3.2A. - voltage not shown, but 5v should get it spinning

I guess it will take a good proportion of this when driving a reasonable load.

An arduino output pin will only supply 0.04A . The arduino on board regulator will only supply about 0.05A.

The 2N2222 is a small tansistor - will handle only about 0.1A.

So : get a suitable big power supply. Get logic level power MOSFET to control the power

Until your hardware has a chance of working, fiddling with code will get you nowhere.

regards

Allan.

Are transistors that different from one another?

YES - thousands/millions of different transistors with thousands/millions of different characteristics (voltage, current, gain etc.).

I think at your apparently given level of electronic skills you should step back a little and start with smaller devices and get them operating as you intend. Only after that go with the bigger guys.

Otherwise you will be stumbling from one disaster into another one.

And, from a distance it is pretty hard to assist you when you are not sensing what information we need to help you and have to go on a forensic path with you, which will take a very long time until you got all the electronic basics which you don't have (yet).

I'm still laughing at "tried everything". There's literally no point in suggesting things to try- he's already tried what you said. Can't you read? :slight_smile: