Help with my bluetooth HC-05 (ZS-040)

Good evening forum, I’m starting to make some projects on my arduino uno, here’s the sketch I have to control the arduino internal led with my android bluetooth

#include <SoftwareSerial.h>

SoftwareSerial Bluetooth(10, 11);                           // RX, TX
const int led = 13;                                        
char BluetoothData;                                         // char of bluetooth data

void setup() 
{
  Bluetooth.begin(9600);                                    // begin bluetooth
  Serial.begin(9600);                                       // begin serial com
  pinMode(led,OUTPUT);                                      
}

void loop()
{
   if (Bluetooth.available())                               // if there's a bluetooth data, read it
   {
     BluetoothData=Bluetooth.read();
     Serial.print("El dato bluetooth es ");
     Serial.println(BluetoothData);
     
     if(BluetoothData=='1')                                 // if data=1 ==> led on
       {  
         Serial.println("bluetooth data is '1'");
         digitalWrite(led,HIGH);
         Bluetooth.println("ON");
       } 

     if(BluetoothData=='0')                                 // if data=0 ==> led off
       {  
         Serial.println("bluetooth data is '0'");
         digitalWrite(led,LOW);
         Bluetooth.println("OFF");
       }           
    }
      delay(1000);                                            
}

In my android phone I use bluetooth serial controller with two buttons and I receive a bad data, so the led is still off, what I’m doing wrong

carlitos101:
In my android phone I use bluetooth serial controller with two buttons and I receive a bad data, so the led is still off, what I'm doing wrong

What does bad data mean? What are the hex values you are sending and what hex values are you receiving?

Your problem could be procedural rather than programming, perhaps as simple as wiring, or even power.
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

Your code works properly for me with my android bluetooth serial terminal app.

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

The software serial constructor is written from the point of view of the Arduino.

You should connect the TX of the Bluetooth module to the RX pin 10 and the RX of the Bluetooth module to TX pin 11. You may want to consider using a voltage divider on the Bluetooth RX line to reduce the 5V output from the Arduino to 3.3V for input to the module,

cattledog:
Your code works properly for me with my android bluetooth serial terminal app.

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

The software serial constructor is written from the point of view of the Arduino.

You should connect the TX of the Bluetooth module to the RX pin 10 and the RX of the Bluetooth module to TX pin 11. You may want to consider using a voltage divider on the Bluetooth RX line to reduce the 5V output from the Arduino to 3.3V for input to the module,

Thanks for the answer, I don’t know if you can show me? Maybe, it’s similar as the example for the AT control?, I’ll attach the example sheet (I’ve tried the method 1)

dsh.772-148.2.pdf (924 KB)

Connect the TX pin of the module to the RX software serial pin, and the RX pin of the module to the TX software serial pin.

Try switching your current connections,

Show a photo of your connections between the HC05 and the Arduino if you can't figure this out.

Power_Broker:
What does bad data mean? What are the hex values you are sending and what hex values are you receiving?

In my android phone I use bluetooth serial controller with two buttons and I receive a bad data,

Please provide additional information about the app on the phone and how the buttons are programmed. You might want to start with a bluetooth serial terminal app like Kai Morich's Bluetooth Serial Terminal

cattledog:
Please provide additional information about the app on the phone and how the buttons are programmed. You might want to start with a bluetooth serial terminal app like Kai Morich's Bluetooth Serial Terminal

https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=en_US

Thanks, the app I'm using is Bluetooth Serial Controller, I configured it with two buttons, controller B, ascii

Thanks, the app I'm using is Bluetooth Serial Controller, I configured it with two buttons, controller B, ascii

If your connections are correct, the problem is on the android side. When I send '1' and '0' from my Bluetooth Serial terminal app, I see the following serial output, and the led goes on and off.

El dato bluetooth es 1
bluetooth data is '1'
El dato bluetooth es 0
bluetooth data is '0'

cattledog:
Connect the TX pin of the module to the RX software serial pin, and the RX pin of the module to the TX software serial pin.

Try switching your current connections,

Show a photo of your connections between the HC05 and the Arduino if you can’t figure this out.

Thanks for the prompt answer, I’ll show a photo of the connections I made

carlitos,

I've been learning how to use Bluetooth. You have to be able to prove each component of your system.

Install this app on yr phone: SerialBlutooth by kai-morich. It's a terminal program.

It can pair then connect with your bluetooth. Don't use a sketch, just connect the Bluetooth to pins 0 & 1 and the terminal program will communicate with the IDE monitor.

