Hi!
I’ve built a robot which is moved with 2 dc motors and a servo, connected to a Pololu VHN 5019, wwhich is stacked onto an Arduino Uno. I want the motors to move forwards / backwards only, and the servo to move from 90 º to 110 º (to turn right) and to 90 º to 70 º (to turn left). The servo makes the robot tilt in the desired direction, which provides the turning as the dc motors are moving. I have, however, a problem with the code. When the bluetooth turns on, the servo moves continuosly (it should only move when a button on a mobile phone app is pressed) and the dc motors don’t react. If I eliminate the servo code lines, the motors work just fine. The servo is connected to the pin on the vhn corresponding to 5v in the Arduino. The external power supply is 2 lipo batteries in parallel, supplying 12 v and 6000 mah. Could you please point me in the right direction? I’m also attaching the code:
#include <DualVNH5019MotorShield.h>
#include "DualVNH5019MotorShield.h"
DualVNH5019MotorShield md;
#include <Servo.h>
Servo myservo;
char dataIn='S';
char determinant;
char det;
int vel = 200; //Bluetooth Stuff
int overdrive = 13; //Press Toggle Switch #1, the pin13 LED will light up
void setup(){
Serial.begin(9600);md.init();
myservo.attach(3);delay(100);
myservo.write(90);delay(100);
}
int check()
{if (Serial.available() > 0) {dataIn = Serial.read();
if (dataIn == 'F'){determinant = 'F';}
else if (dataIn == 'B'){determinant = 'B';}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;}
void loop(){ det = check(); // You'll need to reconstruct this if your not using the Pololu Dual VNH5019
while (det == 'F') // F, move forward
{md.setSpeeds(vel,vel);det = check();}
while (det == 'B') // B, move back
{md.setSpeeds(-vel,-vel);det = check();}
while (det == 'S') // S, stop
{md.setSpeeds(0,0);det = check();}
while (det == 'W')
{myservo.write(110);delay(100);det = check();}
while (det == 'w')
{myservo.write(90);delay(100);det = check();}
while (det == 'U')
{myservo.write(70);delay(100);det = check();}
while (det == 'u')
{myservo.write(90);delay(100);det = check();}
}
Thanks in advance!