-2

Can someone review my code to see if the code is the problem?

If nothing is wrong with the code, can someone look at my image and tell me if I set up the shield and the motors wrong and see if that's the problem?

enter image description here

Here's the picture of the Arduino setup:

Here's my code:

#include <AFMotor.h>

AF_DCMotor motor(1, MOTOR12_8KHZ);
AF_DCMotor motor2(2, MOTOR12_8KHZ);
AF_DCMotor motor3(2, MOTOR12_1KHZ);


void setup()  {
  Serial.begin(9600);
  Serial.println("Motor Test!");
  motor.setSpeed(20); //set speed of motor
  motor2.setSpeed(20); //set speed of motor
  motor3.setSpeed(25); //set speed of motor

}

void loop() {
  Serial.print("tick");
  motor.run(FORWARD);
  delay(2000);

  Serial.print("tock");
  motor.run(RELEASE);
  delay(5000);

  Serial.print("tack"); //first song starts 
  motor.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor.run(RELEASE);
  delay(14000);

  Serial.print("tack"); 
  motor.run(BACKWARD);
  delay(2000);

  Serial.print("tock"); //first song ends
  motor.run(RELEASE);
  delay(13000);

  Serial.print("tick");
  motor.run(FORWARD);
  delay(2000);

  Serial.print("tock"); //second song starts 
  motor.run(RELEASE);
  delay(24000);

  Serial.print("tick");
  motor.run(FORWARD);
  delay(2000);

  Serial.print("tock"); //second song ends 
  motor.run(RELEASE);
  delay(17000);

   Serial.print("tick");
  motor.run(BACKWARD);
  delay(2000);

  Serial.print("tock"); //third song starts 
  motor.run(RELEASE);
  delay(23000);

  Serial.print("tick");
  motor.run(BACKWARD);
  delay(2000);

  Serial.print("tock"); //third song ends 
  motor.run(RELEASE);
  delay(21000);

  Serial.print("tick");
  motor.run(FORWARD);
  delay(2000);

  Serial.print("tock");
  motor.run(RELEASE);
  delay(5000);

  Serial.print("tick");
  motor.run(FORWARD);
  delay(3000);

  Serial.print("tack"); //fourth song starts 
  motor.run(RELEASE);
  delay(5000);

  Serial.print("tack"); 
  motor.run(BACKWARD);
  delay(2000);

  Serial.print("tock"); //fourth song ends
  motor.run(RELEASE);
  delay(21000);
   //waving motor
  Serial.print("tick"); 
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(5000);

  //Waving motor
  Serial.print("tick"); //first song starts
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(BACKWARD);
  delay(2000);

   Serial.print("tock");
  motor2.run(FORWARD);
  delay(1000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock"); //first song ends
  motor2.run(RELEASE);
  delay(14000);

  Serial.print("tick"); 
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(5000);

  Serial.print("tack"); //Second song starts
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(BACKWARD);
  delay(2000);

   Serial.print("tock");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock"); //second song ends
  motor2.run(RELEASE);
  delay(15000);


  Serial.print("tick"); 
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(5000);

  Serial.print("tack"); //Third song starts
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(BACKWARD);
  delay(2000);

   Serial.print("tock");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tock"); //third song ends
  motor2.run(RELEASE);
  delay(14000);

  Serial.print("tick"); //fourth song starts
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(BACKWARD);
  delay(2000);

   Serial.print("tock");
  motor2.run(FORWARD);
  delay(1000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock"); //fourth song ends
  motor2.run(RELEASE);
  delay(7000);

  //dancing motor
  Serial.print("tock"); //first song starts
  motor3.run(RELEASE);
  delay(11000);

  Serial.print("tick"); 
  motor3.run(FORWARD);
  delay(22000);

  Serial.print("tock"); //first song stops //second song starts
  motor3.run(RELEASE);
  delay(16000);

  Serial.print("tick"); //Second song stops
  motor3.run(FORWARD);
  delay(28000);

  Serial.print("tock"); //Third song starts
  motor3.run(RELEASE);
  delay(15000);

  Serial.print("tick"); //Third song stops
  motor3.run(FORWARD);
  delay(33000);

  Serial.print("tock"); //fourth song starts
  motor3.run(RELEASE);
  delay(16000);

  Serial.print("tick"); 
  motor3.run(FORWARD);
  delay(5000);

  Serial.print("tock");
  motor3.run(RELEASE);
  delay(1000);

  Serial.print("tick"); //fourth song ends
  motor3.run(FORWARD);
  delay(16000);

  Serial.print("tock");
  motor3.run(RELEASE);
  delay(5000);
}
  • 1
    Unfortunately you didn't copy the error message, but only the message, that there is an error. There has to be more, which more specifically explains the problem. Include that in your question – chrisl Apr 2 at 20:07
  • Since it seems, that the problem is with uploading, try to upload without the motor shield connected – chrisl Apr 2 at 20:07
  • @chrisl yea I did its at the top of the discription, thats all the error says – Tommy Apr 2 at 20:30
  • And it dosent work without the motor sheild! – Tommy Apr 2 at 20:31
  • 1
    @Tommy At this point your question is a big mess. You edited it multiple times, also removing the error message, that describes your problem. Your question is not stated clear enough for this site (as this is not your first question, you should know by now, how to do it). It is your duty to track down the error to a specific part of your project. If you have problems with uploading, this has nothing to do with the code. You should use the blink example to solve this problem. Finally, when you can upload again, you can go back to your code. – chrisl Apr 3 at 9:35
1

As far as I can tell from the picture you share that you don't have an external power supply connect to the shield to drive the "12 DC motors".

Read https://learn.adafruit.com/adafruit-motor-shield/power-requirements for better understanding on how to power the motors.

| improve this answer | |
0

You are probably trying to load your code using Tools -> Burn Bootloader. Instead, you should use Sketch -> Upload, or shortcut CTRL + U or using the upload button:

enter image description here

| improve this answer | |
  • When I hit that arrow it says done uploading but the motors are not running – Tommy Apr 2 at 22:08
  • Now that's a different problem. Done uploading means, your code is uploaded. Why don't you debug your code and open a new question with what specific problem you are having? – Fahad Apr 2 at 22:12
  • how is that a different problem and why would I debug my code if there is no error with the code – Tommy Apr 2 at 22:13
  • I thought your problem was you couldn't upload your code. At least that's what your long Question Title says. – Fahad Apr 2 at 22:14
  • 3
    @Tommy, you are going about software development the wrong way .... there is absolutely no reason why your code should be any more than turning on one motor, in one direction, for one second .... you are trying to build a race car before you know how to tighten a bolt – jsotola Apr 3 at 0:23

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