Introduction: Bluetooth Controlled Boat Using HC-05 - This Instructable Was Created in Fulfillment of the Project Requirement of the Makecourse at the University of South Florida (www.makecourse.com)

This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)

Hi makers,

As part of the project for the make course at University of South Florida, I considered making a boat which could actually be maneuvered with the commonly held device that is a Cell phone (Android OS) making use of Bluetooth technology.

Pros of using Bluetooth for communication :

  • Easy of connectivity with Bluetooth module and the cell phone.
  • Can be configured with simple AT (attention commands).
  • Posses range of connectivity from 10 meters to 100 meters.

Parts required to build a Bluetooth controlled boat:

  1. Arduino UNO - 1no
  2. DC motor - 2no's
  3. L298 motor driver - 1no
  4. Bluetooth module (HC-05) - 1no
  5. Connecting wire
  6. HCSR-04 ultrasonic ranging module
  7. A powerful battery to run 2 DC motors (I used 9.6 V 2000mah RC car battery from Radio Shack)
  8. 9v battery to run arduino uno
  9. An android phone installed with a Bluetooth terminal

Basic skills required to build this project :

  1. Ability to code for arduino uno development board
  2. Autodesk Inventor or any other similar 3D design tool to model the Boat using 3D printer
  3. basic wiring skill.

Operation of the project:

  1. Connect android phone to the Bluetooth module HC-05.
  2. Send data to Bluetooth module from the Android phone which would then be processed by Arduino Uno, based on the data received by the Arduino Uno, motors are controlled.
  3. Motors would be connected to propellers on either side of the boat in order for the boat to move, which then causes the boat to move in a particular direction based on the data sent from the android phone.

Steps to build the boat and make it work:

  1. Design of Hull and other parts of the boat using Autodesk Inventor.
  2. Once design is complete get your design printed at the 3D shop.
  3. Circuit schematic of the control system.
  4. Arduino C++ code to make the control system work.
  5. The day!! Put together all parts of the boat from the 3D shop and the control system. Boat should be ready to run.

* Android app to send data to the Bluetooth module (HC-05) would be a Bluetooth Terminal downloaded from the google play store

Step 1: Design of Hull and Other Parts of the Boat Using Autodesk Inventor

"This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)"

Autodesk Inventor is one of the awesome tools available to design, simulate and create animations of the 3D objects designed just like AutoCAD.

Link to download and know more about Autodesk Inventor: http://www.autodesk.com/products/inventor/overview

If you are new to to Autodesk Inventor, Watch tutorial videos on how to use various tools available in the Autodesk inventor which provides various way to come about designing anything you think of.

Please take a look at the attached images to get a brief idea on how the boat looks like in this project.

Once you are ready with your design go ahead and jump to the 3D print shop and get the parts printed.

Note: Make sure the size of the parts designed can be accepted in the 3D print shop, if the design is huge please make sure the huge part is split into multiple parts and can be rejoined after the print.

Step 2: Circuit Schematic and Connections

"This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)"

Take a look at the attached picture of the schematic to help you through the connections.

If in case you would like do it without having to zoom about the schematic in the pic, I shall provide you with sufficient resources to connect devices to arduino.

The bluetooth module HC-05 by default operates in 9600 baud rate(bits per second) and the initial configurations of the module is done using AT(attention commands). The enable pin is pulled high before turning on the bluetooth module HC-05 to enter the AT mode. please find the following link to know more about the bluetooth module HC-05: http://www.electronica60norte.com/mwfls/pdf/newBlu...

To know more about the At commands and its ability to configure the working of the Bluetooth module please follow the following link: https://alselectro.wordpress.com/2014/10/18/blueto...

The receive pin of the HC-05 module is connected to a voltage divider using 2 resistors in order to level down the 5volt output from the transmit pin of arduino to 3.3volt level in order to prevent damage to the Bluetooth module.

