Trouble wiring an HC06 Bluetooth module

Hello all,

This is my first post, so if something isn't in the right format, let me know! Anyway, my problem arises when I try to wire an HC06 bluetooth module into an Arduino Uno R3 (w/atmega328p) constructed on a breadboard. My project was to make a light detector that I could turn on and off at will by sending a command to do so using a PC terminal program (PuTTY) and a bluetooth dongle. I followed this Arduino tutorial up to the point where USB functionality was mentioned as optional:

(I also had: 1.) A photoresistor hooked up to 5v & GND via 10k ohm resistor with connection to Analog A0 in between, and 2.) An LED connected to digital pin 11 and GND via a 220 Ohm resistor)

I used this module:

http://www.amazon.com/gp/aw/d/B0093XAV4U/ref=redir_mdp_mobile?psc=1&redirect=true&ref_=oh_aui_detailpage_o02_s00

(**Note: since the module's RX pin is set to work under 3.3v, I routed the Arduino's TX pin as input to a separate voltage divider exactly like the one mentioned in the section below...)

(**For reference, here's the pinOut map I used for the Atmega328p:
http://www.instructables.com/file/F1PWPB9H337KORO
)

After researching, I was led to belive that the module would work nominally if the input voltage was 3.3v, and conveniently the Arduino Uno R3 comes with a 3.3v pin labled "3V3" if it comes ready-made. However, I did not have the voltage regulator component necessary to drop down the voltage at hand, so I improvised and created a voltage divider. To put it simply, the circuit was connected in the shape of a "T", with the left leg connected to 5v as input via a 10k Ohm resistor, the bottom leg being the theoretical 3.3v output connecting to the module VCC, and the right leg connecting to GND by two 10k resistors summing up to 20 Ohms (alternatively, I could've used a 1.2k resistor and 2.2k resistor, respectively). My assumption was that if I provided 3.3v (regardless of whether the divider's input voltage came from a 5v-outputting digital I/O pin or from the 5v power pin), the bluetooth module would work. I connected the divider's input to multiple places, including directly to the VCCs (pins 7 and 20 on the atmega), and several other available output pins, but the HC06 module wouldn't operate. I replaced wires, changed breadboards, and even scrapped the divider and connected VCC to 5v directly (caused the module to turn on, but data could not be transmitted). I connect everything back to the ready-made Arduino Uno board, and connect the module's VCC to the 3V3 pin (w/o voltage divider), and this has since been the only way that I could get the HC06 to work properly. Is there any way to get the module to work on a handmade Arduino Uno without using the 3.3v regulator, or is that unavoidable? Please advise

-rjavier441, CA, USA

Can you draw a diagram of your wiring and post a photo of it. A diagram is much easier to understand than a written description.

I got one of these HC06 modules and I wired it according to the diagram in one of the links at the bottom of the page.

...R

rjavier441:
Is there any way to get the module to work on a handmade Arduino Uno without using the 3.3v regulator, or is that unavoidable?

Very probably, but it is entirely dependent on how closely your handmade Arduino resembles a real one. The device you have is a plain-vanilla HC-06 bluetooth and, if you look at the back of the module, you will see that it clearly states that the power Vcc is 3.6 - 6v. This means you should assume 3.3v is not enough, 5v is enough, and indeed is starting to look like a good idea. Another really good idea is to put (nearly) all those resistors in the bottom drawer and forget about them for a while. All you need to know is where the equivalent of the Uno's D0,D1 pins are, and I think you will be wasting your time trying to draw anything.

You might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

@All: I've attached a schematic if you'd like to have a look.
@Nick: It does work if i put in 5V into VCC, but the last time i did that, the commands i'd be typing from my terminal would get jumbled up. Sometimes they wouldnt even match up with the letters i'd be typing. I am willing to try again and see what happens, though.

Reducing the picture to a size a little less insulting, cutting out the excess junk, and having it the right way up might be rather helpful but, if you can get anything at all with 5v power, the real problem is more likely to be code - which is conspicuously absent. There is no way that the jumbling up you refer to is caused by the power supply.

Resize your pic. to a maximum of 1000 pixels on the longest side. Also, post your code.

// Per.

Here's the code I used to receive data via the HC-06:

