Learning HC-05 but cannot get past basics

I'm trying to just do a basic data display using an HC-05 and appinventor. I have discovered a problem having nothing to do with the appinventor so I have put that on hold until I solve this issue. In summery, when I connect a variable pot to Pin A0 on my Arduino Uno with the HC-05 connected, I can see the data with a terminal program (Serial Bluetooth Terminal) on my Android phone but there are additional digits added and repeats of data. This condition comes through on the appinventor app as well but not as obvious as with the terminal program.

So here's the details:

I've connected a potentiometer to 3.3V and ground with the output connected to Pin AO. I've connected the HC-05's Vcc to 5.0V and ground on the arduino and, after loading the arduino, I connect the Arduino's Tx through a voltage divider to the HC-05 Rx as well as Arduino's Rx to HC-05's Tx. I can pair the HC-05 and connect to it.

The following is my code:

[code]
/* Electronoobs Bluetooth data receive with
   Android and Arduino. transmits data from pin A0
   Remember to disconnect the Rx and Tx pins of the HC-06 when
   uploading the code

   Subscribe: http://www.youtube.com/c/ELECTRONOOBS
   Tutorial: http://www.electronoobs.com/eng_arduino_tut20.php
*/
//Inputs
int in = A0;

void setup() {
  Serial.begin(9600);   //Set the baud rate of the comunication
  pinMode(in, INPUT);   //Define the pin as input
}

void loop() {
  //Read the analog value
  float val = analogRead(in);

  //Divide by 310 to obtain a range from 0 to 3.3V
  float val2 = val / 310;

  //Use serial.print to send the data in a "text" format
  Serial.println(val2);

  delay(400);//Small delay between each data send
}
[/code]

Here's the Serial Monitor:

And here's the output of the terminal program:

Note there a multiple times a "1" was added to the data. In the past, there were also multiple times the data was repeated with the same time stamp and there were multiple digits added rather than just one as shown here.

What's going on!

Thanks for your time.

Doug

Best to use a logic level converter like:
https://www.walmart.com/ip/SparkFun-Logic-Level-Converter-Bi-Directional/650112214

You can get tgem for about $1 each if you do a little searching.

Resistors are really poor at low-noise operation.

mrburnette:
Thanks for your reply. So, are you saying that is the source of my problem?

This is enough to show that the title of your post is erroneous, and you have probably learned all you need to learn about HC-05. I would be very suss about reply #2. While it seems not to be really necessary, it IS good practice to to ensure 3.3v at Bluetooth Rx, but the way you are doing it is the way everybody else does it, and surely not the cause of your problem.

For all that, I can't say much about what the problem really is, but I suspect it is all about timing, even though I note that you do have a delay in the loop - a large one, not a small.

Since you are smart enough to use hardware serial, two options offer themselves:

  1. Even though I understand the serial monitor is working perfectly, you might just try having it run simultaneously with Bluetooth, Thereby checking that the problem really is exclusivel to Bluetooth.

  2. You might configure Bluetooth and monitor to run at 115200, as this might be one of those times when speed really counts.

This might be the time when you need to know something about data buffering - something I know nothing about. I also know nothing about reading pots, but I assume that the code is essentially kosher - just needs a bit of tweaking

You appear to be using Morisch's terminal, which is essentially the go-to app these days, and I don't think there is anything to be suss about there.

I use a 1K, 2K resistor voltage divider with my HC05 modules running at 9600 baud all the time. I have had no issues.

Nor have I had any issues running at 38400 baud during setup in AT mode with the resistor voltage divider .

I set up an HC05 on my Uno and connected to serial Bluetooth terminal on my Android tablet. Running your code, I do not see the extra digit.

I suspect that the resistor network is on solderless breadboard and that the stray capactance and environmental noise is a potential concern.

Intermittent issues are always a P.I.T.A. to locate & solve.

Years ago, I built this device to deal with serial issues around my work area:
https://forum.arduino.cc/t/the-qbf-the-quick-brown-fox-for-serial-diags/229468

In fact the data I show is close to simultaneously - the serial monitor shows my home time zone, the terminal program is in my current time zone.

I’ll try that.

My luck! Thanks for doing that.

No, I created a purpose made jumper that includes the soldered resistors and connector for the HC-05.

