Go Down

Topic: Problem driving motors with the adafruit motor shield (Read 1 time) previous topic - next topic

ke0aer


Hi, I am having a problem using the Adafruit motor shield. I am working on an autonomous robot that turns 180 degrees when it is 14 inches from the wall. The sonar sensor that I am using is the Maxbotix Ez0. When I upload my code, nothing happens. Motors don't turn, but the sonar does register accurate inch values.

here is my code:

#include <AFMotor.h>

AF_DCMotor motor1 (1);
AF_DCMotor motor2(2);

int SonarVal;

void setup() {
     Serial.begin(9600);
     motor1.setSpeed(255);
     motor1.run(RELEASE);
     motor2.setSpeed(255);
     motor2.run(RELEASE);
}

void gather() {
     SonarVal = analogRead(0);
}

void loop() {
     gather();
     
     
     
     if(SonarVal = 14) {
          motor1.run(FORWARD);
          motor1.setSpeed(200);
          motor2.run(RELEASE);
          motor2.setSpeed(200);
}

else {
     motor1.run(FORWARD);
     motor1.setSpeed(200);

     motor2.run(FORWARD);
     motor2.setSpeed(200);
     }
}

any help is appreciated!!

Thanks, ke0aer

johnwasser

Code: [Select]
    if(SonarVal = 14) {

You probably mean:

Code: [Select]
    if(SonarVal == 14) {
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

ke0aer

correct.

do you think that the batteries may be the problem?

johnwasser


do you think that the batteries may be the problem?


I can't tell that from the code and you have not mentioned anything about your batteries, motors, or wiring.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

oric_dan


correct.

do you think that the batteries may be the problem?
See this thread,
http://forum.arduino.cc/index.php?topic=255068.0

ke0aer

So basically power the arduino seperately from the motor shield
and don't use 9v batteries. Use larger nimh packs

TomGeorge

Hi, can you post a circuit diagram of your project please, CAD or picture in jpg, png or pdf format.
Also a picture of  your project please.
Have you tried just a simple test program that runs your motors forward, to see if your wiring and control procedures work/

Tom...... :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up