Problem with HC06 BT module and Led

Hello,

I am currently working on my simple project, the purpose of my project is controlling led with my smartphone using bluetooth. I am using HC06 as my module.
I have problem with this project, the serial communication working fine with ide arduino serial monitor, but it get trouble when i plug the Hc06 module to arduino, the serial communication didn't work with ide serial monitor and even with my smartphone that has been connected to the module. The code that i made is simple, it should makes led turning on or off when i give a command from my phone. I did my research, but i didn't get the proper solution to this problem.

bool state=false;
byte ledPin=13;
void setup() {

Serial.begin(9600);
pinMode(ledPin, OUTPUT);

}

void loop() {

if(Serial.available()){

char data = Serial.read();

if(data == ‘t’){

state=!state;

digitalWrite(ledPin, state);

}

}

}

Thanks

How are you connecting the hc06? Not to pins 0 and 1 I hope. You can't connect the hc06 and serial monitor at the same time. Which Arduino are you using? If an Uno, You could create a second serial port with a software serial library.

Arduino UNO based project to control LEDs by using an android smartphone | Arduino UNO based project to control LEDs by using an android smartphone - Electronics Lovers ~ Technology We Love

There could be three problems

  1. You cannot upload code with Bluetooth connected. I believe you already know that
  2. You cannot use the Serial monitor to send commands, only to watch commands sent from phone, and it is not the object of your exercise anyway.
  3. Your wiring is the wrong way round. It should be Rx>Tx and Tx>Rx

A successful connection between phone and bluetooth, i.e. LED goes solid, means just that. It does not mean a successful connection to Arduino. Check the wiring

There is probably nothing wrong with your code and there is definitely nothing wrong with using bluetooth on pins 0,1. Indeed quite the opposite. Have you tried the code using just the serial monitor and bluetooth disconnected? If the works, there is definitely nothing wrong with the code. Check the wiring.

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

after you have checked the wiring.

I can't say I have every used a HC-06 but I do use HC-05s.

The HC-05s cannot be wired directly to a Uno as the Uno's serial signals are based on 5 volts and the HC-05s are based on 3.3 volts. You have to use a resistor pair to drop the voltage from the Uno down to 3 volts from 5 volts. With respect to the signals going from the HC-05 to the Uno, I use a 74HCT125 to boost the voltage from 3 volts to 5 volts.

KenK:
You have to use a resistor pair to drop the voltage from the Uno down to 3 volts from 5 volts.

Good practice, but probably not fatal if you don't, and probably not relevant to the problem.

With respect to the signals going from the HC-05 to the Uno, I use a 74HCT125 to boost the voltage from 3 volts to 5 volts.

Completely unwarranted, and definitely not relevant to the problem.

See if these help:

Turning a LED on and off part 1

Turning a LED on and off part 2. Now with 2 way control.

Turning a LED on and off part 3. 2 way control with 3 LEDs with 3 switches

Try this web site::