L298 motor driver circuit consists of 2 H-bridge inside it in order to control two motors as required by the project. Enable pins on the driver are used to control the speed of the motor by making use of PWM pins of arduino. L298 accepts higher voltages and is only dedicated to run the motors and the logic level controller of the L298 motor driver requires 5V supply to maintain logic level on the board. Please check the following link for more information about L298 motor driver circuit https://www.sparkfun.com/datasheets/Robotics/L298_...

HC-SR04 is a ultrasonic range finder which would be used to measure the distance of any obstacle ahead of the boat during action, If any obstruction is nearing then the propellers rotate backwards to prevent collision of the boat. Trigger pin is supplied with 10 microsecond signal to trigger the burst of signal from HC-SR04 and the echo pin listens to the reflected signal to calculate the distance based on the delay in the received signal from the transmitted signal. please take a look at the following link for more information about HC-SR04: http://www.micropik.com/PDF/HCSR04.pdf

DC Motors Various types of motors are available for toys, pick any dc motor which has high RPM to get the boat pulling faster.

HC05

TX ----> RX (PIN 10 OF ARDUINO)

RX-----> TX (PIN 11 OF ARDUINO)

VCC----> 5V

GND---> GND ARDUINO PIN

L298

VSS ----> 5V

VS -------> 9V

OUTA-----> MOTOR1

OUTB------> MOTOR1

OUTC------> MOTOR2

OUTD ------> MOTOR2

INA ----------> ARDUINO PIN 2

INB -----------> ARDUINO PIN 3

INC -----------> ARDUINO PIN 4

IND -----------> ARDUINO PIN 5

ENA----------> any PWM pin (or connect it to 5v for default full speed)

