In the program,I use arduino UNO,also use the motor driver VNH5019 to drive two 7V dc motors.This motor driver is connected with arduino board together.then the two dc motors connect two wheels to make them run.So I want to add bluetooth so I can use smartphone to control two dc motors,motor drivers(can go forward,back,turn left,turn right and so on...).I put the programming code on the
arduino sketch:
#include <DualVNH5019MotorShield.h>
DualVNH5019MotorShield md;
char dataIn='S';char determinant;char det;int vel = 0;
int power = 4;
int overdrive = 13;
void stopIfFault()
{
if (md.getM1Fault())
{
Serial.println("M1 fault");
while(1);
}
if (md.getM2Fault())
{
Serial.println("M2 fault");
while(1);
}
}
void setup()
{
Serial.begin(115200);
Serial.println("Dual VNH5019 Motor Shield");
md.init();
pinMode(power , OUTPUT);
pinMode(overdrive, OUTPUT);
}
void loop()
{
det = check();
while (det == 'F')
{md.setSpeeds(vel,vel);det = check();}
while (det == 'B')
{md.setSpeeds(-vel,-vel);det = check();}
while (det == 'L')
{md.setSpeeds(vel/4,vel);det = check();}
while (det == 'R')
{md.setSpeeds(vel,vel/4);det = check();}
while (det == 'I')
{md.setSpeeds(vel,vel/2);det = check();}
while (det == 'J')
{md.setSpeeds(-vel,-vel/2);det = check();}
while (det == 'G')
{md.setSpeeds(vel/2,vel);det = check();}
while (det == 'H')
{md.setSpeeds(-vel/2,-vel);det = check();}
while (det == 'S')
{md.setSpeeds(0,0);det = check();}
while (det == 'U')
{digitalWrite(power, HIGH);det = check();}
while (det == 'u')
{digitalWrite(power, LOW);det = check();}
while (det == 'W')
{digitalWrite(overdrive, HIGH);det = check();}
while (det == 'w')
{digitalWrite(overdrive, LOW);det = check();}
}
int check()
{
if (Serial.available() > 0)
{
dataIn = Serial.read();
if (dataIn == 'F'){determinant = 'F';}
else if (dataIn == 'B'){determinant = 'B';}
else if (dataIn == 'L'){determinant = 'L';}
else if (dataIn == 'R'){determinant = 'R';}
else if (dataIn == 'I'){determinant = 'I';}
else if (dataIn == 'J'){determinant = 'J';}
else if (dataIn == 'G'){determinant = 'G';}
else if (dataIn == 'H'){determinant = 'H';}
else if (dataIn == 'S'){determinant = 'S';}
else if (dataIn == '0'){vel = 400;}
else if (dataIn == '1'){vel = 380;}
else if (dataIn == '2'){vel = 340;}
else if (dataIn == '3'){vel = 320;}
else if (dataIn == '4'){vel = 280;}
else if (dataIn == '5'){vel = 240;}
else if (dataIn == '6'){vel = 200;}
else if (dataIn == '7'){vel = 160;}
else if (dataIn == '8'){vel = 120;}
else if (dataIn == '9'){vel = 80;}
else if (dataIn == 'q'){vel = 40;}
else if (dataIn == 'U'){determinant = 'U';}
else if (dataIn == 'u'){determinant = 'u';}
else if (dataIn == 'W'){determinant = 'W';}
else if (dataIn == 'w'){determinant = 'w';}
return determinant;
}
}
The compile is okay for that,but dont know whether it can work .If it is okay,beside the smartphone,what else(device) need I put on arduino board to receive the signal,(device)can communicate with my smartphone bluetooth to let the bluetooth part programming code run properly?Is that BlueSMiRF to connect with arduino board(step:short RTS and CTS together. I soldered a wire between the RTS and CTS;Connect BlueSMiRF Vcc to Arduino's 3v3.;Connect BlueSMiRF GND to Arduino GND;Connect BlueSMiRF TX to Arduino RX;Connect BlueSMiRF RX to Arduino TX)) or other devices?How should I follow?Thanks so much.