HC-06 with Arduino UNO, serial pin won't change when u change the softwareserial pin setting

I use Arduino UNO, Arduino Nano, and Bluetooth module HC-06.
I use blynk (v2.27.15) on my android phone

I use 2 types of connection 1st between Arduino UNO to Arduino nano, and 2nd Arduino UNO to HC-06, the default connection between Arduino UNO to HC-06 using softwareserial pin 2,3. but when I connect my wire in pin 2 and 3, the serial monitor content won’t appear, and I connect back to pin 0 and 1, the serial monitor content appears. Why I can’t change the connection pin?

here it is my code:

#define BLYNK_USE_DIRECT_CONNECT

#include <SoftwareSerial.h>
#define RX1 2 //Connect to the TX pin of the HC-12
#define TX1 3 //Connect to the RX pin of the HC-12
SoftwareSerial DebugSerial = SoftwareSerial(RX1, TX1); // RX, TX

#define RX2 4 //Connect to the TX pin of the Arduino Nano
#define TX2 5 //Connect to the RX pin of the Arduino Nano
SoftwareSerial mySerial(RX2, TX2);

#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleSerialBLE.h>

//char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxee";
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxAS";

int A;
int B;
int C;
int D;
int E;
int F;
int G;
int H;
int I;
int J;
int K;

int ma;
int mam;
int mb;
int feed;
int tfeed;

int ff;


void setup()
{
DebugSerial.begin(9600);
mySerial.begin(9600);
ff = 0;
Serial.begin(9600);
Blynk.begin(Serial, auth);
}

void loop()
{
Blynk.run();
}

BLYNK_WRITE(V0)
{
A = param.asInt();
Serial.print(A);
if ( A == 1)
{
Serial.write("-A1-");
Serial.println(" Manual ");
}
if ( A == 2)
{
Serial.write("-A2-");
Serial.println(" Setting ");
}
if ( A == 3)
{
Serial.write("-A3-");
Serial.println(" Auto ");
}
}

BLYNK_WRITE(V6)
{
J = param.asInt();
Serial.print(J);
if ( J == 1)
{
Serial.write("-12-");
mySerial.write(12);
Serial.println(" Auto start ");
}
if ( J == 0)
{
Serial.write("-13-");
mySerial.write(13);
Serial.println(" Auto stop ");
}
}

thanks

For you to be able to view the serial data from a pair of pns on an MCU, a TTL to USB adapter is required.

The UNO (and the majority of other dev boards) has an onboard TTL to to USB adapter. This is connected between pins 0/1 and the large USB port on the end of the board.

If you want to use other pins for debugging then you’ll need to add an additional TTL to USB adapter, usually known as an FTDI adapter, between your software serial pins and your PC.

The simpler solution is probably to continue using pins 0/1 for debugging via the built-in TTL–>USB adapter, and use a software serial port to communicate with your other device(s).

Pete.

1 Like

Hai Pete, i have no problem when i set pin 4 and 5 to serial communication between Arduino UNO and Arduino Nano, and before i set this code, i have done set it to pin 2 and 3 to communicate between Arduino UNO and Arduino Nano, so pin 0 and 1 to communicate between Arduino UNO and HC-06.

Just because when i need to cut connection from HC-06 with Arduino when i want to upload new program, so i need to move the HC-06 communication pin.

Also i’m not set pin 0 and 1 to serial but why the serial monitor keep showing the exact thing i want to send form my HC-06 to Arduino UNO?

You don’t need to, the Uno’s one hardware serial port - referenced as Serial is hard-wired to pins 0/1 and the large USB connector on the end of the board (via the built-in TTL to USB adapter).

You are using this to communicate between the UNO and HC-06 for your Blynk Bluetooth connection:

and you are eavesdropping on that connection when you connect the large USB connector to your PC and open the serial monitor.

As I’ve already explained, if you wish to use a SoftwareSerial port for debugging then you’ll need an external TTL to Serial (FTDI) adapter.

Or, you’ll need to connect your HC-06 to a SoftwareSerial port and use Serial rather than DebugSerial for your debug messages so that then can be viewed via the onboard USB connector.

Pete.

1 Like

hooo, i see, then why the example code form blynk library for bluetooth HC-05 and HC-06 connected to 2 and 3 as the following

#define BLYNK_USE_DIRECT_CONNECT

// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleSerialBLE.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

void setup()
{
  // Debug console
  DebugSerial.begin(9600);

  DebugSerial.println("Waiting for connections...");

  // Blynk will work through Serial
  // 9600 is for HC-06. For HC-05 default speed is 38400
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

void loop()
{
  Blynk.run();
}

@Richard_Hadiputra please edit your post, using the pencil icon at the bottom, and replace whatever characters you’ve used at the beginning and end of your code with the correct triple backtick characters so that it displays correctly.
Triple backticks look like this:
```

Pete.

Yes, i did it, thanks, i’m not realize it before

Because that’s exactly what you need to do if you want to use the Uno’s Single hardware serial port with built-in TTL to USB adapter for debugging.

I really don’t think you’ve grasped the principal here, but I can’t be bothered to keep explaining and re-explaining something that isn’t Blynk related.
I’d suggest that you re-read the comments I’ve made in this topic and try to understand them. If that doesn’t help then do some googling or watch some YouTube videos that explain the issue in a way that you are able to understand.

Pete.