FULLY FEATURED BLUETOOTH CONTROL CAR WITH MIT APP INVENTOR || MKINVENTIO...


FULLY FEATURED BLUETOOTH CONTROL CAR

SOURCE CODE:

//BLUETOOTH CONTROL CAR WITH L293D MOTOR DRIVER

///MKINVENTIONS MADHAN KUMAR CHIRUGURI

///FOLLOW ME ON FACEBOOK AND INSTAGRAM

//MADHAN KUMAR CHIRUGURI



#include<Servo.h>

Servo servo1;

Servo servo2;



char command;



int LMT1  = 5;//left motor 1

int LMT2  = 6;//left motor 2

int RMT1  = 7;//right motor 1

int RMT2  = 8;//right motor 2



int LED1  = A0;//FRONT LED

int LED2  = A1;//BACK LED

int LED3  = A2;//BOTTOM LED



int HORN  = 4;//HORN



void setup()

{     

  Serial.begin(9600);



  pinMode(LMT1, OUTPUT);

  pinMode(LMT2, OUTPUT);

  pinMode(RMT1, OUTPUT);

  pinMode(RMT2, OUTPUT);



  pinMode(LED1, OUTPUT);

  pinMode(LED2, OUTPUT);

  pinMode(LED3, OUTPUT);



  pinMode(HORN, OUTPUT);



  servo1.attach(2);

  servo2.attach(3);



}



void loop(){



 if(Serial.available() > 0){

    command = Serial.read();

    Serial.println(command);







//FORWARD..............

if(command == 'F' ){

  forward();

}

//BACKWARD..............

else if(command == 'B' ){

  backward();

}

//LEFT..............

else if(command == 'L' ){

  left();

}

//RIGHT..............

else if(command == 'R' ){

  right();

}



//FORWARD LEFT........

else if(command == 'F' && command == 'L' ){

  forwardleft();

}



//FORWARD RIGHT........

else if(command == 'F' && command == 'R' ){

  forwardright();

}





//BACKWARD LEFT........

else if(command == 'B' && command == 'L' ){

  backwardleft();

}



//BACKWARD RIGHT........

else if(command == 'B' && command == 'R' ){

  backwardright();

}



//STOP..............

else{

  stp();

}









//LED1..............

if(command == 'U' ){

  digitalWrite(LED1, HIGH);

}

if(command == 'u' ){

  digitalWrite(LED1, LOW);

}



//LED2..............

if(command == 'V' ){

  digitalWrite(LED2, HIGH);

}

if(command == 'v' ){

  digitalWrite(LED2, LOW);

}



//LED3..............

if(command == 'W' ){

  digitalWrite(LED3, HIGH);

}

if(command == 'w' ){

  digitalWrite(LED3, LOW);

}



//HORN..............

if(command == 'H' ){

  digitalWrite(HORN, HIGH);

}

if(command == 'h' ){

  digitalWrite(HORN, LOW);

}







//SERVO1.............

if(command == 'X' ){

  servo1.write(180);

}

if(command == 'x' ){

  servo1.write(0);

}

if(command == 'M'){

  servo1.write(90);

}







//SERVO2.............

if(command == 'Y' ){

  servo2.write(180);

}

if(command == 'y' ){

  servo2.write(0);

}

if(command == 'N'){

  servo2.write(90);

}









 }

}













void forward(){

  analogWrite(LMT1, 255);

  analogWrite(LMT2, 0);

  analogWrite(RMT1, 255);

  analogWrite(RMT2, 0);

}







void backward(){

  analogWrite(LMT1, 0);

  analogWrite(LMT2, 255);

  analogWrite(RMT1, 0);

  analogWrite(RMT2, 255);

}





void right(){

  analogWrite(LMT1, 0);

  analogWrite(LMT2, 150);

  analogWrite(RMT1, 150);

  analogWrite(RMT2, 0);

}



void left(){

  analogWrite(LMT1, 150);

  analogWrite(LMT2, 0);

  analogWrite(RMT1, 0);

  analogWrite(RMT2, 150);

}



void stp(){

  analogWrite(LMT1, 0);

  analogWrite(LMT2, 0);

  analogWrite(RMT1, 0);

  analogWrite(RMT2, 0);

}



void forwardleft(){

  analogWrite(LMT1, 0);

  analogWrite(LMT2, 0);

  analogWrite(RMT1, 150);

  analogWrite(RMT2, 0);

}



void forwardright(){

  analogWrite(LMT1, 150);

  analogWrite(LMT2, 0);

  analogWrite(RMT1, 0);

  analogWrite(RMT2, 0);

}





void backwardleft(){

  analogWrite(LMT1, 0);

  analogWrite(LMT2, 0);

  analogWrite(RMT1, 0);

  analogWrite(RMT2, 150);

}



void backwardright(){

  analogWrite(LMT1, 0);

  analogWrite(LMT2, 150);

  analogWrite(RMT1, 0);

  digitalWrite(RMT2, 0);



}


Post a Comment

0 Comments