//PARSER CODE (SERIAL)-----------------------------------------------------------------------------------------
if(Serial.available() > 0)
{
inputChar = (char)Serial.read(); //Reads one byte, interperets it as an ASCII Char, and puts in inputChar
if(mode == 0)
{
if(inputChar == ':') //Checks for the ':', which indicates the end of the commandWord
{
commandWord = '\0';

  • i = 0;*
  • mode = 1;*
  • inputChar = '0'; *
  • }*
  • else if(inputChar == ',')*
  • {*
    _ commandWord = '\0';_
    * i = 0;*
    * ready2compare = 1; //will initialize the comparison of commands to validCommands dictionary*
    * inputChar = '0';*
    * }*
    * else*
    * {*
    _ commandWord = inputChar; //If the inputChar isn't the ':', the read byte (aka ASCII character) is added to the string at position 'i'
    * inputChar = '0'; //inputChar is cleared to make way for next reading*
    * i++;
    }
    }*_

_ //After reading the commandWord and the ':', what is expected next is the value with which to change the times (saved as a string):
else if(mode == 1)

{
if(inputChar == ',') // The comma signifies end of received value. If none is present, code will assume the minute val is next.
{
receivedValue = '\0'; //buffer string where value is saved
receivedInteger = atoi(receivedValue); //Since receivedValue is a char, we convert it to an int using atoi fucntion (C++).
inputChar = '0';
i = 0;
mode = 0;
ready2compare = 1;
}
else if(inputChar == ':') // The colon signifies that the minute value is next.
{
receivedValue = '\0'; /*This section of code is specifically for when we are receiving the current time requested by the returnTime command.
The received current time is expected to be in HH:MM:SS format. When 'HH:' is received, the two digits for hours will*

* be stored in receivedValue, then once the ':' is encountered, the loop will break, and go to the next loop, which is*
intended to parse the values for minutes and seconds./
receivedInteger = atoi(receivedValue); //Since receivedValue is a char, we convert it to an int using atoi fucntion (C++).
inputChar = '0';
i = 0;
mode = 2;
}
else*

* {
receivedValue = inputChar;
inputChar = '0';
i++;
}
}
else if(mode == 2) //This loop will convert the minutes and seconds to the format used in this code (MM:SS ---> militaryTime)...Don't really need seconds...?
{
if(inputChar == ',') // Comma signals the end of command*

* {
receivedMinuteValue = '\0';
receivedMinute = atoi(receivedMinuteValue); //Converts Minute(received as chars) into Minute(as short int)
i = 0;
mode = 0;
ready2compare = 1;
}
else if(inputChar == ':')
{
receivedMinuteValue = '\0';
receivedMinute = atoi(receivedMinuteValue);
i = 0;
mode = 3;
}
else*

* {
receivedMinuteValue = inputChar;
inputChar = '0';
i++;
}
}
else if(mode == 3) //If a seconds value is sent, i will not use it, but to avoid code getting confused, i will store it somewhere to delete.
{
if(inputChar == ',')
{
receivedSecondsValue[0] = '\0'; //Clears seconds value...
i = 0;
mode = 0;
ready2compare = 1;
}
else*

* {
receivedSecondsValue = inputChar;
inputChar = '0';
i++;
}
}
}_

*

To make your code readable you will need to modify your post to put your code in code tags (the # button) so it looks like this

And your image is much too large to see on the screen. Please resize it so it is a max of 1000 pixels in any direction.

Your code seems much longer than this demo that I used.

// http://www.instructables.com/id/Arduino-AND-Bluetooth-HC-05-Connecting-easily/step3/Arduino-Code/
// modified to work with Serial2 on Mega
// worked first time

// This program shown how to control arduino from PC Via Bluetooth
// Connect ...
// arduino>>bluetooth
// D11   >>>  Rx
// D10   >>>  Tx
//Written By Mohannad Rawashdeh


// you will need arduino 1.0.1 or higher to run this sketch

#include <SoftwareSerial.h>// import the serial library

//SoftwareSerial Serial2(10, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer

void setup() {
  
//  Serial.begin(9600);
//  Serial.println("Starting BlueToothTest.ino");
  
  Serial2.begin(9600);
  Serial2.println("Bluetooth On please press 1 or 0 blink LED ..");
  pinMode(ledpin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
   if (Serial2.available()){
       BluetoothData=Serial2.read();
       if(BluetoothData=='1'){   // if number 1 pressed ....
         digitalWrite(ledpin,1);
         Serial2.println("LED  On D13 ON ! ");
       }
      if (BluetoothData=='0'){// if number 0 pressed ....
        digitalWrite(ledpin,0);
        Serial2.println("LED  On D13 Off ! ");
      }
  }
  delay(100);// prepare for next data ...
}

...R