5

I'm using the Adafruit Motor Shield v2.3. I'm powering the Arduino with a USB cable and I'm powering the motor shield with a 9 volt battery.

I removed the vin pin, and I'm using this tutorial/code to make the DC motor spin.

I've tried 3 different kinds of DC motors, but none of them will do anything. The Arduino works for normal sketches, like lighting up LEDs, but I can't get the motors to work.

Any ideas?

Edit: I'm using Adafruit's "Motor Test" code from the Motor Shield v2 library, as shown below. The motor is on port 1.

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

#include <AFMotor.h>

AF_DCMotor motor(4);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");

  // turn on motor
  motor.setSpeed(200);

  motor.run(RELEASE);
}

void loop() {
  uint8_t i;

  Serial.print("tick");

  motor.run(FORWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i);  
    delay(10);
 }

  for (i=255; i!=0; i--) {
    motor.setSpeed(i);  
    delay(10);
 }

  Serial.print("tock");

  motor.run(BACKWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i);  
    delay(10);
 }

  for (i=255; i!=0; i--) {
    motor.setSpeed(i);  
    delay(10);
 }


  Serial.print("tech");
  motor.run(RELEASE);
  delay(1000);
}

enter image description here

6
  • You said "this tutorial/code" but there is nothing. Did you forget to add a link?
    – Jake C
    Commented Jan 27, 2016 at 5:07
  • @JakeC - Thanks, I had copied it from my reddit post. It's fixed now. Commented Jan 27, 2016 at 5:13
  • What motors are you using? Are they rated to run at 9 volts? How good is the connection to the motor? It looks like from the picture that the pins are shorting on the casing. Do you have a multi-meter? Have you checked the voltage of the battery?
    – Jake C
    Commented Jan 27, 2016 at 5:22
  • ACtually, ignore the above, according to Adafruit, you cannot use a 9V battery. See: learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/…
    – Jake C
    Commented Jan 27, 2016 at 5:22
  • 1
    As pointed out here countless times before, a 9v "transistor" battery is the wrong choice for most motor projects, as it has minimal current capability. Don't use it! Commented Jan 27, 2016 at 5:23

3 Answers 3

5

A couple of things I see...

1.) Your motor leads may be shorting out of the housing of the motor. make sure they are not.

2.) You may have the motor on the wrong port for the given code:

On line 7 of the code it reads: AF_DCMotor motor(4);

So try switching physically your motor to port 4.

3.) Also, this board has an I2C address and I dont see that addressed anywhere in the code. You can check to see what the I2C address is with this code. It will also show you that the motor control board is indeed responding.

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
// 
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ ) 
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4) 
    {
      Serial.print("Unknow error at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}
2
  • Thanks for the code! I had soldered my pins on a bit crooked, so it was difficult to push them all the way in. When I ran your test, it couldn't find any I2C devices, and according to some Google results, that problem can be caused by various pin connectivity issues. I detached the motor shield from the Arduino, straightened out the pins, reinserted the motor shield as firmly as I could, and then everything started working! Commented Feb 9, 2016 at 2:16
  • 1
    @Pikamander2 :) Glad I could help!
    – Accentrix
    Commented Feb 12, 2016 at 2:36
3

Per the comments above, and the documentation from Adafruit, a 9V battery is insufficient for use with motors as they do not provide enough current.

6
  • Well, I've tried it with 2 AA batteries as well, but no luck. Here's what it currently looks like: i.imgur.com/IyTPnfx.jpg Commented Jan 27, 2016 at 6:04
  • 2 AA is only ~3V, nowhere near enough. Per the Adafruit guide, the Green LED needs to be lit brightly and from the pic it doesn't appear to be as bright. You would need to use at least 4 AA batteries to meet the 5V threshold and no more than 8 to stay under the 12 V maximum.
    – Jake C
    Commented Jan 27, 2016 at 6:07
  • Here it is with a Tenergy 9.6V 2000mAh battery (fully charged). It's lit up a lot brighter, but the motor still does nothing. i.imgur.com/Uursw2z.jpg Commented Jan 27, 2016 at 6:19
  • At this point I would update your original question with the new details, and my previous comments would apply there. Check the connections to the motor (they still don't very good). Maybe use a multi-meter to check the output of the board.
    – Jake C
    Commented Jan 27, 2016 at 6:23
  • Also, I've added the code to the original post. It's just the standard Adafruit motor example code, with no modifications Commented Jan 27, 2016 at 6:24
2

I see that this is still not working even with a proper battery. My next best guess is you need to update your library:

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

#include <AFMotor.h>

Judging by 2009 and AFMotor.h you have a copy of an old version of the library. I recommend getting the latest version and following the official tutorial.

2
  • The issue turned out to be that my bent pins weren't pushed all the way in to the Arduino, so Accentrix's answer was the most helpful. Still, thanks for the link, I hadn't noticed that I was using an old library. Commented Feb 9, 2016 at 2:17
  • This was my problem. For the old version of the adafruit motor shield board, the header is named "AFMotor.h". Mine is the Adafruit motor shield v2 and the correct header file is named "Adafruit_MotorShield.h". If you make this mistake then the problem is exactly as described, everything looks like it should work but nothing happens.
    – Self Dot
    Commented Dec 18, 2022 at 12:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.