Bluetooth Robot

I am testing around a bluetooth module. And this is the result of the test.

I have recently bought a HC-06 bluetooth module, and after couple of hours of searching in the internet, I’ve figured out how to use the module. Detailed info and source here.

hc06-top-side

The module runs on 3.3v-5v, default pairing code 1234 and baudrate is 9600, N, 8,1. For only communication purposes, you don’t need to mess about the AT commands(it is in the online also).

hc-06-and-hc-05-source-wavesen-data-sheet

If you want to test the module if it works or not, i have a way, Download PUTTY here, you need another USB>Serial converter(I’ve used PL2303) and a bread board. Then connect TXD(pl-2303)>>RXD(HC-06), RXD(pl-2303)>>TXD(HC-06),  GND(pl-2303)>>GND(HC-06),  VCC 3.3v(pl-2303)>>VCC(HC-06).

jy-mcu-bt_board-v1-05-bottom-side

Run Putty,  from connection type radio button, select serial,  From Serial line, Edit that to com6(in my case), click open. This will open the desired bluetooth com port.  Run putty again, from connection type radio button, select serial,  From Serial line, Edit that to com8(in my case), click open. This will open serial port of pl-2303. And you can transmit and receive your keystrokes.

Here is a slight little problem. You need to know which com port of your pc is used for communicating with which device. Is it a real problem? No. Just right click Computer>manage>device manager>ports (Com & LPT). And here will show the ports. You can identify the pl2303 port because of it named as prolific or similar. And another confusion is which port is used for bluetooth device? The answer is after pairing with HC-06 you need to try each port one by one in putty. And whenever a successful connection is made. The LED of the HC-06 will stop blinking and it will stay on always.

Ok, Enough .. Here comes the code for arduino(atmega8). Will work on other 168/328 too.

[code language=”cpp”]
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(11,INPUT);
pinMode(12,INPUT);
pinMode(13,INPUT);
pinMode(14,INPUT);
pinMode(15,INPUT);
pinMode(16,INPUT);
pinMode(17,INPUT);
pinMode(18,INPUT);
analogWrite(9,80);
analogWrite(10,80);
}

void loop() {
// see if there’s incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it’s a capital H (ASCII 72), turn on the LED:
if (incomingByte == ‘w’) {
GoForward();
}
// if it’s an L (ASCII 76) turn off the LED:
if (incomingByte == ‘s’) {
GoBackward();
}
if (incomingByte == ‘a’) {
TurnLeft();
}
if (incomingByte == ‘d’) {
TurnRight();
}
if (incomingByte == ‘i’) {
analogWrite(9,80);
analogWrite(10,80);
}
if (incomingByte == ‘u’) {
analogWrite(9,100);
analogWrite(10,100);
}
if (incomingByte == ‘y’) {
analogWrite(9,120);
analogWrite(10,120);
}
if (incomingByte == ‘t’) {
analogWrite(9,140);
analogWrite(10,140);
}
if (incomingByte == ‘r’) {
analogWrite(9,180);
analogWrite(10,180);
}
if (incomingByte == ‘o’) {
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}
}
}

void GoForward()
{
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}

void GoBackward()
{
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
}

void TurnRight()
{
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}

void TurnLeft()
{
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}

void HardLeft()
{
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}

void HardRight()
{
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
}
[/code]

Most of the functions are self-explaining. And some of them are unused and for later uses. This hardware was made for one of my previous PID Line follower project and that’s another story 😀 .

The Hardware/Circuit diagram?
You need to wait until my next free time….

Comments (2)

  1. Pingback: Bluetooth Robot-2 | khairulhasanmd

  2. Pingback: Bluetooth Robot-2 – Intelligent Technology

Leave a Reply

Your email address will not be published. Required fields are marked *