Saturday, November 28, 2015

Arduino Bluetooth Car

Hello Everyone,

This is my another post in which I am going to illustrate you about the Arduino Bluetooth Car.Here,I will show you the video which will completely illustrate you about this so that you can easily understand the functioning of the Arduino Bluetooth Car.





The Code:

int motorPin1 = 10;
int motorPin2 = 11;
int motorPin3 = 8;
int motorPin4 = 9;

void setup()
{
   Serial.begin(9600);

   pinMode(motorPin1, OUTPUT);
   pinMode(motorPin2, OUTPUT);
   pinMode(motorPin3, OUTPUT);
   pinMode(motorPin4, OUTPUT);

   digitalWrite(motorPin1, 0);
   digitalWrite(motorPin2, 0);
   digitalWrite(motorPin3, 0);
   digitalWrite(motorPin4, 0);
}

void loop()
{
   char vDados = Serial.read();
   if (vDados == '1')
   {
      fFrente();
   }
   elseif (vDados == '2')
   {
      fFrente();
      fDireita();
   }
   elseif (vDados == '3')
   {
      fDireita();
   }
   elseif (vDados == '4')
   {
      fRe();
      fDireita();
   }
   elseif (vDados == '5')
   {
      fRe();
   }
   elseif (vDados == '6')
   {
      fRe();
      fEsquerda();
   }
   elseif (vDados == '7')
   {
     fEsquerda();
   }
   elseif (vDados == '8')
   {
     fFrente();
     fEsquerda();
   }
   delay(111);

   fParar();
}
void fParar()
{
   digitalWrite(motorPin1, 0);
   digitalWrite(motorPin2, 0);
   digitalWrite(motorPin3, 0);
   digitalWrite(motorPin4, 0);
}
void fFrente()
{
   digitalWrite(motorPin1, 1);
}
void fDireita()
{
  digitalWrite (motorPin3, 1);
}
void fRe()
{
  digitalWrite(motorPin2, 1);
}
void fEsquerda()
{
  digitalWrite (motorPin4, 1);
}

If you have any query regarding my post,you can comment your questions and suggestions in comment section.

No comments:

Post a Comment