#include <SoftwareSerial.h>
#include <Servo.h>
#include <String.h>
SoftwareSerial BT(11, 10); //TX, RX respetively
String voice;
int i;
int state1;
Servo servo1; //1 7
Servo servo2; //16 10
Servo servo3; //2 3
Servo servo4; //5 6
Servo servo5; //8 9
Servo servo6; //11 12
Servo servo7; //14 15
Servo servo8; //17 18
Servo servo9; //4
Servo servo10; //13
void setup()
{
servo1.attach(2);
servo2.attach(13);
servo3.attach(4);
servo4.attach(5);
servo5.attach(6);
servo6.attach(7);
servo7.attach(8);
servo8.attach(9);
servo9.attach(12);
servo10.attach(3);
servo1.write(90);
servo2.write(90);
servo3.write(90);
servo4.write(90);
servo5.write(90);
servo6.write(90);
servo7.write(90);
servo8.write(90);
servo9.write(90);
servo10.write(90);
BT.begin(9600);
Serial.begin(9600);
}
void INITIAL()
{
servo1.write(90);
servo2.write(90);
servo3.write(90);
servo4.write(90);
servo5.write(90);
servo6.write(90);
servo7.write(90);
servo8.write(90);
servo9.write(90);
servo10.write(90);
}
void BACKWARD()
{ servo3.write(45); //legs move up
servo7.write(135);
servo5.write(45);
delay(150);
servo1.write(75); //legs move forward BADAYO
servo10.write(105);
delay(150);
servo2.write(75); ////////////////////////////////////75
servo9.write(105);
delay(150);
servo3.write(90); //legs move down
servo7.write(90);
servo5.write(90);
delay(150);
//BODY
servo1.write(90); //BODY LAI AGADI SARYO ANI TYO BODY AGADI SARDA SARDAI OPPOSITE KHUTTA PAXADI TIRA GAYO
servo10.write(90);
servo2.write(75);
servo9.write(105);
delay(150);
servo6.write(135); //OPPOSITE TIRA KO KHUTTA LAI MATHI UTHAYO
servo4.write(45);
servo8.write(135);
delay(150);
servo2.write(105); //OPPOSITE legs move forward BADAYO /////////////////////////////////105
servo9.write(75);
delay(150);
servo1.write(105);
servo10.write(75);
delay(150);
servo6.write(90); //OPPOSITE legs move down
servo4.write(90);
servo8.write(90);
delay(150);
//BODY
servo1.write(105); //ABA YESLE MARKA MAH PARYO ,,K VANDA KHERI 2ND TIME BODY SARDA CHAI SURUKO KHUTTA HARU PAXADI GAYO ABA YO PROBLEM MILAUNU KO LAGI TALA KO SOLUTION HERR VAI
servo10.write(75);
servo2.write(90);
servo9.write(90);
delay(150);
//SOLUTION
servo3.write(45); //legs move up
servo7.write(135);
servo5.write(45);
delay(150);
servo1.write(90); //legs move forward BADAYO
servo10.write(90);
delay(150);
//vai dherai batho vais khutta tala jhareko khai bhujis aba khutta tala jhar
servo3.write(90); //legs move up
servo7.write(90);
servo5.write(90);
}
void FORWARD()
{ servo3.write(45); //legs move up
servo7.write(135);
servo5.write(45);
delay(200);
servo1.write(115); //legs move forward BADAYO
servo10.write(65);
delay(200);
servo3.write(90); //legs move down
servo7.write(90);
servo5.write(90);
delay(200);
//BODY
servo1.write(90); //BODY LAI AGADI SARYO ANI TYO BODY AGADI SARDA SARDAI OPPOSITE KHUTTA PAXADI TIRA GAYO
servo10.write(90);
servo2.write(115);
servo9.write(65);
delay(200);
servo6.write(135); //OPPOSITE TIRA KO KHUTTA LAI MATHI UTHAYO
servo4.write(45);
servo8.write(135);
delay(200);
servo2.write(65); //OPPOSITE legs move forward BADAYO
servo9.write(115);
delay(200);
servo6.write(90); //OPPOSITE legs move down
servo4.write(90);
servo8.write(90);
delay(200);
//BODY
servo1.write(65); //ABA YESLE MARKA MAH PARYO ,,K VANDA KHERI 2ND TIME BODY SARDA CHAI SURUKO KHUTTA HARU PAXADI GAYO ABA YO PROBLEM MILAUNU KO LAGI TALA KO SOLUTION HERR VAI
servo10.write(115);
servo2.write(90);
servo9.write(90);
delay(200);
//SOLUTION
servo3.write(45); //legs move up
servo7.write(135);
servo5.write(45);
delay(200);
servo1.write(90); //legs move forward BADAYO
servo10.write(90);
delay(200);
//vai dherai batho vais khutta tala jhareko khai bhujis aba khutta tala jhar
servo3.write(90); //legs move up
servo7.write(90);
servo5.write(90);
}
void RIGHT()
{ servo3.write(45); //legs move up
servo7.write(135);
servo5.write(45);
delay(150);
servo1.write(55); //legs move forward BADAYO
servo10.write(55);
delay(150);
servo3.write(90); //legs move down
servo7.write(90);
servo5.write(90);
delay(150);
servo6.write(135); //OPPOSITE TIRA KO KHUTTA LAI MATHI UTHAYO TESPAXI BODY GHUMAUNA SAJILO HUNXA VANERA
servo4.write(45);
servo8.write(135);
delay(150);
//BODY
servo1.write(90); //BODY LAI GHUMAYO 1part
servo10.write(90);
servo2.write(55);
servo9.write(55);
delay(150);
servo6.write(90); //OPPOSITE legs move down
servo4.write(90);
servo8.write(90);
delay(150);
servo3.write(45); //legs move up
servo7.write(135);
servo5.write(45);
delay(150);
servo2.write(90);
servo9.write(90);
delay(150);
servo3.write(90); //legs move up
servo7.write(90);
servo5.write(90);
}
void LEFT()
{
servo6.write(135); //OPPOSITE TIRA KO KHUTTA LAI MATHI UTHAYO TESPAXI BODY GHUMAUNA SAJILO HUNXA VANERA
servo4.write(45);
servo8.write(135);
delay(150);
servo2.write(125); //legs move forward
servo9.write(125);
delay(150);
servo6.write(90); //legs move down
servo4.write(90);
servo8.write(90);
delay(150);
servo3.write(45); //legs move up
servo7.write(135);
servo5.write(45);
delay(150);
//BODY
servo2.write(90); //BODY GHUMYO
servo9.write(90);
servo1.write(125);
servo10.write(125);
delay(150);
servo3.write(90); //legs move down
servo7.write(90);
servo5.write(90);
delay(150);
servo6.write(135); //OPPOSITE TIRA KO KHUTTA LAI MATHI UTHAYO TESPAXI BODY GHUMAUNA SAJILO HUNXA VANERA
servo4.write(45);
servo8.write(135);
delay(150);
servo1.write(90);
servo10.write(90);
delay(150);
servo6.write(90); //OPPOSITE TIRA KO KHUTTA LAI MATHI UTHAYO TESPAXI BODY GHUMAUNA SAJILO HUNXA VANERA
servo4.write(90);
servo8.write(90);
}
void FLICKER()
{
servo4.write(30);
delay(200);
servo9.write(60);
delay(200);
servo9.write(90);
delay(200);
servo9.write(120);
delay(200);
servo9.write(90);
delay(200);
servo9.write(60);
delay(200);
servo9.write(90);
delay(200);
servo4.write(180);
delay(200);
}
void UPWARD()
{ for(int i=90;i>=45;i--)
{ servo3.write(180-i);
servo5.write(180-i);
servo6.write(i);
servo8.write(i);
delay(50);
} servo4.write(135);
servo7.write(45);
}
void DOWNWARD()
{ for(int i=90;i>=65;i--)
{
servo3.write(i);
servo4.write(i);
servo5.write(i);
servo6.write(180-i);
servo7.write(180-i);
servo8.write(180-i);
delay(50);
}
}
void FLICK_LEFT()
{ //FLICK LEFT PART
for(int i=0;i<=5;i++)
{
servo6.write(150);
servo8.write(150);
servo2.write(45);
delay(200);
servo2.write(135);
delay(200);
}
}
void FLICK_RIGHT()
{
//FLICK RIGHT PART
for(int i=0;i<=5;i++)
{
servo3.write(30);
servo5.write(30);
servo1.write(135);
delay(200);
servo1.write(45);
delay(200);
}
}
void doingmoves()
{ servo3.write(45);
servo8.write(135);
delay(200);
servo3.write(90);
servo8.write(90);
delay(200);
servo4.write(45);
servo7.write(135);
delay(200);
servo4.write(90);
servo7.write(90);
delay(200);
for(i=0;i<=2;i++)
{ servo5.write(45);
servo6.write(135);
delay(200);
servo5.write(90);
servo6.write(90);
delay(200);
}
}
void SPINTHESPINNER()
{ servo8.write(110);
servo6.write(110);
delay(200);
servo2.write(180);
delay(200);
servo8.write(135);
servo6.write(135);
delay(200);
for(int i=180;i>=90;i--)
{
servo2.write(i);
delay(10);
}
delay(200);
servo8.write(90);
servo6.write(90);
}
void loop()
{
while (BT.available())//Check if there is an available byte to read
{ delay(10); //Delay added to make thing stable
char c = BT.read(); //Conduct a serial read
if (c == '#')
{
break; //Exit the loop when the # is detected after the word
}
voice += c; //Shorthand for voice = voice + c
}
voice.toLowerCase();
if (voice.length() > 0)
{
Serial.println(voice);
if(voice == "initial"||voice=="0"||voice == "*initial")
{
INITIAL();
}
else if(voice == "forward"||voice=="1"||voice == "*forward")
{
FORWARD();
}
else if(voice=="2")
{
FORWARD();
FORWARD();
}
else if(voice=="3")
{
FORWARD();
FORWARD();
FORWARD();
}
else if(voice=="4")
{
FORWARD();
FORWARD();
FORWARD();
FORWARD();
}
else if(voice=="5")
{
FORWARD();
FORWARD();
FORWARD();
FORWARD();
FORWARD();
FORWARD();
}
else if (voice == "backward"||voice=="6"||voice == "*backward")
{
BACKWARD();
}
else if (voice=="7")
{
BACKWARD();
BACKWARD();
}
else if (voice=="8")
{
BACKWARD();
BACKWARD();
BACKWARD();
}
else if (voice=="9")
{
BACKWARD();
BACKWARD();
BACKWARD();
BACKWARD();
}
else if (voice=="10")
{
BACKWARD();
BACKWARD();
BACKWARD();
BACKWARD();
BACKWARD();
BACKWARD();
}
else if (voice=="left"||voice=="11"||voice=="*left")
{
LEFT();
}
else if (voice=="12")
{
LEFT();
LEFT();
LEFT();
}
else if (voice=="13")
{
LEFT();
LEFT();
LEFT();
LEFT();
}
else if (voice=="right"||voice=="14"||voice=="*right")
{
RIGHT();
}
else if (voice=="15")
{
RIGHT();
RIGHT();
RIGHT();
}
else if (voice=="16")
{
RIGHT();
RIGHT();
RIGHT();
RIGHT();
}
else if (voice=="doingmoves"||voice=="29"||voice=="*doingmoves")
{
doingmoves();
}
else if (voice=="spin"||voice=="31"||voice=="*spin")
{
SPINTHESPINNER();
}
else if (voice=="flick left"||voice=="30"||voice=="*flick left")
{
FLICK_LEFT();
servo2.write(90);
delay(100);
servo6.write(90);
servo8.write(90);
}
else if (voice=="flick right"||voice=="32"||voice=="*flick right")
{
FLICK_RIGHT();
servo1.write(90);
delay(100);
servo3.write(90);
servo5.write(90);
}
else if (voice=="leg6"||voice=="23"||voice=="*leg6")
{ servo8.write(30);
delay(200);
servo8.write(90);
}
else if (voice=="leg5"||voice=="24"||voice=="*leg5")
{ servo7.write(30);
delay(200);
servo7.write(90);
}
else if (voice=="leg4"||voice=="25"||voice=="*leg4")
{ servo6.write(30);
delay(200);
servo6.write(90);
}
else if (voice=="leg3"||voice=="28"||voice=="*leg3")
{ servo5.write(150);
delay(200);
servo5.write(90);
}
else if (voice=="leg2"||voice=="27"||voice=="*leg2")
{ servo4.write(150);
delay(200);
servo4.write(90);
}
else if (voice=="leg1"||voice=="26"||voice=="*leg1")
{ servo3.write(150);
delay(200);
servo3.write(90);
}
else if (voice=="upward"||voice=="33"||voice=="*upward")
{ UPWARD();
}
else if (voice=="downward"||voice=="34"||voice=="*downward")
{ DOWNWARD();
}
else if (voice=="dance"||voice=="35"||voice=="*dance")
{
UPWARD();
delay(100);
for(int i=0;i<=4;i++){
servo7.write(135);
servo4.write(135);
delay(150);
servo7.write(45);
servo4.write(45);
delay(150);
}
}
else if (voice=="u6")
{ servo8.write(150);
delay(200);
servo8.write(90);
}
else if (voice=="u5")
{ servo7.write(150);
delay(200);
servo7.write(90);
}
else if (voice=="u4")
{ servo6.write(150);
delay(200);
servo6.write(90);
}
else if (voice=="u3")
{ servo5.write(30);
delay(200);
servo5.write(90);
}
else if (voice=="u2")
{ servo4.write(30);
delay(200);
servo4.write(90);
}
else if (voice=="u1")
{ servo3.write(30);
delay(200);
servo3.write(90);
}
else if (voice=="upback")
{ servo4.write(90);
servo7.write(90);
for(int i=45;i<=90;i++)
{ servo3.write(180-i);
servo5.write(180-i);
servo6.write(i);
servo8.write(i);
delay(50);
}
}
else if (voice=="downback")
{
for(int i=65;i<=90;i++)
{
servo3.write(i);
servo4.write(i);
servo5.write(i);
servo6.write(180-i);
servo7.write(180-i);
servo8.write(180-i);
delay(50);
}
}
voice="";//Reset the variable after initiating
}
}