JDY-31 Bluetooth module works great with Software Serial but doesn't with Hardware one (RX/TX pins)

Hi All!

I having a problem interfacing between my Arduino Uno and JDY-31. Something weird is going on. When I connecting JDY-31 to pins 10 and 11 and using Software Serial bound to those pins I able to send and receive data great, but when I reconnecting it to RX/TX pins and trying to do the same with Hardware Serial it seems that nothing happens when I sending the data from my Android phone.

Just to recap and prevent common question - I connecting Arduino TX to JDY-31 RX through voltage divider (1.1k and 2.2k resistor. Tested with my multimeter - getting ideal 3.3 volts here.

I also did loopback test of my Arduino RX/TX pins (RESET to GND and jumper between RX/TX) - test PASSED (receiving what I sending in Serial monitor).

Did the same with JDY-31 (RX to TX jumper) - TEST PASSED (receiving what I sending in Bluetooth terminal on Android)

Sketch I uploading when I connecting JDY-31 to Hardware Serial (RX/TX) - Doesn't works:

void setup() {
  Serial.begin(19200);
  pinMode(13, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    String command = Serial.readString();
    Serial.print("Received: ");
    Serial.println(command);

    if (command == "on") {
      digitalWrite(13, HIGH);
    }

    if (command == "off") {
      digitalWrite(13, LOW);
    }
  }
}

Sketch I uploading when connecting it with Software Serial (10 and 11 pins) - Works Great:

#include <SoftwareSerial.h>

SoftwareSerial EEBlue(10, 11);  // RX | TX

void setup() {
  EEBlue.begin(19200);
  pinMode(13, OUTPUT);
}

void loop() {
  if (EEBlue.available() > 0) {
    String command = EEBlue.readString();
    EEBlue.print("Received: ");
    EEBlue.println(command);

    if (command == "on") {
      digitalWrite(13, HIGH);
    }

    if (command == "off") {
      digitalWrite(13, LOW);
    }
  }
}

Of course I disconnecting RX/TX pins when I uploading sketch for Hardware Serial case and powering Arduino from 9v battery through jack instead of USB when testing.

I am very confused. Any help deeply appreciated.

Thank you :slight_smile:

Uno. Hardware serial using pins 0 and 1. Pins 0 and 1 are the programing port of the Uno. Basically, the Uno des snot have a good hardware serial port for you to use.

If you are using a 9V battery like this.


Don't.

Hi. Yes I using 0 and 1 and yes I know that I can't use it along with the USB programming port at the same time. I have updated my post a little. What's wrong with 9v battery?

Use of this thing


and the words "9 volt battery" may provide an answer.

Well, ok I see. But this is definitely doesn't reason of my issues. My battery is fresh, I also tried other power sources and I getting it all works great with Software Serial even with 9v battery.

Anyways, good luck.

There is nothing wrong with using hardware serial on a Uno, which goes quite some way to explain why the pins 0,1 are clearly marked Rx,Tx. All you need is to know how to do it, which is clearly the case here.

Since your codes appear to be identical apart from the actual serial commands, I guess you should assume the problem is mechanical - something silly in the wiring that will probably only happen once. I assume you are using the same Bluetooth for each instance , or that with hardware serial is indeed properly configured for 19200 baud.

If you have other power sources, stick with one of them for the time being.

1 Like

Hi Nick. Thank you for replying! Yes, I think you are right and the problem is mechanical. But I have no idea where this problem is. I using the same wires, jumpers and resistors for both experiments... The only difference is a pins to which I connecting RX and TX wires. What do you mean when you saying that it only happen once?

According you assumptions:

  • I using the same Bluetooth module, right.
  • 19200 is correct baud rate, since it set it with AT command, it was confirmed with AT response and further inquire AT command.

Are there female headers on the Uno? Perhaps the Rx and Tx have gotten worn from the connecting and disconnecting for upload. If there are locations to solder a male pin at the Rx and Tx, perhaps you could install them and use a jumper wire with female end when connection to hardware serial.

The more stupid the mistake, the more likely it is that you will only make it once....
El cheapo breadboard, perhaps?

You can absolve Arduino and your code by disconnecting Bluetooth and sending the data from the serial monitor - at the correct speed.

Just to humour me, and pretty secure in the knowledge that you don't have a good reason to configure at 19200, could you reset to 9600 and see if you can get a result?

Hi Nick, thank you for all your help and suggestions.

Today I tried with another Bluetooth module I have - hc-05. It appears that it works good with RX/TX pins on the same breadboard, same Arduino, same wires, jumpers, resistors, etc. The only the thing I did is swapped out the module it self.

The other problem that I can't pair this device with my Android phone, only with Windows PC, but this is previously know issue and different story.

Based on that there is only conclusion that it is something wrong with my JDY-31 module. At least I can't assume anything else, do you?

What I going to do is to purchase another JDY-31 module (may be even x2) and see what happens.

This will take about 2 days to get it delivered, but I will write here my final results for sure.

Thank you!

Hah! I did not appreciate what you were using, and changing to HC-05 is a really good idea. The JDY is a stinker and you should NOT double your chances of grief by getting another one. Cancel your order, now, at once and immediately...!

You have proven your self you are on the right track with the HC-05, so stay on it.

IF you are referring to HC-0x, I think this is nonsense. There are fake and bad HC-0x about but kosher HC-0x/Arduino is a marriage made in heaven, and I have never heard of a comms problem. The only thing I can guess at is that you are using the Morisch terminal and it is in BLE mode, thereby precluding it from seeing HC-0x but Android should be be able to see HC-05 in its settings anyway, so I'm far from sure what is going on here!

IF HC-0x is working with windows PC, that is enough to prove it is kosher.

Please explain more your issue with pairing an HC05 with your Android phone. Is it truly a pairing issue in the Bluetooth Settings section of the phone or is it a connection problem with an app.?

What version of Android is on the phone, and what app is connecting?

Hi Nick! Well I am definitely not an expert in this area, so I rely on your experience about choosing the right Bluetooth module. HC-05 was the one I started with, but after experiencing issues pairing this device to my Android phone (Samsung Galaxy S21FE) I decided to try another one and it was JDY-31. It pairing perfectly with my Android and it worked with RX/TX pins first times. I have used it in my 4wd robot build and I was able to control my robot with it from my phone when it was connected to RX/TX. But I have worked on another aspects of my robot a while and when I've tryied to control it with Bluetooth again I discovered that it no longer working. I assumed that it may be some conflicts with other things connected to Arduino controlling my robot. So I decided to unplug Bluetooth module and debug this issue in clean envirment using another arduino and breadboard I have. Further issues I got into you know.

Hi man! Thank you for replying me. I used my Samsung Galaxy S21FE and also tried to connect from my wife's Samsung Galaxy S21 Ultra. Both phones discovering HC-05 device, but when I trying to pair the spinner rotating for a while and finally I getting "Can't connect" error. I talking about system Bluetooth menu of Android, since I know that before using any app I need to pair it in system settings.

I can assume that it may be some security paranoia of Samsung and may be it doesn't like to connect to some kind of non-brand device, but I am not sure. Unfortunately I don't have any Chinese phones to try with them. My MacBook air M1 also can't pair. But my main working HP laptop running on Windows 10 pairing perfectly.

I have had no experience with JDY but I have seen enough badmouthing. If you have had joy with them, who am I to query that? None of this explains your problems with HC-05. It makes no sense and I can only conclude that there is something peripheral going on. I assume MacBook is macOS.

Hey Nick! Yeah it is macOS, but I don't really care about it and any other Apple devices. I only would like to have my Android to be paired with it, but I have no idea how to debug pairing issues. I guess I should google how to look into Android system logs file to figure out why it can't pair with HC-05....

I have been wondering if your Bluetooth woes might be down to inadequate power.

Hi Nick! Are you mean inadequate power of Arduino?