Interfacing BT Module HC-06 and GSM Module SIM 808 EVB-V3.2.2 at the same time

Hi Guys,

I am currently using an Arduino Mega for building a “Smart Home”. I would like to control it through BT and SMS. I have both modules connected to the Mega. If I only connect one of the systems everything works fine but both at the same time doesn’t work. I made some research and I am pretty sure that the problem is in choosing the correct baud rate but I still cant come up with a solution.
Sorry that some of the comments in the code are in german, but its more for my own understanding since I am new to this.

This is my code:

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

String msg = String("");
int SmsContentFlag = 0;       // EN: Set to 1 when the next GPRS shield message will contains the SMS message
String SIM_PIN_CODE = String( "1305" ); // EN: Code PIN of the SIM card (if applied)

String altBtData;
const int ledPinBlue = 38;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);               //this is the messages that are typed as the normal AT commands
  smsSerial.begin(9600);            //this serial is for the connection from and to the sim module to type the necessary AT commands
  altBtSerial.println("SMS-Serial available");
  altBtSerial.begin(9600);          //this serial is the one for the bluetooth: so all the texts have to be printed here
  altBtSerial.println("alt-bluetooth available");
  pinMode(ledPinBlue, OUTPUT);

  altBtSerial.println("Setup is Ready");


void loop() {
  char SerialInByte;

  if (Serial.available())                           //wenn eine nachricht im serial auftaucht,             
    smsSerial.print((unsigned char);  //dann soll sie im smsSerial abgeschickt werden => ausführen der AT commands
  else  if (smsSerial.available())                  //wenn eine nachricht vom SMS modul kommt
    char SerialInByte;            
    SerialInByte = (unsigned char); //speicher diese in der variable SerialInByte
    altBtSerial.print(SerialInByte);                //schreibe sie im bluetooth serial => das könnte schon reichen um dann von den if bt data available erkannt zu werden, dann muss es nur eine funktion geben
    if ( SerialInByte == 13 ) {                     // EN: Store the char into the message buffer
    if ( SerialInByte == 10 ) {                     // EN: Skip Line feed
    else {
      msg += String(SerialInByte);                  // EN: store the current character in the message string buffer

  if (altBtSerial.available()) {
    altBtData = altBtSerial.readString();
    if (altBtData == "on") {
    if ( altBtData == "off") {

void ProcessSms( String msg ) {
  altBtSerial.print( "ProcessSms for [" );
  altBtSerial.print( msg );
  altBtSerial.println( "]" );

  if ( msg.indexOf("OnB") >= 0 ) {
    digitalWrite( ledPinBlue, HIGH );
    altBtSerial.println( "SMS: Blue LED is on" );

  if ( msg.indexOf("OffB") >= 0 ) {
    digitalWrite( ledPinBlue, LOW );
    altBtSerial.println( "SMS: Blue LED is off" );


void GprsSendPinCode() {        // EN: Send the SIM PIN Code to the GPRS shield
  if ( SIM_PIN_CODE.indexOf("XXXX") >= 0 ) {
    altBtSerial.println( "*** OUPS! you did not have provided a PIN CODE for your SIM CARD. ***" );
    altBtSerial.println( "*** Please, define the SIM_PIN_CODE variable . ***" );
  smsSerial.println( SIM_PIN_CODE );

void GprsTextModeSMS() {
  smsSerial.println( "AT+CMGF=1" );             // EN: Request Text Mode for SMS messaging
  altBtSerial.println("Set to SMS text mode");

void GprsReadSmsStore( String SmsStorePos ) {
  // Serial.print( "GprsReadSmsStore for storePos " );
  // Serial.println( SmsStorePos );
  smsSerial.print( "AT+CMGR=" );
  smsSerial.println( SmsStorePos );

void ClearGprsMsg() {
  msg = "";

void ProcessGprsMsg() {
  altBtSerial.print( "GPRS Message: [" );
  altBtSerial.print( msg );
  altBtSerial.println( "]" );

  if ( msg.indexOf( "+CPIN: SIM PIN" ) >= 0 ) {
    altBtSerial.println( "*** NEED FOR SIM PIN CODE ***" );
    altBtSerial.println( "PIN CODE *** WILL BE SEND NOW" );

  if ( msg.indexOf( "Call Ready" ) >= 0 ) {
    altBtSerial.println( "*** GPRS Shield registered on Mobile Network ***" );

  if ( msg.indexOf( "+CMTI" ) >= 0 ) {
    altBtSerial.println( "*** SMS Received ***" );
    int iPos = msg.indexOf( "," );
    String SmsStorePos = msg.substring( iPos + 1 );
    altBtSerial.print( "SMS stored at " );
    altBtSerial.println( SmsStorePos );

    GprsReadSmsStore( SmsStorePos );

  if ( msg.indexOf( "+CMGR:" ) >= 0 ) {
    SmsContentFlag = 1;

  if ( SmsContentFlag == 1 ) {
    altBtSerial.println( "*** SMS MESSAGE CONTENT ***" );
    altBtSerial.println( msg );
    altBtSerial.println( "*** END OF SMS MESSAGE ***" );
    ProcessSms( msg );

  SmsContentFlag = 0;

void ledOn() {
  digitalWrite(ledPinBlue, HIGH);
  altBtSerial.println("BT: LED is on");

void ledOff () {
  digitalWrite(ledPinBlue, LOW);
  altBtSerial.println("BT: LED is off");

The results in the Bluetooth Serial Monitor look like this:

GPRS Message: [

+CMTI: "SM",5

GPR�sage: [
+CMTI: "SM",5]
*** SM�������***
SMS stored at 5


GPRS Message: [

So first of all it doesn’t process the message properly. I was sending “OnB” to turn on a LED.
And second is obviously these questionmarks.

I was trying to use different baud rates to overcome the problem. I got my input from here: AltSoftSerial Library, for an extra serial port
So I know that the baud rate of the SoftwareSerial should be like 10 times higher then the one from the altSoftSerial port.
But I cant find a way to make it work.

So I would be really happy for some help of yours!
And since this is my first post I am also open for some feedback!

Thanks already


Oh and I read the posts that already exist in this forum and a little bit more: - - -

For starters, you are using two serial devices, both on software serial. Your Mega has four hardware serial ports, yes, four, and you are using only one of them - and that is just for the monitor. That cannot possibly be a good idea.

Your output does indeed look like mis-match in baud rate but everything seems to be at default 9600, and you only have to ensure the serial monitor or terminal is set at 9600 too.

So I know that the baud rate of the SoftwareSerial should be like 10 times higher then the one from the altSoftSerial port.

This sounds like complete nonsense, and is irrelevant anyway.

OK thanks for that I will try to use the hardware ports then.