Hello Team,
I am building the robot that runs with 4DC motors and i have small issues when attach the bluetooth to it.
Here is quick run down of items i am using:
- Arduino Uno - also t ested with Arduino Mega
- Adafruid Motor Shiled 2.3
- Bluetooth HC-06
- 4 DC motors 6v
- Android app: https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller&hl=en
Now When i run the test code for these motors without bluetooth, motors are running with full strength, no issues. Here is the test code for the motors only:
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Select which 'port' M1, M2, M3 or M4.
Adafruit_DCMotor *M1 = AFMS.getMotor(1);
Adafruit_DCMotor *M2 = AFMS.getMotor(2);
Adafruit_DCMotor *M3 = AFMS.getMotor(3);
Adafruit_DCMotor *M4 = AFMS.getMotor(4);
void setup() {
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
// turn on motor
M1->setSpeed(255);
M2->setSpeed(255);
M3->setSpeed(255);
M4->setSpeed(255);
M1->run(RELEASE);
M2->run(RELEASE);
M3->run(RELEASE);
M4->run(RELEASE);
Serial.begin(9600); // set up Serial library at 9600 bps
}
void loop()
{
M1->run(FORWARD);
M2->run(FORWARD);
M3->run(FORWARD);
M4->run(FORWARD);
delay (5000);
M1->run(BACKWARD);
M2->run(BACKWARD);
M3->run(BACKWARD);
M4->run(BACKWARD);
delay (5000);
}
When i attach the bluetooth and run the code below the motors are running with such low torque that barely can move the robot.
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Select which 'port' M1, M2, M3 or M4.
Adafruit_DCMotor *M1 = AFMS.getMotor(1);
Adafruit_DCMotor *M2 = AFMS.getMotor(2);
Adafruit_DCMotor *M3 = AFMS.getMotor(3);
Adafruit_DCMotor *M4 = AFMS.getMotor(4);
const int BTState = 11;
int state;
void setup() {
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
// turn on motor
M1->setSpeed(255);
M2->setSpeed(255);
M3->setSpeed(255);
M4->setSpeed(255);
M1->run(RELEASE);
M2->run(RELEASE);
M3->run(RELEASE);
M4->run(RELEASE);
pinMode(BTState, INPUT);
Serial.begin(9600); // set up Serial library at 9600 bps
}
void loop()
{
//Stop car when connection lost or bluetooth disconnected
if (digitalRead(BTState) == LOW) {
state = 'S';
}
//Save income data to variable 'state'
if (Serial.available() > 0) {
state = Serial.read();
}
//If state is equal with letter 'F', car will go forward!
if (state == 'F') {
M1->run(FORWARD);
M2->run(FORWARD);
M3->run(FORWARD);
M4->run(FORWARD);
}
//If state is equal with letter 'B', car will go backward
else if (state == 'B') {
M1->run(BACKWARD);
M2->run(BACKWARD);
M3->run(BACKWARD);
M4->run(BACKWARD);
}
//If state is equal with letter 'S', stop the car
else if (state == 'S') {
M1->run(RELEASE);
M2->run(RELEASE);
M3->run(RELEASE);
M4->run(RELEASE);
}
}
I have connected everything correctly when comes to bluetooth but i do not understand why when i initiate Forward or Backward command from my phone or computer via bluetooth i am not getting full speed of the DC motors. it almost seems that i am not getting enough power to them.
Any idea what am i doing wrong?