Mehmet SARI
Published © MIT

Car Control with Arduino Uno and Bluetooth

With this project, you can remotely control your car with Bluetooth.

BeginnerFull instructions provided5 days9,209
Car Control with Arduino Uno and Bluetooth

Things used in this project

Story

Read more

Custom parts and enclosures

app inventor apk

Code

arduino code

Arduino
char buffer[67];

byte Pino02 = 2;
byte Pino03 = 3;
byte Pino04 = 4;
byte Pino05 = 5;
byte Pino06 = 6;
byte Pino07 = 7;
byte Pino12 = 12;
byte Pino13 = 13;


void setup(){
  Serial.begin(9600);
  Serial.flush();
  pinMode(Pino02, OUTPUT);
  pinMode(Pino03, OUTPUT);
  pinMode(Pino04, OUTPUT);
  pinMode(Pino05, OUTPUT);
  pinMode(Pino06, OUTPUT);
  pinMode(Pino07, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}
void loop(){
  if (Serial.available()>0){
    int index=0;
    delay(100);//deixe o buffer encher
    int numChar = Serial.available();
    if(numChar>65){
      numChar=65;
    }
    while(numChar--){
      buffer[index++] = Serial.read();
    }
    splitString(buffer);
  }
}
void splitString(char* data){
  Serial.print("Dados inseridos: ");
  Serial.println(data);
  char* parameter;
  parameter= strtok (data, " ,");
  while(parameter != NULL){
    setLED(parameter);
    parameter = strtok (NULL, " ,");
  }
  //Limpa o texto e os buffers seriais
  for (int x=0; x<66; x++){
    buffer[x]='\0';
  }
  Serial.flush();
}
void setLED(char* data){
  
  if (data[0] == 'A'){
    analogWrite(9, 50);
    analogWrite(10, 50);
    digitalWrite(Pino02, LOW);
    digitalWrite(Pino03, HIGH);
    digitalWrite(Pino04, HIGH);
    digitalWrite(Pino05, LOW);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    }//İLERİSOL

    if (data[0] == 'C'){
    analogWrite(9, 50);
    analogWrite(10, 50);
    digitalWrite(Pino02, HIGH);
    digitalWrite(Pino03, LOW);
    digitalWrite(Pino04, LOW);
    digitalWrite(Pino05, HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    }//İLERİSAĞ
  
  if (data[0] == 'B'){
    analogWrite(9, 25);
    analogWrite(10, 25);
    digitalWrite(Pino02, HIGH);
    digitalWrite(Pino03, LOW);
    digitalWrite(Pino04, HIGH);
    digitalWrite(Pino05, LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
    }//GERİ1

    if (data[0] == 'M'){
    analogWrite(9, 75);
    analogWrite(10, 75);
    digitalWrite(Pino02, HIGH);
    digitalWrite(Pino03, LOW);
    digitalWrite(Pino04, HIGH);
    digitalWrite(Pino05, LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
    }//GERİ2

     if (data[0] == 'N'){
    analogWrite(9, 125);
    analogWrite(10, 125);
    digitalWrite(Pino02, HIGH);
    digitalWrite(Pino03, LOW);
    digitalWrite(Pino04, HIGH);
    digitalWrite(Pino05, LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
    }//GERİ3

    if (data[0] == 'P'){
    analogWrite(9, 175);
    analogWrite(10, 175);
    digitalWrite(Pino02, HIGH);
    digitalWrite(Pino03, LOW);
    digitalWrite(Pino04, HIGH);
    digitalWrite(Pino05, LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
    }//GERİ4

    if (data[0] == 'L'){
    analogWrite(9, 225);
    analogWrite(10, 225);
    digitalWrite(Pino02, HIGH);
    digitalWrite(Pino03, LOW);
    digitalWrite(Pino04, HIGH);
    digitalWrite(Pino05, LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
    }//GERİ5
    
  if (data[0] == 'D'){
    analogWrite(9, 25);
    analogWrite(10, 25);
    digitalWrite(Pino02, LOW);
    digitalWrite(Pino03, HIGH);
    digitalWrite(Pino04, LOW);
    digitalWrite(Pino05, HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    }//İLERİ1

    if (data[0] == 'H'){
    analogWrite(9, 75);
    analogWrite(10, 75);
    digitalWrite(Pino02, LOW);
    digitalWrite(Pino03, HIGH);
    digitalWrite(Pino04, LOW);
    digitalWrite(Pino05, HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    }//İLERİ2

    if (data[0] == 'I'){
    analogWrite(9, 125);
    analogWrite(10, 125);
    digitalWrite(Pino02, LOW);
    digitalWrite(Pino03, HIGH);
    digitalWrite(Pino04, LOW);
    digitalWrite(Pino05, HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    }//İLERİ3

    if (data[0] == 'K'){
    analogWrite(9, 175);
    analogWrite(10, 175);
    digitalWrite(Pino02, LOW);
    digitalWrite(Pino03, HIGH);
    digitalWrite(Pino04, LOW);
    digitalWrite(Pino05, HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    }//İLERİ4

    if (data[0] == 'L'){
    analogWrite(9, 225);
    analogWrite(10, 225);
    digitalWrite(Pino02, LOW);
    digitalWrite(Pino03, HIGH);
    digitalWrite(Pino04, LOW);
    digitalWrite(Pino05, HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    }//İLERİ5
  
  if (data[0] == 'U'){
    digitalWrite(Pino02, LOW);
    digitalWrite(Pino03, LOW);
    digitalWrite(Pino04, LOW);
    digitalWrite(Pino05, LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,LOW);
    }//DUR
     
  if (data[0] == 'E'){
    analogWrite(9, 50);
    analogWrite(10, 50);
    digitalWrite(Pino02, LOW);
    digitalWrite(Pino03, HIGH);
    digitalWrite(Pino04, LOW);
    digitalWrite(Pino05, HIGH);
    }//YAVAŞ İLERİ
      
  if (data[0] == 'F'){
    analogWrite(9, 50);
    analogWrite(10, 50);
    digitalWrite(Pino02, HIGH);
    digitalWrite(Pino03, LOW);
    digitalWrite(Pino04, HIGH);
    digitalWrite(Pino05, LOW);
    }//YAVAŞ GERİ

    
    
  
 }

Credits

Mehmet SARI

Mehmet SARI

9 projects • 16 followers
i am a electronic teacher

Comments