Home stretch little help needed

Wild bull thank you I’ll give er a go, been making some progress alone,

I appreciate the help!


code compiled and loaded fine, when i run the serial monitor i get this odd response, never seen it before

It's a baud rate mismatch. Set the monitor to the rate in the code.

thank you ill try, youre great BTW, more people on forums like you are needed


odd i believe im correct here, same error, if wrong just let me know, im slowly
getting to understand in the code where things are

If they match, you should be ok. The code I posted was using 115200 though.

That garbage you're seeing is a typical symptom of a mismatch though, so I still suspect that that is the problem.

ahhh let me try that

that worked still not getting motors to move, im going to look for a very basic 3 motor sketch to make sure i have enough power right now off the battery pack and make sure they are fine. I ran a sketch before and they moved no problem, but perhaps the batteries are getting low.

i was able to see the audio on your skecth come through, so i will keep plugging away on this , THANK YOU!!

In the loop function there is a for loop that ramps up the motor speed. It will run through those speeds really quickly and then turn the motor off again. It may be worth putting a delay in the loop to see if that gets the motor running.

yup just tested the C cell batteries, 2 are at .77, 2 at 1.53 where they should be , ill change out the 2 dead ones and revisit the test


so weird, here we are again. Music receiving. No action on motors.
All new batteries all at 1.53 C cell batteriesx4. should handle the motors easily

ill try to track down a sketch to test the motors properly again. i ran one last time and the motors worked fine without issue. odd. ill keep trying. Thank you again, cant mention how much i appreciate it

i AM running a usb cable to power the UNO
and running the battery power TO the motorshield WITH the powerbridge clip REMOVED as instructed to {if i remember correctly}

ok so test skecth is fine, all 3 motors just verified,
on screenshot, i see the library is different that the main code, would it make sense to use library that i know works?
and then im guessing have to change DCMotor etc?
audio is still coming into the board and seen, just motors not reacting

i can feel im close now

Yup, take the working motor code and splice it into the code that detects sound.

think i got it all except for this one error which i dont understand, everything else i "think" is correct



/*
  Make a set of motors move to sound.
  Uses an Arduino Uno paired with the Adafruit Motor Shield v2.
  Written with the larger Big Mouth Billy Bass (or any animatronic) in mind.

   Modified by Joe Villegas on July 2018:
   -Defined all motors
   -Set variables (Ex: speed and sensitivity) for easier tweaking
   -Added support for the third motor in some Basses (Disable/Enable third motor use)
   -Included serial printouts for debugging and audio reading monitoring
   August 2018:
   -Added frantic mode (Maximum speed of motor movement, requires lots of power)

   Original information:
   Created by Donald Bell, Maker Project Lab (2016).
   Based on Sound to Servo by Cenk Özdemir (2012)
   and DCMotorTest by Adafruit
*/

// Libraries
#include <Wire.h>
#include <AFMotor.h>
#include <Adafruit_PWMServoDriver.h>

boolean legacyFish = true; //For older models that incorporate three motors
//* Motor speed variables
int motorDelay = 0; //Delay between sound readings and motor movements
//* Range: 1 - 255. Lower makes most movement.
int mouthMotorSpeed = 100;
int headMotorSpeed = 100;
int tailMotorSpeed = 25;

//Base system variables
int afmsFreq = 1600; //Default is 1600 (1.6kHz)
int audioSensitivity = 1023;

//Audio threshold variables
boolean headMovementEnabled = true; //TODO: head motor is unable to move the head itself (reglue?)
int staticThreshold = 1;            //To leave out any unwanted movement due to static
int mouthAudioThreshold = 10;
int tailAudioThreshold = 25;

//* ---- This section below don't touch

//Handled all by system (Best to not touch)
// Create the motor shield object with the default I2C address
AF_DCMotor AFMS = AF_DCMotor();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Select which 'port' M1, M2, M3 or M4.
AF_DCMotor *mouthMotor = AFMS.getMotor(1);
AF_DCMotor *headMotor = AFMS.getMotor(2);
AF_DCMotor *tailMotor = AFMS.getMotor(3);

// Some other Variables we need
int SoundInPin = A1;
//int LedPin = 12; //in case you want an LED to activate while mouth moves
int sensorPin = A1; // select the input pin for the audio signal input
int LedPin = 13;

boolean audioDetected = false;
int audioLastDetected = 0;
boolean bodyMoved;
bool modeFrantic = true;
int speedFrantic = 254;
int ping = 0;

void setup()
{
  if (modeFrantic == true)
  {
    motorDelay = 0;
    mouthMotorSpeed = speedFrantic;
    headMotorSpeed = speedFrantic;
    tailMotorSpeed = speedFrantic;
    Serial.println("Frantic mode");
  }
  Serial.begin(115200);
  Serial.println("sup b");
  AFMS.begin(afmsFreq);
  if (afmsFreq == 1600)
  {
    Serial.println("Adafruit Motor Shield booted");
  }
  else
  {
    Serial.println("AFMS enabled with frequency of " + String(afmsFreq));
  }
  // Set the speed to start, from 0 (off) to 255 (max speed)
  //mouth motor
  mouthMotor->setSpeed(mouthMotorSpeed);
  Serial.println("Mouth motor speed set to " + String(mouthMotorSpeed) + ".");
  mouthMotor->run(FORWARD); // turn on motor
  Serial.println("Mouth motor connected, attempted to move");
  mouthMotor->run(RELEASE);
  pinMode(SoundInPin, INPUT);
  pinMode(LedPin, OUTPUT);
  //head motor
  headMotor->setSpeed(headMotorSpeed);
  Serial.println("Head motor speed set to " + String(headMotorSpeed) + ".");
  headMotor->run(FORWARD); // turn on motor
  Serial.println("Head motor connected, attempted to move");
  headMotor->run(RELEASE);
  pinMode(SoundInPin, INPUT);
  //tail motor
  if (legacyFish == true)
  {
    tailMotor->setSpeed(tailMotorSpeed);
    Serial.println("Tail motor speed set to " + String(tailMotorSpeed) + ".");
    tailMotor->run(FORWARD); // turn on motor
    Serial.println("Tail motor connected, attempted to move");
    tailMotor->run(RELEASE);
  }
  Serial.println("Billy Bass is GO!");
}

