Hesham
Published © TAPR-OHL

Bluetooth Mini Car

A toy car controlled by mobile.

IntermediateShowcase (no instructions)9,116
Bluetooth Mini Car

Things used in this project

Hardware components

Android device
Android device
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Arduino motor shield
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
LED (generic)
LED (generic)
×2
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×15
car chassis
×1
Baterry
×1

Software apps and online services

Bluetooth terminal

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Screenshot%202016-02-21%2019.38.55%20(2).png

Screenshot%202016 02 21%2019.38.55%20(2)

Code

Bluetooth 2WD car

Arduino
This code is compatible with any serial Bluetooth app like "Bluetooth terminal" or you can create your own app using "appinventor.mit.edu" or simply test it with or without bluetooth module using the serial monitor.
char junk;
String inputString="";
long time = 0; 
int state = HIGH;
int frontled = 7;
int frontled2 = 3;
int buzzer = 4;

void setup()                    // run once, when the sketch starts
{
 Serial.begin(9600);     
 pinMode(3, OUTPUT);
 pinMode(buzzer, OUTPUT);
 pinMode(redled, OUTPUT);
 pinMode(redled2, OUTPUT);
 pinMode(12, OUTPUT); 
 pinMode(9, OUTPUT);
 pinMode(13, OUTPUT);
 pinMode(11, OUTPUT); 
 pinMode(8, OUTPUT); 
 pinMode(frontled, OUTPUT);
 pinMode(frontled2, OUTPUT); 
}

void loop()
{
  if(Serial.available()){
  while(Serial.available())
    {
      char inChar = (char)Serial.read(); //read the input
      inputString += inChar; //make a string of the characters coming on  serial
    }
    Serial.println(inputString);
    while (Serial.available() > 0)  
    { 
    junk = Serial.read() ; 
    }      // clear the serial buffer
    if(inputString == "a"){         //in case of 'a' turn the LED on
      if (state == HIGH)
      state = LOW;
    else
      state = HIGH;

    time = millis();    

    digitalWrite(frontled, state);
    digitalWrite(frontled2, state);
    }
    else if(inputString == "f"){   //incase of 'f'= forward
      digitalWrite(12, HIGH); //Establishes forward direction of Channel A
      digitalWrite(9, LOW);   //Disengage the Brake for Channel A
      analogWrite(3, 255);   //Spins the motor on Channel A at full speed
      digitalWrite(13, HIGH); //Establishes forward direction of Channel B
      digitalWrite(8, LOW);   //Disengage the Brake for Channel B
      analogWrite(11, 255);   //Spins the motor on Channel B at full speed
    }
    else if(inputString == "b"){  //incase of 'b'= brakes
      digitalWrite(9, HIGH);  //Engage brakes for channel A
      digitalWrite(8, HIGH);  //Engage brakes for channel A
    }
    else if(inputString == "l"){  //incase of 'l'= left
      digitalWrite(12, HIGH); //Establishes forward direction of Channel A
      digitalWrite(9, LOW);   //Disengage the Brake for Channel A
      analogWrite(3, 100);   //Spins the motor on Channel A at half speed
      digitalWrite(13, LOW); //Establishes backward direction of Channel B
      digitalWrite(8, LOW);   //Disengage the Brake for Channel B
      analogWrite(11, 100);   //Spins the motor on Channel B at half speed
    }
    else if(inputString == "r"){  //incase of 'r'= right
      digitalWrite(12, LOW); //Establishes backward direction of Channel A
      digitalWrite(9, LOW);   //Disengage the Brake for Channel A
      analogWrite(3, 100);   //Spins the motor on Channel A at half speed
      digitalWrite(13, HIGH); //Establishes forward direction of Channel B
      digitalWrite(8, LOW);   //Disengage the Brake for Channel B
      analogWrite(11, 100);   //Spins the motor on Channel B at half speed
    }
    else if(inputString == "w"){   //incase of 'w'= backward
      digitalWrite(12, LOW); //Establishes backward direction of Channel A
      digitalWrite(9, LOW);   //Disengage the Brake for Channel A
      analogWrite(3, 255);   //Spins the motor on Channel A at full speed
      digitalWrite(13, LOW); //Establishes backward direction of Channel B
      digitalWrite(8, LOW);   //Disengage the Brake for Channel B
      analogWrite(11, 255);   //Spins the motor on Channel B at full speed
    }
    inputString = ""; //we clear the variable for the next commande
  }
}

Credits

Hesham

Hesham

1 project • 9 followers
I am 13 year old boy, i like to do projects using different platform of microcontrollers

Comments