The bi-directional converters are still the "best" approach outside of an I/O pin being identified as "5 Volt tolerent"
https://learn.sparkfun.com/tutorials/logic-levels/all

Contradiction in terms, and irrelevant to boot. By simultaneous, I mean simultaneous. The same data is fed to both together. This may not be too revealing, but may yield something, and is not hard to do.

I had difficulty changing the baud rate on one of my modules, but finally got it changed to 115200 on another module. I then changed the baud rate in the Arduino code to 115200 but again got the same results as before. This time the Terminal data is "simultaneous" with the serial monitor. You can see extra digits are added as well as multiple data points with the same time stamp.

So, still no joy!

Would you be willing to change the HC05 back to 9600 baud and try with software serial. Just to see if having serial monitor and the HC05 both connected to the same serial port may be a cause.

HC05 TX to Uno pin 2 and HC05 RX to Uno pin 3 via the voltage divider. Works fine on my setup.


/* Electronoobs Bluetooth data receive with
   Android and Arduino. transmits data from pin A0
   Remember to disconnect the Rx and Tx pins of the HC-06 when
   uploading the code

   Subscribe: http://www.youtube.com/c/ELECTRONOOBS
   Tutorial: http://www.electronoobs.com/eng_arduino_tut20.php
*/
#include <SoftwareSerial.h>

SoftwareSerial ss(2,3);

//Inputs
int in = A0;

void setup() {
  Serial.begin(115200);   //Set the baud rate of the comunication
  //pinMode(in, INPUT);   //***** not required for analog in ****
  ss.begin(9600);
}

void loop() {
  //Read the analog value
  float val = analogRead(in);

  //Divide by 310 to obtain a range from 0 to 3.3V
  float val2 = val / 310;

  //Use serial.print to send the data in a "text" format
  ss.println(val2);
  Serial.println(val2);

  delay(400);//Small delay between each data send
}

For what it’s worth, here’s a comparison of the last data I presented:

OK, it was worth a try. And do I understand correctly that you have never had a problem with the data on the serial monitor?

When your module is connected to the phone, what is the pattern of flashing indicator leds that you see?

Is it a pattern of 2 rapid flashes (on, off, on, off, takes ≈ 1 second) then a pause (off) of several seconds?

I ask because there were other postings where a defective module was causing latency issues and the flash pattern was not correct.

Yes, that's correct

Yes, that's correct

Yes, will do it momentarily.

Question: does the Baud rate I tell the Arduino to use (eg, Serial.begin(9600)) in the Arduino code have any effect on the HC-05 or does it just dictate what Baud rate is being sent to the serial monitor? In other words, do I have to have the Baud rate set for the HC-05 the same as in my arduino code?

If you have the HC05 connected to software serial then the Serial baud (Serial.begin(baud)) rate is for serial monitor only. The software serial baud rate (ss.begin(baud)) is for the HC05.

They do not have to be the same.

So I used your code but changed the Serial.begin to 9600 - guess that doesn't make a difference. But the results are that all is good on the serial monitor but nothing on the terminal program other than a good connection. Haven't found any combination that makes it work.

I saw some of you other communications about this issue and have concluded I need a different HC-05. My is Version 4.0-20190728. I also think at least one is defective also and neither will hold a change in baud rate.

Thanks for your effort!

Will continue this thread if the new one doesn't work!

Probably correct. HC-05 is a Bluetooth v2 device, and any that purport to be a a v3 or v4 device are likely to be junk. I think it is pretty clear though, that these deices are quite OK so long as you do not want to send AT commands, and most people don't, or don't need to. The latter probably includes you, despite what I said, and reverting to 9600 would be a good idea.

None of the above alters the fact that your problem is unique to you - so far....

I'm surprised you ask the question, as this is surely not a problem for you. Since you are using hardware serial, the monitor AND Bluetooth must match match what you call in your code, which surely you have already ensured. If there is a mismatch, I'm sure you would get much more gibberish out of Bluetooth than the odd extra digit. There should be inverted question marks and all sorts of other crap.

Received my new HC-05 from DSD Tech on Amazon and all works perfectly. It uses version 2.0-2020060. Sure waisted a lot of time on the other brand!