ENB ----------> any PWM pin (or connect it to 5v for default full speed

HC-SR04

ECHO ---------> PIN 8 ARDUINO

TRIGGER ------> PIN 9 ARDUINO

VCC --------------> 5V

GND --------------> GND ARDUINO

Step 3: Arduino C++ Sketch and Description

"This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)"

/******************************************

PURPOSE: Bluetooth controlled boat(motor's)

Created by Rakshith C M [U93539962]

DATE: 12/2016

**********************************************/

#include "SoftwareSerial.h" // Serial communication library

#define echoPin 8 // This is the echo pin

#define triggerPin 9 // This is the trigger pin

SoftwareSerial mySerial(10, 11); // RX, TX

const int motorRA = 2; // antickock wire RED and pin 2

const int motorRC = 3; // clockwise wire black and pin 3

const int motorLA = 4; // anticlock wire GREEN and pin4

const int motorLC = 5; // clockwise wire YELLOW and pin 5

const int enA = 9; // PWM pin to adjust the speed of the motor

const int enB = 6; // PWM pin to adjust the speed of the motor

/***************************setup function****************************************************/

void setup() {

pinMode(motorRA,OUTPUT); // Pin Mode configuration

pinMode(motorRC,OUTPUT);

pinMode(motorLA,OUTPUT);

pinMode(motorLC,OUTPUT);

pinMode(enA,OUTPUT);

pinMode(enB,OUTPUT);

Serial.begin(38400); // Serial Communcation at 38400 baud rate
mySerial.begin(9600); // Serial communication with HC-05 at 9600

/***************************Main loop*********************************************************/

void loop() //Infinite loop
{

if (mySerial.available()) // If data from myserial avaliable at 9600 baud enter the loop

{

char val = mySerial.read(); // read the data received from Serial and store in val

Serial.write(val); // Write to Serial monitor

switch(val)

{

case '1':

{

forward(); // Method call for forward movement of the boat

break;

}

case '2':

{

backward(); // Method call for Backward movement of the boat

break;

}

case '3':

{

halt(); // Method call for halt of the boat

break;

}

case '4':

{

left(); // Method call for left turn of the boat

break;

}

case '5':

{

right(); // Method call for right turn of the boat

break;

}

}}

mySerial.flush(); // flush myserial

float distance = readprox();

if(distance<5) {

halt();

delay(2);

backward();

delay(4000);

halt();

mySerial.print("Caution:Obstacle obstruction");

} }

void forward()

{

digitalWrite(motorRC,LOW); // write HIGH to motor control pin

digitalWrite(motorRA,HIGH); // Write LOW to motor control pin

digitalWrite(motorLA,HIGH); // write HIGH to motor control pin

digitalWrite(motorLC,LOW); // Write LOW to motor control pin

mySerial.print("Forward\n");

}

void backward()
{

digitalWrite(motorRC,HIGH);

digitalWrite(motorRA,LOW);

digitalWrite(motorLA,LOW);

digitalWrite(motorLC,HIGH);

mySerial.print("Backward\n");

}

void halt()
{

digitalWrite(motorRC,LOW);

digitalWrite(motorRA,LOW);

digitalWrite(motorLA,LOW);

digitalWrite(motorLC,LOW);

mySerial.print("Halt\n");

analogWrite(enA,0);

analogWrite(enB,0);

}

void left()
{

digitalWrite(motorRC,LOW);

digitalWrite(motorRA,HIGH);

digitalWrite(motorLA,LOW);

digitalWrite(motorLC,LOW);

mySerial.print("Left\n");

}

void right()
{

digitalWrite(motorRC,LOW);

digitalWrite(motorRA,LOW);

digitalWrite(motorLA,HIGH);

digitalWrite(motorLC,LOW);

mySerial.print("Right");

}

float readprox()
{

digitalWrite(triggerPin,LOW); //Trigger pin is set to LOW

delay(2); // Delay 2 millisecond

digitalWrite(triggerPin,HIGH); //Trigger pin is set to HIGH

delay(10); // Delay 10 millisecond

digitalWrite(triggerPin,LOW); //Trigger pin is set to LOW

float distance = pulseIn(echoPin,HIGH); // Read the echo pulse from the proximity sensor

float CM = (float)distance/58; //Cm's // Convert duration to centimeters

return CM;

}

code description:

  1. Include "SoftwareSerial.h" library for the serial communication with Bluetooth module
  2. Set appropriate ports as Input and output
  3. Begin serial communication at 38400 baud rate for the Serial Monitor (input and output) // AT mode
  4. Begin serial communication at 9600 baud rate to communicate in the data mode of the Bluetooth module HC-05
  5. we will be using the object created for "software Serial" at 9600 baud rate in order to initiate transfer in and out of the Bluetooth module.
  6. The IF statement in the loop checks whether any communication is going on. When the IF statement hold true then the value is read from the the HC-05 and passed onto a switch-case statement.
  7. Based on the data received in the variable for example if a digit '1' (char in the code) is sent from the android phone then the case statement causes the motors to rotate, Similar operation can be performed on various type of data received (ASCII) a particular operation can be performed.
  8. The above code has various methods outside the void loop which would be called only when necessary for example piece of code to turn on the motors would be in a particular method.
  9. Therefore, based on what type of ASCII value is sent form the android phone a particular method is called with the help of a switch-case statement.

Step 4: Time to Burn the Code and Test It Before Getting the Toy to Water.

"This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)"

It's time to get everything working.

Make sure all connections are intact and go ahead burn the code to arduino uno.

The Bluetooth module starts flashing. Grab your android phone and search for HC-05 and connect to it and the default password is "1234". Once the module is connected the LED's start blinking for every 2 secs.

I have configured buttons in the app to send character 1 (forward) , 2(back), 3(halt),4(left) and 5(right). Based on the character sent the motors rotate accordingly to cause the boat to move in a particular direction.

character 'd' is sent to get back the distance of the obstacle upfront. Every operation is printed on the monitor for indication.

I Hope enough information has been conveyed to get started with building your own toy and do more cool stuffs like getting all the sensor data from the surroundings through Bluetooth which would be very handy to monitor various factors.

Thank you,

Rakshith C M