0

I am currently working on a project with a HC-06 module. I hooked it up accordingly like so:

Arduino -> HC-06
5V -> VCC
GND -> GND
TX -> RX
RX -> TX

and I ran this code:

void setup() {
  Serial.begin(9600);
}

void loop() {
   Serial.print("test");
   Serial.print("\n");

}

Strangely enough that does not work at all. When I am using neither with or without PC as the power source. When I am using SoftwareSerial like this it works like a charm:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX

void setup() {
  mySerial.begin(9600);
}

void loop() {

   mySerial.print("test");
   mySerial.print("\n");

}

Can someone please explain why and of course how to fix that?

  • assuming you have double checked that the wiring (tx/rx) is the same between the two. Also are you sure your upload completes when you use the hardware serial? Many times if another device is attached to the hardware serial port, the programing will fail – Chad G Feb 19 '18 at 16:38
1

You are using a Leonardo. Pins 0/1 aren't Serial, they're Serial1. Serial is the built-in USB connection.

void setup() {
  Serial1.begin(9600);
}

void loop() {
   Serial1.print("test");
   Serial1.print("\n");

}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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