# combine two codes GSM and BBLUETOOTH Module HELP

**URL:** <https://forum.arduino.cc/t/combine-two-codes-gsm-and-bbluetooth-module-help/578032>\
**Category:** Programming\
**Created:** [March 6, 2019, 12:50pm UTC](https://forum.arduino.cc/t/combine-two-codes-gsm-and-bbluetooth-module-help/578032 "2019-03-06T12:50:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rey1251](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@rey1251](https://forum.arduino.cc/u/rey1251)\
**Post date:** [March 6, 2019, 12:50pm UTC](https://forum.arduino.cc/t/combine-two-codes-gsm-and-bbluetooth-module-help/578032/1 "2019-03-06T12:50:24Z")

</div>

#define REMOTEXY\_MODE\_\_HARDSERIAL

#include \<RemoteXY.h\>

#define REMOTEXY\_SERIAL Serial  
#define REMOTEXY\_SERIAL\_SPEED 9600

#pragma pack(push, 1)  
uint8\_t RemoteXY\_CONF[] =  
{ 255, 1, 0, 0, 0, 20, 0, 8, 13, 0,  
2, 0, 25, 19, 53, 22, 2, 26, 31, 31,  
79, 78, 0, 79, 70, 70, 0  
};

struct {

uint8\_t switch\_1;

uint8\_t connect\_flag;

} RemoteXY;  
#pragma pack(pop)

#define PIN\_SWITCH\_1 13

void setup()  
{  
RemoteXY\_Init ();

pinMode (PIN\_SWITCH\_1, OUTPUT);

}

void loop()  
{  
RemoteXY\_Handler ();

digitalWrite(PIN\_SWITCH\_1, (RemoteXY.switch\_1 == 0) ? LOW : HIGH);

}  
#include \<SoftwareSerial.h\>  
SoftwareSerial SIM900(7, 8);

String incomingData;  
String message = "";  
int relay\_pin = 2;

void setup()  
{  
Serial.begin(115200);  
SIM900.begin(19200);

pinMode(relay\_pin, OUTPUT);  
digitalWrite(relay\_pin, HIGH);

SIM900.print("AT+CMGF=1\r");  
delay(100);

SIM900.print("AT+CNMI=2,2,0,0,0\r");  
delay(100);  
}

void loop()  
{

receive\_message();

if (incomingData.indexOf("off") \>= 0)  
{  
digitalWrite(relay\_pin, LOW);  
message = "Motor is turned off";

send\_message(message);  
}

if (incomingData.indexOf("on") \>= 0)  
{  
digitalWrite(relay\_pin, HIGH);  
message = "Motor is turned on";  
off  
send\_message(message);  
}  
}

void receive\_message()  
{  
if (SIM900.available() \> 0)  
{  
incomingData = SIM900.readString();  
Serial.print(incomingData);  
delay(10);  
}  
}

void send\_message(String message)  
{  
SIM900.println("AT+CMGF=1");  
delay(100);  
SIM900.println("AT+CMGS="+639355830460"");  
delay(100);  
SIM900.println(message);  
delay(100);  
SIM900.println((char)26);  
delay(100);  
SIM900.println();  
delay(1000);  
}

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 6, 2019, 1:02pm UTC](https://forum.arduino.cc/t/combine-two-codes-gsm-and-bbluetooth-module-help/578032/2 "2019-03-06T13:02:11Z")

</div>

The cented text  
has to be the  
worst way in, like, ever  
to display  
a  
sketch.  
Rather use tags:  
`[code] sketch goes here [/code]`

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 6, 2019, 2:04pm UTC](https://forum.arduino.cc/t/combine-two-codes-gsm-and-bbluetooth-module-help/578032/3 "2019-03-06T14:04:02Z")

</div>

You have piss-poorly posted code A that does something. You have piss-poorly posted code B that does something. You have some completely unspecified requirements for a new program.

You can't realistically expect anyone to tell you how to write the new program.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 6, 2019, 2:08pm UTC](https://forum.arduino.cc/t/combine-two-codes-gsm-and-bbluetooth-module-help/578032/4 "2019-03-06T14:08:00Z")

</div>

karma++ for inventive posting though

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [March 6, 2019, 3:34pm UTC](https://forum.arduino.cc/t/combine-two-codes-gsm-and-bbluetooth-module-help/578032/5 "2019-03-06T15:34:32Z")

</div>

Does this help?

```cpp
void setup()
{
  setupA();
  setupB();
}

void loop()
{
  loopA();
  loopB();
}

#define REMOTEXY_MODE__HARDSERIAL

#include <RemoteXY.h>

#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 9600

#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{
  255, 1, 0, 0, 0, 20, 0, 8, 13, 0,
  2, 0, 25, 19, 53, 22, 2, 26, 31, 31,
  79, 78, 0, 79, 70, 70, 0
};

struct
{
  uint8_t switch_1;
  uint8_t connect_flag;
} RemoteXY;

#pragma pack(pop)

#define PIN_SWITCH_1 13

void setupA()
{
  RemoteXY_Init ();
  pinMode (PIN_SWITCH_1, OUTPUT);
}

void loopA()
{
  RemoteXY_Handler ();
  digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1 == 0) ? LOW : HIGH);
}

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);

String incomingData;
String message = "";
int relay_pin = 2;

void setupB()
{
  Serial.begin(115200);
  SIM900.begin(19200);

  pinMode(relay_pin, OUTPUT);
  digitalWrite(relay_pin, HIGH);

  SIM900.print("AT+CMGF=1\r");
  delay(100);

  SIM900.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);
}

void loopB()
{
  receive_message();

  if (incomingData.indexOf("off") >= 0)
  {
    digitalWrite(relay_pin, LOW);
    message = "Motor is turned off";
    send_message(message);
  }

  if (incomingData.indexOf("on") >= 0)
  {
    digitalWrite(relay_pin, HIGH);
    message = "Motor is turned on";
    send_message(message);
  }
}

void receive_message()
{
  if (SIM900.available() > 0)
  {
    incomingData = SIM900.readString();
    Serial.print(incomingData);
    delay(10);
  }
}

void send_message(String message)
{
  SIM900.println("AT+CMGF=1");
  delay(100);
  SIM900.println("AT+CMGS=\"+639355830460\"");
  delay(100);
  SIM900.println(message);
  delay(100);
  SIM900.println((char)26);
  delay(100);
  SIM900.println();
  delay(1000);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 11:40pm UTC](https://forum.arduino.cc/t/combine-two-codes-gsm-and-bbluetooth-module-help/578032/6 "2021-05-05T23:40:54Z")

</div>


