BLUETOOTH CONTROLLER CAR WITH MIT APP INVENTOR || L298N MOTOR DRIVER


BLUETOOTH CONTROLLER CAR WITH MIT APP INVENTOR || L298N MOTOR DRIVER

CODE:
//BLUETOOTH CONTROL CAR WITH L298N MOTOR DRIVER
///MKINVENTIONS MADHAN KUMAR CHIRUGURI
///FOLLOW ME ON FACEBOOK AND INSTAGRAM
//MADHAN KUMAR CHIRUGURI

char command; 

int LMT1  = 4;//IN1
int LMT2  = 6;//IN2
int RMT1  = 7;//IN3
int RMT2  = 8;//IN4
int ENABLEAB  = 5;//ENABLE AB

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

  pinMode(LMT1, OUTPUT);
  pinMode(LMT2, OUTPUT);
  pinMode(RMT1, OUTPUT);
  pinMode(RMT2, OUTPUT);
  pinMode(ENABLEAB, OUTPUT);
}

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();
}
 }
}


void forward(){
  digitalWrite(LMT1, HIGH);
  digitalWrite(LMT2, LOW);
  digitalWrite(RMT1, HIGH);
  digitalWrite(RMT2, LOW);
  analogWrite(ENABLEAB, 200);  
}



void backward(){
  digitalWrite(LMT1, LOW);
  digitalWrite(LMT2, HIGH);
  digitalWrite(RMT1, LOW);
  digitalWrite(RMT2, HIGH);
  analogWrite(ENABLEAB, 200);
}


void right(){
  digitalWrite(LMT1, LOW);
  digitalWrite(LMT2, HIGH);
  digitalWrite(RMT1, HIGH);
  digitalWrite(RMT2, LOW);
  analogWrite(ENABLEAB, 200);
}

void left(){
  digitalWrite(LMT1, HIGH);
  digitalWrite(LMT2, LOW);
  digitalWrite(RMT1, LOW);
  digitalWrite(RMT2, HIGH);
  analogWrite(ENABLEAB, 200);
}

void stp(){
  digitalWrite(LMT1, LOW);
  digitalWrite(LMT2, LOW);
  digitalWrite(RMT1, LOW);
  digitalWrite(RMT2, LOW);
  analogWrite(ENABLEAB, 200);
}

void forwardright(){
  digitalWrite(LMT1, LOW);
  digitalWrite(LMT2, LOW);
  digitalWrite(RMT1, HIGH);
  digitalWrite(RMT2, LOW);
  analogWrite(ENABLEAB, 200);
}

void forwardleft(){
  digitalWrite(LMT1, HIGH);
  digitalWrite(LMT2, LOW);
  digitalWrite(RMT1, LOW);
  digitalWrite(RMT2, LOW);
  analogWrite(ENABLEAB, 200);
}


void backwardleft(){
  digitalWrite(LMT1, LOW);
  digitalWrite(LMT2, LOW);
  digitalWrite(RMT1, LOW);
  digitalWrite(RMT2, HIGH);
  analogWrite(ENABLEAB, 200);
  }

void backwardright(){
  digitalWrite(LMT1, LOW);
  digitalWrite(LMT2, HIGH);
  digitalWrite(RMT1, LOW);
  digitalWrite(RMT2, LOW);
  analogWrite(ENABLEAB, 200);
}  

Post a Comment

0 Comments