Go Down

Topic: Robot controlled by dual h bridge wont move for the life of me (Read 120 times) previous topic - next topic

FaresWheel

So i followed this tutorial of how to make a dual motor arduino robot (https://darkbluebit.com/arduino/robot-motor-control/).

It had a schematic, and I followed it. The schematic is with the SparkFun controller though, and I have the Pololu one, so some things had to be changed since the pins are different.

So I did this (schematic attached). I know the controller is sparkfun, but they don't have the pololu one, so here's a picture of the pins (https://darkbluebit.com/wp-content/uploads/2016/01/robot-hbridge3.jpg)

Code: [Select]
// Left motor
const int pinAIN1 = 5; //Direction
const int pinAIN2 = 4; //Direction
const int pinPWMA = 3; //Speed

// Right motor
const int pinBIN1 = 7;  //Direction
const int pinBIN2 = 8; //Direction
const int pinPWMB = 9;  //Speed

//H-Bridge Standby
const int pinSTBY = 6;

boolean leftMotor = 1;
boolean rightMotor = 0;

void setup() {
 pinMode(pinPWMA, OUTPUT);
 pinMode(pinAIN1, OUTPUT);
 pinMode(pinAIN2, OUTPUT);
 pinMode(pinPWMB, OUTPUT);
 pinMode(pinBIN1, OUTPUT);
 pinMode(pinBIN2, OUTPUT);
 pinMode(pinSTBY, OUTPUT);
}

void loop() {
 // acceleration
 for (int i = 0; i <= 255; i += 5) {
   motorDrive(leftMotor, 1, i);
   motorDrive(rightMotor, 1, i);
   delay(50);
 }
 delay(1700);

 // turn right
 motorStop(rightMotor);
 delay(1500);

 // go ahead
 motorDrive(rightMotor, 1, 255);
 delay(1000);

 // stop
 motorStop(leftMotor);
 motorStop(rightMotor);
 delay(300);  

 // turn around in place
 motorDrive(leftMotor, 0, 255);
 motorDrive(rightMotor, 1, 255);
 delay(3600);

 // stop
 motorStop(leftMotor);
 motorStop(rightMotor);
 delay(300);  

 // turn left in a circle
 motorDrive(leftMotor, 1, 180);
 motorDrive(rightMotor, 1, 255);
 delay(4000);

 // slow down
 for (int i = 255; i >= 0; i -= 5) {
   motorDrive(leftMotor, 1, i);
   motorDrive(rightMotor, 1, i);
   delay(55);
 }

 // stop
 motorStop(leftMotor);
 motorStop(rightMotor);
 delay(10000);
}

/*
 Drive a motor:
   - motorNumber: 0 left motor, 1 right motor
   - moveForward: motor direction (0 reverse, 1 forward)
   - motorSpeed: 0 to 255 ---> 0 = stop / 255 = max speed
*/
void motorDrive(boolean motorNumber, boolean moveForward, int motorSpeed) {
 boolean pinIn1;  //Relates to AIN1 or BIN1 (depending on the motor number specified)

 // direction to turn the motor
 //   clockwise: IN1 = HIGH and IN2 = LOW
 //   counter-clockwise: IN1 = LOW and IN2 = HIGH
 if (moveForward)
   pinIn1 = LOW;
 else
   pinIn1 = HIGH;

 // select the motor to turn, set the direction and the speed
 if (motorNumber == leftMotor) {
   digitalWrite(pinAIN1, pinIn1);
   digitalWrite(pinAIN2, !pinIn1);
   analogWrite(pinPWMA, motorSpeed);
 } else {
   digitalWrite(pinBIN1, pinIn1);
   digitalWrite(pinBIN2, !pinIn1);
   analogWrite(pinPWMB, motorSpeed);
 }

 // STBY must be high to enable motors
 digitalWrite(pinSTBY, HIGH);
}

// Stop the specified motor
void motorStop(boolean motorNumber) {
 if (motorNumber == leftMotor) {
   digitalWrite(pinAIN1, LOW);
   digitalWrite(pinAIN2, LOW);
 } else {
   digitalWrite(pinBIN1, LOW);
   digitalWrite(pinBIN2, LOW);
 }
}



I clicked verify, and it doesn't work. Nothing moves and the motors don't spin. The lights are glowing on the arduino, but not a budge. The video he posted has his wires a bit different than the schematic, like the ones from the controller to the diode being in the middle of the 2 instead of the top. I know for sure that the batteries and the motors aren't faulty. The arduino is powered by USB.

Can someone please help me?

slipstick

Clicking "Verify" just compiles the code to check it. You need to click "Upload" next to it to get the code transferred into the Arduino and run. Then it might do something.

Steve

FaresWheel

I've pressed verify and upload, but still no movement

slipstick

Try putting some serial prints in to see where it gets to in the code. If it's running through the code as you expect then the connections are wrong. It's way too hard to follow that Fritzing so I'll let you sort that out.

Steve

justone

That motor driver does not need external flyback diodes so just get rid of those.

Go Up