Balance Bot w/ keyestudio balance car shield

First Arduino project and am attempting to build a self balancing robot as a science project. Project has stalled and I don't know where to begin troubleshooting.

My bot is based on the Arduino UNO, Keyestudio Balance Car Shield (combines mpu6050 and L298P), 6V (4xAA) power supply, 6V DC motors with encoders.

Due to limited documents on keystudio, I am left guessing which wires connect to which on the motor encoder and where to begin programming. I figured I could cut and paste from various instructables but none have worked.

My next step was to test individual components on the shield. I am able to initialize and get output information from the mpu6050. The L298P is a different matter entirely. I have tried to spin the motors in both directions and varios speeds with no success. I assume that my wires are not connected correctly but am lost as to figure out how to fix them.

Any help is greatly appreciated.

My code for testing motor operation:

 L298N Motor Demonstration
 L298N-Motor-Demo.ino
 Demonstrates functions of L298N Motor Controller
 
 DroneBot Workshop 2017
 http://dronebotworkshop.com
*/
 
 
// Motor A
 
int enA = 9;
int in1 = 8;
int in2 = 7;
 
// Motor B
 
int enB = 3;
int in3 = 5;
int in4 = 4;
 
void setup()
 
{
 
  // Set all the motor control pins to outputs
 
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
 
}
 
void demoOne()
 
{
 
  // This function will run the motors in both directions at a fixed speed
 
  // Turn on motor A
 
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
 
  // Set speed to 200 out of possible range 0~255
 
  analogWrite(enA, 200);
 
  // Turn on motor B
 
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
 
  // Set speed to 200 out of possible range 0~255
 
  analogWrite(enB, 200);
 
  delay(2000);
 
  // Now change motor directions
 
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);  
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH); 
 
  delay(2000);
 
  // Now turn off motors
 
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);  
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
 
}
 
void demoTwo()
 
{
 
  // This function will run the motors across the range of possible speeds
  // Note that maximum speed is determined by the motor itself and the operating voltage
 
  // Turn on motors
 
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);  
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH); 
 
  // Accelerate from zero to maximum speed
 
  for (int i = 0; i < 256; i++)
 
  {
 
    analogWrite(enA, i);
    analogWrite(enB, i);
 
    delay(20);
 
  } 
 
  // Decelerate from maximum speed to zero
 
  for (int i = 255; i >= 0; --i)
 
  {
 
    analogWrite(enA, i);
    analogWrite(enB, i);
 
    delay(20);
 
  } 
 
  // Now turn off motors
 
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);  
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);  
 
}
 
void loop()
 
{
 
  demoOne();
 
  delay(1000);
 
  demoTwo();
 
  delay(1000);
 
}

Was able to fin pin numbers and get the motors to spin!

Now I'm confused about power requirements and hook-ups. Any help with providing the right power to the motors.

Hi,
This may help;
http://www.keyestudio.com/keyestudio-balance-car-shield.html#custom-info

And;

  1. Working Voltage: DC 12V
  2. Working Current in driver: ≤ 2 A
  3. Working Temperature: 0℃~+80℃
  4. Coming with xbee/Bluetooh Bee wireless interface
  5. On-board buzzer(D6) used as alarming
  6. D11 as PWM pin 1 of motor 1, D9 as PWM pin 2 of motor 2, D 10 and D12 as output pin of motor 1, D8 and D7 as output pin of motor 2
  7. With two PH2.0-6P motor interfaces

In particular the motor pins used.
Motor 1, PWM pin D11, control Pins D10 and D12.
Motor 2, PWM pin D9, control Pins D7 and D8.

Your test code uses completely different pins.
Edit your code;
From this;

// Motor A
// Motor A
 
int enA = 9;
int in1 = 8;
int in2 = 7;
 
// Motor B
 
int enB = 3;
int in3 = 5;
int in4 = 4;

To this;

// Motor A
 
int enA = 11;
int in1 = 10;
int in2 = 12;
 
// Motor B
 
int enB = 9;
int in3 = 8;
int in4 = 7;

Tom.... :slight_smile:

Thank you, Tom.

On to coding...