Problems with a servo when using Arduino Pro Mini and Bluetooth Mate Gold

<
#include <SoftwareSerial.h>
#include <Servo.h>
String readString;
String string1;
String string2;
String string3;
String string4;
String string5;
Servo myServo;
#define rxPin 8
#define txPin 9
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

int inChar = 0; //invariabel
int val = 0;
int var1 = 0;
int var2 = 0;
int var3 = 0;
int var4 = 0;
int var5 = 0;
int var6 = 0;
int var7 = 0;

/////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {

mySerial.begin(9600);
Serial.begin(9600);

bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, Mate to send back CMD
bluetooth.println("U,9600,N"); // Change
bluetooth.begin(9600); // Start bluetooth serial at 9600
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(500);
bluetooth.println("C,000666C0ADE8"); // make contact with the other BT

pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(6, OUTPUT);
myServo.attach(6);
}
///////////////////////////////////////LOOP////////////////////////////////////////////////////
void loop() {

if (bluetooth.available()>0) {

string1 = bluetooth.readStringUntil('A');

string2 = bluetooth.readStringUntil(',');
bluetooth.read();

string3 = bluetooth.readStringUntil('B');
bluetooth.read();

string4 = bluetooth.readStringUntil(',');
bluetooth.read();

Serial.print(string2);
Serial.print(" ");
Serial.println(string4);

var1 = string2.toInt();
myServo.write(var1);

readString="";
string1="";
string2="";
string3="";
string4="";

}
}>

Text Arduino.pdf (22.5 KB)

Is there a question?
Code tags?

SoftwareSerial.h and Servo.h are not compatible. Both use the same timer. And it is a bad idea to use a load of Strings in a small Arduino.

Other than that, what did you think the problem was? Compile errors? Post the error messages.

Steve

I included a PDF file about the problem. The problem could be that SoftwareSerial.h and Servo:h are not compatible. I did not know. How to avoid?

There are alternatives for both SoftwareSerial (AltSoftSerial, NeoSWSerial) and Servo (ServoTimer2). Some combination of those will probably work for you.

I've never tried the SW Serial ones but ServoTimer2 has worked for me though the commands to use it are slightly different from the standard Servo library.

Steve

Thank you Steve. I have tried with ServoTimer2 and it seems to solve the problem. Unfortunately I burned the BT module by making a mistake. A new one is on its way. Next week I will try again.