Can I use HC 06 without Software Serial etc?

If the answer is yes, how? Sadly, Software Serial and Simple SD Audio (TMRPCM etc) don't work together.

When I use standard serial pins (Hardware Serial) how can i define BTserial? Like this;

#include <SoftwareSerial.h>

SoftwareSerial BTserial(19, 18);

Without SoftwareSerial how can i define BTserial?

There must be a very very simple answer. I'm so boring with my project. (Actually it's my thesis) I understand, Software Serial and Simple SD Audio can't work together. (For my project) I just need a simple answer. Without software serial, can i define BTserial? I also used AltSoftSerial and some different libraries, but that 2 libraries just don't work together.

I have a speaker (Speaker is working without Bluetooth) and a phone. Phone receive and send commands. With PIR motion sensor, my robot will go back and say someting. (Like "Please go out") The phone also must receive "Please go out" (With SerialPrint) command.

Is HC 06 just not enough for this project? I want just trying BTserial without Software Serial. I have 5 days.

I find a good library (Yes, library must to be. This library just use TX1 and RX1 and don't touch any other pins) and the result is same. Speaker (With SD Card Product) and Bluetooth don't work together. What a shame.

KayraBey91:
When I use standard serial pins (Hardware Serial) how can i define BTserial? Like this;

#include <SoftwareSerial.h>

SoftwareSerial BTserial(19, 18);

Without SoftwareSerial how can i define BTserial?

Assuming you want to use Serial1:

HardwareSerial &BTserial = Serial1;

If you want to use a different serial port then you just need to change the last part.

There’s no magic in renaming Serial1 to BTserial, it’s just giving it a different name, which maybe would make your code easier to read.

Thank you sir, that works but bluetooth and speaker still don't work together. So, this is a different problem. Could the problem be hardware? (HC - 06, SD Card Product, Arduino etc)

Please explain exactly what you mean by "bluetooth and speaker still don't work together".

This is my whole code;

#include <SimpleSDAudio.h>
#include <ServoTimer2.h>
HardwareSerial &Bluetooth = Serial1;
int aci=90,i;
ServoTimer2 myservo; 
int gecikme=40;

// Variables used for incoming data
const byte maxDataLength = 20;
char receivedChars[21] ;
boolean newData = false;

// Pins de HC-SR04
const int trigger_sol = 33;
const int echo_sol = 35;

// Pins de HC-SR04
const int trigger_sag = 37;
const int echo_sag = 39;

// Constants for hardware
const byte m_PIN[] = {23,25,27,29};
boolean m_State[] = {false,false,false,false};

const int on_sol = 22;
const int on_orta = 24;
const int on_sag =  26;

const int hareket_sensoru_sol = 38;
const int hareket_sensoru_sag = 40;

int durum;
int engel_oku1;
int engel_oku2;
int engel_oku3;

void setup() {

   Serial.begin(9600);
    myservo.attach(10);
  // Configuración de los pines
    pinMode(trigger_sol, OUTPUT);
    pinMode(echo_sol, INPUT);


   pinMode(trigger_sag, OUTPUT);
   pinMode(echo_sag, INPUT);


  //Engel switchler pull-up olacak


    for (byte pin = 0; pin < 4; pin++) 
    {
         
         
       // Set the LED pins for output and make them LOW
       pinMode(m_PIN[pin], OUTPUT);  digitalWrite(m_PIN[pin],LOW);
    }
    
    pinMode(22,INPUT_PULLUP); // on_sol
    pinMode(24,INPUT_PULLUP); //on_orta
    pinMode(26,INPUT_PULLUP); 


    pinMode(38,INPUT);
    pinMode(40,INPUT);
    
    
  
    

 kafa_test();
 ileri_git(); delay(1000);dur();
 geri_git(); delay(200);dur();
 sola_don(); delay(200);dur();
 saga_don(); delay(200);dur();

 // open serial communication for debugging
    Serial.begin(9600);
    Serial.print("Sketch:   ");   Serial.println(__FILE__);
    Serial.print("Uploaded: ");   Serial.println(__DATE__);
    Serial.println(" ");
     
    //  open software serial connection to the Bluetooth module.
    Bluetooth.begin(9600); 
    Serial.println("Serial started at 9600"); 
          
    newData = false;

}
//***********************************************************
//***********************************************************
//***********************************************************
//***********************************************************

void loop() {

    {engel_oku1 = digitalRead(22);

   if (engel_oku1 == LOW) {Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,3,1>" );Bluetooth.print("<L,4,0>" ); 
   digitalWrite(23,LOW);digitalWrite(25, HIGH);digitalWrite(27, LOW);digitalWrite(29, HIGH);sistem_test();dur();Bluetooth.print("<L,3,0>" );}

   

   }
   
    {engel_oku2 = digitalRead(24);
   if (engel_oku2 == LOW) {Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,2,1>" );Bluetooth.print("<L,3,0>" );Bluetooth.print("<L,4,0>" ); 
   digitalWrite(23,LOW);digitalWrite(25, HIGH);digitalWrite(27, HIGH);digitalWrite(29, LOW);sistem_test();dur();Bluetooth.print("<L,2,0>" );}

      
      }
   
    {engel_oku3 = digitalRead(26);
  
   if (engel_oku3 == LOW) {Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,3,0>" );Bluetooth.print("<L,4,1>" ); 
   digitalWrite(23,HIGH);digitalWrite(25, LOW);digitalWrite(27,HIGH);digitalWrite(29, LOW);sistem_test();dur();Bluetooth.print("<L,4,0>" );}

    }
         
    recvWithStartEndMarkers();                // check to see if we have received any new commands
    if (newData)  {   processCommand();  }    // if we have a new command do something about it

   { Serial.println(" Hareket Kontrol Ediliyor ");
int buttonState_sol = digitalRead(38);
int buttonState_sag = digitalRead(40);

if (buttonState_sol == LOW) {Serial.println(" SOLDA ENGEL ");
Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,3,1>");Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,4,0>" ); 
   digitalWrite(25, HIGH);digitalWrite(29, HIGH);digitalWrite(23, LOW);digitalWrite(27, LOW);delay(2000);sistem_test();dur();Bluetooth.print("<L,3,0>");}

   
else if(buttonState_sag == LOW)

{ Serial.println(" SAGDA ENGEL ");
Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,4,1>" );Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,3,0>"); 
   digitalWrite(23, HIGH);digitalWrite(27, HIGH);digitalWrite(25, LOW);digitalWrite(29, LOW);delay(2000);sistem_test();dur();Bluetooth.print("<L,4,0>");}
   }


}


