I am using HC-05 Bluetooth module to control two servos. I use Bluetooth terminal in my android phone to control them.
Problem is that myServo1 is moving like I want but I can't control myServo2. Code is reading the variable a but it can't read variable b.
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myServo1;
Servo myServo2;
int servo;
SoftwareSerial BT(2, 3);
void setup()
{
myServo1.attach(11);
myServo2.attach(10);
servo = 90;
Serial.begin(9600);
BT.begin(9600);
}
char a;
char b;
void loop()
{
if (BT.available())
{
a=(BT.read());
b = (BT.read());
if (a=='1')
{
myServo1.write(180);
delay(50);
}
if (a=='2')
{
myServo1.write(-180);
delay(50);
}
if (b=='3')
{
myServo2.write(90);
delay(50);
}
if (b=='4')
{
myServo2.write(-90);
delay(50);
}
}
}
Where is the problem?
a
andb
to the serial monitor?