Bluetooth Car using Arduino

0
181

This tutorial demonstrates how to create an Arduino Robot Car that can be Bluetooth controlled using an HC-05 Bluetooth Module, an L293D Motor Drive Shield, and an Arduino.

Bluetooth Module HC-05

The HC-05 is a Bluetooth SPP module that is easy to use and is optimised for setting up serial wireless communication. The Serial port Bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps modulation with a total of 2.4GHz radio transceiver and baseband. It has a single-chip Bluetooth system called CSR Bluecore 04-External with CMOS technology and AFH (Adaptive Frequency Hopping Feature). It takes up only 12.7 mm x 27 mm of space.

Bluetooth Module Default Settings for the HC-05

  • Default Bluetooth Name: “HC-05”

  • Default Password: 1234 or 0000

  • Default Communication: Slave

  • Default Mode: Data Mode

Specifications for the HC-05 Bluetooth Module

  • Operating voltage

  • 4V – 6V

  • Operating current consumption

  • 30mA

  • Range

  • <100m

Motor Drive Shield L293D

The L293D is a specialised module that can be installed on either the Arduino UNO R3 Board or the Arduino MEGA board. It is a motor driver shield that comes with a full-featured Arduino Shield and can be used to drive anywhere from two to six DC motors and four-wire Stepper motors. Additionally, it has two sets of pins that can be used to operate a SERVO.

The Specifications for the L293D Motor Drive Shield

  • Operating voltage

2.3V – 5.5V

  • The amount of current used in operation

70 – 150 µA

  • Operating temperature

40°C to +85°C

Components Used

Arduino Shield Connection Diagram

Apps to Download

Libraries to Download

Programming

#include <AFMotor.h>
#include <SoftwareSerial.h>
//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ); 
AF_DCMotor motor2(2, MOTOR12_1KHZ); 
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
char command; 
int RXPin = 2;
int TXPin = 13;
SoftwareSerial softserial (RXPin, TXPin);
void setup() 
{       
  Serial.begin(9600);  //Set the baud rate to your Bluetooth module.
  softserial.begin(9600);
}
void loop(){
  if(softserial.available() > 0){ 
    command = softserial.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;
    }
  } 
}
void forward()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
  motor3.setSpeed(255);//Define maximum velocity
  motor3.run(FORWARD); //rotate the motor clockwise
  motor4.setSpeed(255);//Define maximum velocity
  motor4.run(FORWARD); //rotate the motor clockwise
}
void back()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
}
void left()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(FORWARD);  //rotate the motor clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(FORWARD);  //rotate the motor clockwise
}
void right()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
} 
void Stop()
{
  motor1.setSpeed(0); //Define minimum velocity
  motor1.run(RELEASE); //stop the motor when release the button
  motor2.setSpeed(0); //Define minimum velocity
  motor2.run(RELEASE); //rotate the motor clockwise
  motor3.setSpeed(0); //Define minimum velocity
  motor3.run(RELEASE); //stop the motor when release the button
  motor4.setSpeed(0); //Define minimum velocity
  motor4.run(RELEASE); //stop the motor when release the button
}

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here