0

I have been trying to use the HC-05 Module with my Arduino Uno to control a LED, which can be turned on and off by my phone. Everything is fine when i input the values from the serial monitor. The problem only occurs when I use my phone. I am using a bluetooth terminal for HC-05 and it shows it connected. The bluetooth module is conected as its blinking slows down when I use the app.

Here's the code:

#define ledPin 8
int state = 0;

void setup() {
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, LOW);
 Serial.begin(38400); /
}

void loop() {
 if(Serial.available() > 0){ // Checks whether data is comming from the serial port
 state = Serial.read(); 
 }                                       
 if (state == '0') {
 digitalWrite(ledPin, LOW); 
 Serial.println("LED: OFF");
 state = 0;
 }
 else if (state == '1') {
 digitalWrite(ledPin, HIGH);
 Serial.println("LED: ON");;
 state = 0;
 } 
}

Here's the serial monitor output;

enter image description here Appreciate the Help!

2
  • Can u plz say what is the name of the app u are using to control hc-05 Bluetooth module to turn on and off Commented Jul 10, 2021 at 18:16
  • What phone are you using? HC-05 is basic Bluetooth. Not BLE. If you're using iOS it will not work.
    – Peter
    Commented Jul 10, 2021 at 19:00

2 Answers 2

3

Few Points that you might want to Look into.

  1. Where exactly are you connecting Bluetooth Module with Uno. Make sure you are connecting it with Rx and Tx Pin Only.
  2. First make Simple Program to send some data on Serial Say "Hello World" at every 1second and make sure your Bluetooth is connected to Hardware Serial Pins only. If you receive data on phone then you are good to receive as well If not then Try below points.
  3. Make sure your HC-05 Baudrate is correct. If you are not sure then try some others as well like 9600, 115200 etc.
  4. Make sure Rx and Tx pins are connect with correct pins of HC-05. If you know your Baudrate then try swapping Rx Tx and it should response to you.
0

When switching from serial monitor to phone, did you change how the Arduino board was powered? If you power Arduino board via VIN port, then voltage across VIN and GND needs to be STRICTLY between 7 to 12 volts, otherwise the Arduino board is unstable (even if the board is on).

More tips and supporting information can be found on Step 3 of: https://www.instructables.com/How-to-Connect-HC-05-to-Windows-1011-Mac-Apple-Com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.