Monday, November 23, 2015

Arduino Bluetooth RC-Car

This project is about a car that is controlled via Bluetooth.


Step 1: Materials Requirement

Arduino UNO
•Arduino Motor Shield
HC-05 Bluetooth module
•Jumper Wires
•Robot Wheels
•Omni Wheel
•Base to mount the parts (Here,I have used wood plank 10.5cmx14cm)
•Relay sheild or my relay circuit
•Power source


Step 2: Assembling the components






Now that we have all the components we connect the motor shield to the Arduino.I did a small trick to connect the RX and TX pin to the motor shield because mine didn't have female pin headers. I took two small female pin headers and soldered to my motor shield.

Next we have to mount the Arduino to the base of the car then mount the motor sheild on top of it. Next mount the Bluetooth module on the base remembering the Vcc,GND,RX and TX pins by noting it down.

Next mount the omni wheel onto the base and the dc motor robot wheels too.
Then connect the dc motors to the M1 and M2 ports of the motor shield.

Thereafter connect the RX pin in the module to the TX pin of Arduino and TX pin of module to RX pin of Arduino.

Lastly connect the relay circuit i made to digital pin 6 so that we can switch on the front light via Bluetooth.

Step 3: Coding and the android apk
Before uploading the code remove the 5v or RX and TX pins from the arduino which is connected to the Bluetooth module because there would be problems in uploading the code if not.

Go to play store and download the "Arduino Bluetooth RC Car" apk or scan the Qr code to download easily and install it switch on the car and connect the module using 1234 as the password

//Arduino Bluetooth car
//Author: Manu Goswami
//Function:Controls car via Bluetooth

#include <AFMotor.h>

//creates two objects to control the terminal 1 and 2 of motor shield
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
char command;
const int FrontLed = 6;
void setup()
{    
  Serial.begin(38400);  //Set the baud rate to your Bluetooth module.
  // Front LEDs
  pinMode(FrontLed, OUTPUT);  // declare FrontRightLed as output
}
void loop(){
  if(Serial.available() > 0){
    command = Serial.read();
    Stop(); //initialize with motors stoped
    //Change pin mode only if new command is different from previous.
    //Serial.println(command);
    switch(command){
    case 'F':
      forward();
      break;
    case 'B':
       back();
      break;
    case 'L':
      left();
      break;
    case 'R':
      right();
      break;
      case 'W':
      digitalWrite(6,HIGH);
      break;
      case 'w':
      digitalWrite(6,LOW);
      break;
     }
  }
}
void forward()
{
  motor1.setSpeed(90); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(90); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
}
void back()
{
  motor1.setSpeed(90);
  motor1.run(BACKWARD); //rotate the motor counterclockwise
  motor2.setSpeed(90);
  motor2.run(BACKWARD); //rotate the motor counterclockwise
}
void left()
{
  motor1.setSpeed(90); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(0);
  motor2.run(RELEASE); //turn motor2 off
}
void right()
{
  motor1.setSpeed(0);
  motor1.run(RELEASE); //turn motor1 off
  motor2.setSpeed(90); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
}
void Stop()
{
  motor1.setSpeed(0);
  motor2.run(RELEASE); //turn motor1 off
  motor2.setSpeed(0);
  motor2.run(RELEASE); //turn motor2 off
}

No comments:

Post a Comment