Errors while using SoftwareSerial between Arduino and PC

Hello, I am new to Arduino and I’m trying to follow a tutorial where I can send and receive messages between my Arduino and PC. This is the code I wrote (I am using an Arduino UNO).

This is my code:

#include <SoftwareSerial.h>

#define rxPin 8
#define txPin 7

SoftwareSerial mySerial(rxPin, txPin); // RX, TX
char myChar ; 

void setup() {
  Serial.begin(9600);   
  Serial.println("Goodnight moon!");

  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop(){
  while(mySerial.available()){
    myChar = mySerial.read();
    Serial.print(myChar);
  }

  while(Serial.available()){
   myChar = Serial.read();
   mySerial.print(myChar);
  }
}

I get the “Goodnight moon!” message on the serial. However, “Hello, World?” is not printed on the computer (I use putty to check the message being transmitted from Bluetooth).

It would be greatly appreciated if someone could help me find out what’s wrong with the code.

Thanks in advance.

How is your Bluetooth device connected to the Arduino? A common problem is not having Tx connected to Rx and Rx connected to Tx. You also need a GND connection.

Is your Bluetooth device paired with your PC ?

What Bluetooth device are you using? What PC operating system are you using?

...R

Hello, I’m new to Arduino and I’m currently learning about how to display a message on your PC via Bluetooth.

Here is the code for a simple program where you enter something on the Arduino serial and it is displayed on my PC (using putty), which is connected to the Arduino (UNO).

#include <SoftwareSerial.h>

#define rxPin 8
#define txPin 7

SoftwareSerial mySerial(rxPin, txPin); // RX, TX

char myChar ; 

void setup() {
  Serial.begin(9600);   
  Serial.println("Goodnight moon!");

  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop(){

  while(Serial.available()){
   myChar = Serial.read();
   mySerial.print(myChar);
  }
}

However, when I upload the program, “Goodnight moon!” gets printed on my PC (I want “Hello world?” to be printed).

Also, the characters I enter from the serial do not get displayed as well. However, when I write Serial.print(myChar), it gets displayed.

If someone can explain what’s wrong with the code (or probably with the circuit), I would be extremely grateful. PS. I have checked if tx is connected to rx, and rx to tx.

Thank you in advance.

However, when I upload the program, "Goodnight moon!" gets printed on my PC (I want "Hello world?" to be printed).

Also, the characters I enter from the serial do not get displayed as well. However, when I write Serial.print(myChar), it gets displayed.

Since NOTHING gets displayed via the bluetooth device, I do believe that your duplicate post title is nonsense.

You can not assert that "nothing" is "incorrect".

Your intentions are far from clear - particularly about what terminals are used, what port putty is connected to, its function, and even how many PCs are involved. If only one, then the exercise is pointless anyway. It would appear that the reason why you see “Goodnight Moon” on your PC is that you have written the command

Serial.println(“Goodnight moon!”);

The “Hello world” will be printed to whatever is connected to pins 7,8. Maybe that’s the bluetooth, but what is set up to receive the bluetooth. Maybe you have two terminals open on the one PC?

Why have you started a second Thread. I have already replied to your other Thread and you obviously did not bother to read it.

...R

Topics merged. Savidude, one topic, one conversation please. I.e, do not Crosspost.