void loop()
{
  if (MusicPlaying())
  {
    headMotor->run(FORWARD);
    for (int i = headMotorSpeed; i < 255; i++)
    {
      headMotor->setSpeed(i);
    }
    headMotor->setSpeed(0);
    bodyMoved = true;
    Serial.println("I'm ALIVEEEEE");
  }
}

bool MusicPlaying()
{
  int quietThreshold = 3;
  int sensorValue = analogRead(sensorPin);
  if (sensorValue > quietThreshold)
  {
    digitalWrite(LedPin, HIGH);
    Serial.println("Music IS playing!");
    Serial.print("sensorValue: ");
    Serial.println(sensorValue);
  }
  else
  {
    digitalWrite(LedPin, LOW);
    Serial.println("Music is NOT playing.");
    Serial.print("sensorValue: ");
    Serial.println(sensorValue);
  }
  return sensorValue > quietThreshold;
}

also a huge thank you for keeping replying to this thread, ive been learning everyday and decided to start learning a bit deeper for some more projects after this. You've been a big help, i do appreciate it

Here's the code I did before translated to the old motor library that works. I can compile it, but I don't have the fish to test it :wink:

#include <AFMotor.h>

boolean legacyFish = true; //For older models that incorporate three motors
//* Motor speed variables
int motorDelay = 0; //Delay between sound readings and motor movements
//* Range: 1 - 255. Lower makes most movement.
int mouthMotorSpeed = 100;
int headMotorSpeed = 100;
int tailMotorSpeed = 25;

//Audio threshold variables
boolean headMovementEnabled = true; //TODO: head motor is unable to move the head itself (reglue?)
int staticThreshold = 1;            //To leave out any unwanted movement due to static
int mouthAudioThreshold = 10;
int tailAudioThreshold = 25;

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

// Some other Variables we need
int SoundInPin = A1;
//int LedPin = 12; //in case you want an LED to activate while mouth moves
int sensorPin = A1; // select the input pin for the audio signal input
int LedPin = 13;

boolean audioDetected = false;
int audioLastDetected = 0;
boolean bodyMoved;
bool modeFrantic = true;
int speedFrantic = 254;
int ping = 0;

void setup()
{
  if (modeFrantic == true)
  {
    motorDelay = 0;
    mouthMotorSpeed = speedFrantic;
    headMotorSpeed = speedFrantic;
    tailMotorSpeed = speedFrantic;
    Serial.println("Frantic mode");
  }
  Serial.begin(115200);
  Serial.println("sup b");
  // Set the speed to start, from 0 (off) to 255 (max speed)
  //mouth motor
  mouth.setSpeed(mouthMotorSpeed);
  Serial.println("Mouth motor speed set to " + String(mouthMotorSpeed) + ".");
  mouth.run(FORWARD); // turn on motor
  Serial.println("Mouth motor connected, attempted to move");
  mouth.run(RELEASE);
  pinMode(SoundInPin, INPUT);
  pinMode(LedPin, OUTPUT);
  //head motor
  head.setSpeed(headMotorSpeed);
  Serial.println("Head motor speed set to " + String(headMotorSpeed) + ".");
  head.run(FORWARD); // turn on motor
  Serial.println("Head motor connected, attempted to move");
  head.run(RELEASE);
  pinMode(SoundInPin, INPUT);
  //tail motor
  if (legacyFish == true)
  {
    tail.setSpeed(tailMotorSpeed);
    Serial.println("Tail motor speed set to " + String(tailMotorSpeed) + ".");
    tail.run(FORWARD); // turn on motor
    Serial.println("Tail motor connected, attempted to move");
    tail.run(RELEASE);
  }
  Serial.println("Billy Bass is GO!");
}

void loop()
{
  if (MusicPlaying())
  {
    head.run(FORWARD);
    for (int i = headMotorSpeed; i < 255; i++)
    {
      head.setSpeed(i);
      delay(5);
    }
    head.setSpeed(0);
    bodyMoved = true;
    Serial.println("I'm ALIVEEEEE");
  }
}

bool MusicPlaying()
{
  int quietThreshold = 3;
  int sensorValue = analogRead(sensorPin);
  if (sensorValue > quietThreshold)
  {
    digitalWrite(LedPin, HIGH);
    Serial.println("Music IS playing!");
    Serial.print("sensorValue: ");
    Serial.println(sensorValue);
  }
  else
  {
    digitalWrite(LedPin, LOW);
    Serial.println("Music is NOT playing.");
    Serial.print("sensorValue: ");
    Serial.println(sensorValue);
  }
  return sensorValue > quietThreshold;
}

ill run this :grinning:

we;;, some awesome success
for the first time yet, the motors reacted to the audio.
the bad part is, they motors are not really "functioning" , seems like fast vibrating etc but i can feel and hear them well.

i am excited about actually getting motors to sense the audio, which means there's connection. now its just code tweaking etc. very promising, i was very excited lmao

That's good news. I'm not sure what to try next. You might make the delay in the for loop bigger.

How were the motors working when you ran the code @alto777 gave you?

it didnt work before but now did for the motor test sketch he revised, now to work on the main code to figure out why isnt communicating, but this is a big hurdle solved, thank you