Be wary of the labels "TX" and "RX" and all advice as to how to connect. There are only two ways to connect; try both and prove to yourself the right connections. The labels are ambiguous (they have opposite meanings on my Uno & Nano) and there is no standard as far as I know.

You will enjoy Bluetooth but you need to understand each part of the system.

John.

jpom:
The labels are ambiguous (they have opposite meanings on my Uno & Nano) and there is no standard as far as I know.

This is misleading nonsense. The pin order on a Nano is different but the functions are the same, and they are clearly marked. On some, maybe all, Pro Minis the pin order is same as Uno but the functions are still clearly and unambiguously marked. I think about the worst that can happen is that the arrows might be missing. And there is only one way to connect - TXtoRx and RxtoTx. Transmitters transmit to receivers - as one should expect.

I'll show a photo of the connections I made

Based on modules I have seen, I believe that the photo shows incorrect connections. However, you don't show the pin label side of the HC05 module. Try reversing the connections. Green Wire to 11, and Gray wire to 10.

cattledog:
Based on modules I have seen, I believe that the photo shows incorrect connections. However, you don't show the pin label side of the HC05 module. Try reversing the connections. Green Wire to 11, and Gray wire to 10.

Thank you very much for the answers.

First of all, Tx and Rx of the HC-05 were put on the right position, trying to reverse that, gave me no data in the Serial Monitor and the led status when I send the correct values.

I'll try the suggestions

  1. A voltaje divider at Rx side of the HC-05, like the one showed on Method 1 for the AT commands

  2. Install SerialBlutooth by kai-morich on my phone

It seems to me that is a problem of the app I'm using and the bluetooth data values sent

carlitos101:
It seems to me that is a problem of the app I'm using and the bluetooth data values sent

Holy goodness dude, have you not seen my question?!?:

Power_Broker:
What does bad data mean? What are the hex values you are sending and what hex values are you receiving?

Literally your first reply, asked twice, and it was never answered. At least now you understand why I asked. It is vital to know exactly what is going on with your system and what exact data is being transferred.

I ask one last time: What are the exact hex values you are sending, and what are the exact hex values your arduino is receiving from the HC-05?

My comments focused on the hardware serial pins (0 & 1). These are the ones with comms related labels.

On my Uno they are labelled:

“TX → 1” pin 1 (arrow points to the pin)
“RX ← 0” pin 0 (arrow points away from the pin)

Pin 1 is the Uno’s receiving pin and pin 0 is its transmitting pin.

On my HC-05:

“–> TXD” alongside an unnumbered pin (arrow points to the pin)
“<-- RXD” alongside an unnumbered pin (arrow points away from the pin)

The first pin is the HC’s transmitting pin, the second is its receiving pin.

So, two opposite conventions.

“TX” can mean this pin transmits, or it can mean this pin connects the other device’s transmitting pin (so it’s receiving).

I’ve come go by the Arduino’s onboard leds labelled “TX” & “RX”, which indicate transmitting activity from the Arduino and receiving activity to the Arduino respectively.

I connect GND to pin 0 and the TX led comes on, so the board is transmitting, so pin 0 is the transmitting pin; GND to pin 1 and the RX led lights so that’s the receiving pin. To heck with the pin labels. (I hope this technique is safe to do.)

John.

jpom:
"TX" can mean this pin transmits, or it can mean this pin connects the other device's transmitting pin (so it's receiving).

I submit this is arrant nonsense. Tx means transmit, the arrow points out, and anybody picking an Arduino up for the first time would be well-advised to take it literally - which is clearly the intent.

jpom:
"TX" can mean this pin transmits, or it can mean this pin connects the other device's transmitting pin (so it's receiving).

It depends on the reference point, actually.

TX and RX on Arduinos always mean TX as transmit FROM the Arduino and RX as receive FROM the sensor/device. This is also the convention for most devices. In fact, sometimes devices will have UART pins labeled TXD and RXD that stand for Transmit (Device) and Receive (Device) meaning that the TXD sends data from the device to the Arduino and vice versa for RXD.

I've also seen some PCB pins labeled where TX and RX were labeled with respect to the Arduino (confusing, I know). In theory this makes it easier for noobs to wire their projects since the Arduino TX wires to the device pin labeled TX (unlike the normal crossover convention).

I once had an XBee breakout board that was like that - hours of debugging and the only problem was the wonky labeling lol.

Here’s a Spark Fun Redboard Uno clone with the confusing TX and RX labeling.

Redboard TX_RX.jpg

The official UNO from the Arduino store appears to be the same