3 DC motor sketch error, simple, i thought?

a simple 3 motor test for my project, having to go back to drawing board , getting this weird error
can anyone help, im very sorry for dumb questions, i am VERY new to code, and not good.

screenshot attached for error as well as code embedded

#include <AFMotor.h>

#define NUM_MOTORS 3

AF_DCMotor(1, MOTOR12_1KHZ);
AF_DCMotor(2, MOTOR12_1KHZ);
AF_DCMotor(3, MOTOR34_1KHZ);

AF_DCMotor motors[NUM_MOTORS] = {head, mouth, tail};
void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
  for (int i = 0; i < NUM_MOTORS; i++) {
    motors[i].setSpeed(255);
  }
}

void runMotorOnOff(AF_DCMotor motor , int animationDelay = 500) {
  motor.run(FORWARD);
  delay(animationDelay);
  motor.run(BACKWARD);
  delay(5);
  motor.run(RELEASE);
  delay(animationDelay / 2);
}

void loop() {
  runMotorOnOff(head, 1000);
  runMotorOnOff(mouth, 500);
  runMotorOnOff(tail, 1000);
}

Hi,
What model Arduino are you using?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi,
I think you need to do this in assigning your motors

AF_DCMotor left_motor(1, MOTOR12_1KHZ);
AF_DCMotor right_motor(2, MOTOR12_1KHZ);
AF_DCMotor backleft_motor(3, MOTOR34_1KHZ);

Tom... :smiley: :+1: :coffee: :australia:

im using the UNO with the L293d motorshield, and yes im trying to understand the libraries etc, i have them all installed from what i underastand, i can see them in my list

i tried those changes and same issue / error on same line

Well I don't know what changes you made that didn't work.

This compiles, can't know if it does what you want.

#include <AFMotor.h>

#define NUM_MOTORS 3

AF_DCMotor  head(1, MOTOR12_1KHZ);
AF_DCMotor  mouth(2, MOTOR12_1KHZ);
AF_DCMotor  tail(3, MOTOR34_1KHZ);

AF_DCMotor motors[NUM_MOTORS] = {head, mouth, tail};

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
  for (int i = 0; i < NUM_MOTORS; i++) {
    motors[i].setSpeed(255);
  }
}

void runMotorOnOff(AF_DCMotor motor , int animationDelay = 500) {
  motor.run(FORWARD);
  delay(animationDelay);
  motor.run(BACKWARD);
  delay(5);
  motor.run(RELEASE);
  delay(animationDelay / 2);
}

void loop() {
  runMotorOnOff(head, 1000);
  runMotorOnOff(mouth, 500);
  runMotorOnOff(tail, 1000);
}

HTH and keep studying syntax!

a7

thanks it compiled and loaded, Thank you for your help
now i think a power supply issue as motors move barely at all
is that adjusted in the code ? attached is a video.... brand new c cell batteries around all tested at 1.53v

Seems plausible. No adjustment in code will compensate for an inadequate power supply.

Time to post a schematic of your project. Hand drawn is often better than what you'll come up with if you have to struggle with a real schematic drawing program. Please don't use Fritzing to do this. Pencil and paper...

a7

Here it is

So signal flow as far as everything else is fine, everything is registering except strong motor movement. So with everything else being fine, trying to figure out why the battery supply would be Insufficient. And yes, the Uno is plugged in separately.

Battery to the motor shield is coming from 4 - c cell batteries brand new , totalling 6volts.

Haha, I remember that drawing. Someone stressed the importance of labeling your signals and you took it to the next level…

There is no need to use dashed lines with a label repeatedly repeated along its length.

Otherwise, your diagram gives us something to work with.

Solid unlabeled lines between clearly labeled points woukd be easier on the eyes.

Part of the diagram is off the screen, and I think you’ve to,d us the C cells aren’t in your diagram but are attached to the motor shield - not sure what’s going on/represented by the block furthest on the left.

How much current will the motors draw when full on? How does the C cell battery stack do with that load? Do you have a meter you can use to spcheck voltages and currents?

a7

lol yes im trying haha.

C cell batteries are on the top left of the picture
Basically a 4 bank of C cell batteries totalling 6volt.

I think that’s my issue is not knowing these old motors in here what they require, although this project has been done lots with just this stock battery pack. , the talking fish is over 20 years old, but I know the motors themselves work fine. Hard to find documentation of what they are

Bro we’re good for test
I took it apart , cleaned up the terminals etc and were in business all motors work as per the test sketch.
Thank you for all your help. I’ll continue to pole away on my side

So it was as easy as dirty terminal connections? Nice!

Yay! Now it’s just software. :expressionless:

a7

did initial run w/code, same thing its odd. Audio registering into Arduino via serial monitor, no response from motors

now could it be the test sketch that works the motors fine, the library is not being used in the main code? im just trying to figure out now at the very end, when audio is being registered into the arduino why motors are not reacting to sound

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.