No prints from SoftwareSerial.println

Hey guys,

I'm currently working on my project and need this little test element to work. I want to send and receive data from an Arduino to PC using a HC-06. That's why I want to start little and have come across this tutorial on youtube (link in the code), followed the instruction and I could control the LED by typing 1 or 0 into the serial monitor.

The problem is that I won't receive any prints. I won't receive any softSerial.println although I can clearly control the LED. Therefore, the prints should occur in the serial monitor like in the video, right? But it just keeps being blank and I also don't receive any errors, so... I don't know.

Since the serial monitor settings are being covered by the cam, I assume that the baudrate is 38400 and CR&NL is on.

//code write by Moz for YouTube changel LogMaker360, 27-10-2015
//code belongs to this video: https://www.youtube.com/watch?v=6jZMJ7DFCY0

#include <SoftwareSerial.h>
SoftwareSerial softSerial(10, 11);  //RX/TX

void setup()  
{
  // set digital pin to control as an output
  pinMode(LED_BUILTIN, OUTPUT);

  // set the data rate for the SoftwareSerial port
  softSerial.begin(38400);

  // Send test message to other device
  softSerial.println("Hello from Arduino");
}

char a; // stores incoming character from other device

void loop() {
  if (softSerial.available())
  // if text arrived in from softSerial...
  {
    a=(softSerial.read());
    softSerial.println(a);
    if (a=='1')
    {
      digitalWrite(LED_BUILTIN, HIGH);
      softSerial.println(" LED on"); //does not print
    }

    if (a=='0')
    {
      digitalWrite(LED_BUILTIN, LOW);
      softSerial.println(" LED off"); //does not print
    }

    if (a=='?')
    {
      softSerial.println("Send '1' to turn LED on");
      softSerial.println("Send '0' to turn LED off");
    }   

    // you can add more "if" statements with other characters to add more commands
  }

}

I hope you can help me. If you need further information, just ask :slight_smile:

(deleted)

spycatcher2k:

softSerial.begin(38400);

try

softSerial.begin(9600);

Thanks for your reply. Sadly If I change the baudrate to 9600, I'm not able to control the LED anymore. The default baudrate of the HC-06 is 38400.

You are missing

Serial.begin(9600)

in the setup.

An example

#include <SoftwareSerial.h>
// Programm HC-06
// load programm to Arduino
// no bluetooth connection to HC-06 Module
// send AT commands over Serial
// mit PUTTY auf Arduino COM verbinden
// kein NL und CR setzen
// AT -> OK
// AT+NAME<Name> -> Oksetname
// AT+PIN<4stellige zahl> -> OKsetPIN
// AT+BAUD<X> -> OK<X>
// X=4 : 9600bps (Default)
// X=6 : 38400bps
// X=7 : 57600bps
// X=8 : 115200bps
/////////////////////////
// HC-06 | Arduino
// TX    | D10
// RX    | D11
////////////////////////
SoftwareSerial mySerial(10, 11);

void setup() {

  Serial.begin(9600);
  delay(500);
   mySerial.begin(9600);
// mySerial.begin(57600);
delay(500);
  Serial.println(„Ready“);
}

void loop()

{
  if ( Serial.available() )
  {
    char a = Serial.read();
    mySerial.print(a);
  }
  if ( mySerial.available() )
  {
    char a = mySerial.read();
    Serial.print(a);
  }
}

Reference: Bluetooth Modul HC-06: Baudrate ändern – Interessengemeinschaft Informationstechnik Zwieseltal

Basically, your code just sends data. It doesn't receive any. That's the reason why you need to add the Serial.begin code and add the reading code, as shown above in your code.