//***********************************************************
//***********************************************************
//***********************************************************
//***********************************************************


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++


void sola_don()   // sola dön
{
digitalWrite(23, HIGH);digitalWrite(27, HIGH); delay(100);Serial.println("     SOLA donuyorum    "); durum=1;
}

void saga_don()
{
digitalWrite(25, HIGH);digitalWrite(29, HIGH); delay(100); Serial.println("     SAGA donuyorum    ");durum=1;
}


void ileri_git()  // geri git
{
digitalWrite(23, HIGH);digitalWrite(29, HIGH); delay(100);Serial.println("     ilerliyorum    ");durum=1;
}

void geri_git() // ileri olacak
{
digitalWrite(25, HIGH);digitalWrite(27, HIGH); delay(100);Serial.println("     GERi Gidiyorum    ");durum=1;
}

void dur()
{
    digitalWrite(23, LOW);
    digitalWrite(25, LOW);
    digitalWrite(27, LOW);
    digitalWrite(29, LOW);
    delay(500); Serial.println("     DURDUM    ");
}
//*******************************************************//


void kafa_test()
{
  
  for(i=1;i<=15;i=i+1)
  {
  aci=aci+5;
  myservo.write(aci); 
    // sets the servo position according to the scaled value
  delay(gecikme);   
  }
  Serial.print("1= "); Serial.println(aci); delay(500);
  
    for(i=1;i<=30;i=i+1)
  {
  aci=aci-5;
  myservo.write(aci);  
  delay(gecikme);   
  }
Serial.print("2= "); Serial.println(aci); delay(500);
    for(i=1;i<=15;i=i+1)
  {
    aci=aci+5;
  
  myservo.write(aci);   
   // sets the servo position according to the scaled value
  delay(gecikme);   
  }

Serial.print("3: "); Serial.println(aci); delay(500);
  delay(2000); 
   
  
}

void processCommand()
{
     Serial.print("receivedChars = ");   Serial.println(receivedChars);

    if (receivedChars[0] == 'L')      // do we have a LED command?
    {
        // we know the LED command has a fixed length "L10"
        // and the value at pos 1 is the LED and the value at pos 2 is 0 or 1 (on/off). 
        // 0 and 1 is the same as LOW and HIGH so we can use 0/1 instead of LOW/HIGH
        
        byte mnum = receivedChars[1] - 48;          // convert ascii to value by subtracting 48
        boolean mstatus = receivedChars[2] - 48;
        
        digitalWrite(m_PIN[mnum-1],mstatus);
        m_State[mnum-1] = mstatus;
    }

    receivedChars[0] = '\0';
    newData = false;
}


void sistem_test()
{
  
  for(i=1;i<=5;i=i+1)
  {
  aci=aci+5;
  myservo.write(aci); 
    // sets the servo position according to the scaled value
  delay(gecikme);   
  }
  Serial.print("test1= "); Serial.println(aci); delay(500);
  
    for(i=1;i<=5;i=i+1)
  {
  aci=aci-5;
  myservo.write(aci);  
  delay(gecikme);   
  }
Serial.print("test2= "); Serial.println(aci); delay(500);
  
}

void recvWithStartEndMarkers()
{
     static boolean recvInProgress = false;
     static byte ndx = 0;
     char startMarker = '<';
     char endMarker = '>';
     char rc;
 
     if (Bluetooth.available() > 0) 
     {
          rc = Bluetooth.read();
          if (recvInProgress == true) 
          {
               if (rc != endMarker) 
               {
                    receivedChars[ndx] = rc;
                    ndx++;
                    if (ndx > maxDataLength) { ndx = maxDataLength; }
               }
               else 
               {
                     receivedChars[ndx] = '\0'; // terminate the string
                     recvInProgress = false;
                     ndx = 0;
                     newData = true;
               }
          }
          else if (rc == startMarker) { recvInProgress = true; }
     }
}

When I’m adding the this code to Void Setup;

{

SdPlay.setSDCSPin(4); // sd card cs pin

if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER))

{ while(1); }

if(!SdPlay.setFile("music.wav")) // music name file

{ while(1);

}

}

and adding this code to void setup in any sensor code;

SdPlay.play();

The Bluetooth doesn’t work. HC 06 can’t receive any sensor command but while there is no audio codes, Bluetooth works very well. Also with Hardware Serial, the speed is perfect but with audio codes, wow, don’t work.

There is a speaker, HC 06 bluetooth module, SD Card Module (For audio and speaker) and some sensors. This is all that what can i say.

OMG! OMG! I DO!

Just erased while(1) parts and works well. And my thesis is %100 done. Thank you everybody.