Sending a Simple High/Low command using Bluetooth to Bluetooth Communication

Hello,

I am working on a project where part of what I need to do is receive a wireless Open or Closed Status from another device.

My project consists of two Arduino Uno Boards and two Bluesmirf Silver modules. There is a push button on the board that will be acting as the master.

What I'm looking to do is have the slave device wait for the master to send the closed status before going through its program, and stops the program when the button is in the open status.

I have already found a good program to link up the two Bluetooth modules based on this blog post: Phillipe Cantin: Arduino Bluetooth Link.

I have the push button connected up to digital pin 2 on the Master, just for reference.

Please help me out.

Thank You So Much,
MG

menace69409:
Please help me out.

Sure thing. Post what you have tried so far, and explain the issue you're having.

Hello,

I am very new to this, I am attaching the complete code that i'm using.

There may be extra code, as I have modified the code from Phillipe and I don't truly understand what all the components of the code are for.

With this code I do make the bluetooth link, but I am not sure how to send the open/close signal.

int buttonPin = 2;
int ledPin = 13;
int masterPin = 4;
int isMaster = 0;
int msgToken = 0;

int buttonState = 0;
int incomingByte = 0;
char gBtMsg[256];
char gBTAdr[13];
char gBtCmd[256];

int gBtKnownMACTotal = 2;
char* gBtKnownMAC[2]; //This is set to hold only two MAC adresses

void BtReceive(void){
bool keepReading = true;
int index = 0;

gBtMsg[0] = '\0';

while(keepReading){
keepReading = false;

if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
if(incomingByte != 13){
gBtMsg[index++] = incomingByte;
keepReading = true;
}
}
}

gBtMsg[index] = '\0';
}

void BtSend(char* i_pBtCmd, bool i_ln = true){

if(i_ln){
Serial.println(i_pBtCmd);
} else{
Serial.print(i_pBtCmd);
}

delay(100);
BtReceive();

}

void BtInit(void){
isMaster = digitalRead(masterPin);
bool btConnect = false;
digitalWrite(ledPin,HIGH);

gBtKnownMAC[0] = "00066667ABCD"; // Change this to one of your MAC addresses
gBtKnownMAC[1] = "00066667ABCE"; // and this one too

Serial.begin(115200);
BtSend("$$$", false);

if(isMaster == LOW){

BtSend("SM,1");

BtSend("I,5");
BtSend("---");

while(!btConnect){
delay(100);
BtReceive();
int msgLen = strlen(gBtMsg);
if(msgLen > 0){

if(msgLen >= 12){
char* doneMsg = &gBtMsg[msgLen - 12];

gBtMsg[12] = '\0';
bool foundKnownMAC = false;

for(int i = 0; i < gBtKnownMACTotal && !foundKnownMAC; i++){
if(!strcmp(gBtMsg, gBtKnownMAC*)){*

  • foundKnownMAC = true;*

  • }*

  • }*

  • if(!strcmp(doneMsg, "Inquiry Done")){*

  • digitalWrite(ledPin,HIGH);*

  • if(foundKnownMAC){ *

  • gBtCmd[0] = 'C';*

  • gBtCmd[1] = ',';*

  • for(int i = 0; i < 12; i++){*
    _ gBtCmd[i + 2] = gBtMsg*;_
    _
    }*_

* gBtCmd[15] = '\0';*

* BtSend("$$$", false);*
* BtSend(gBtCmd);*
* BtSend("---"); *
* delay(2000);*
* digitalWrite(ledPin,HIGH);*

* while(!btConnect){*
* delay(1000);*
* BtSend("$$$", false);*
* BtSend("GK");*

* int numVal = 0;*

* if(strlen(gBtMsg) > 0) {*
* numVal= atoi(gBtMsg);*
* }*

* if(numVal == 1){*
* btConnect = true;*
* }*
* BtSend("---");*
* }*
* }*
* }*
* }*
* }*
* }*

* digitalWrite(ledPin,LOW);*
* msgToken = 1;*
* } else{*
* BtSend("SM,0");*
* BtSend("---");*

* while(!btConnect){*
* delay(1000);*
* BtSend("$$$", false);*
* BtSend("GK");*

* int numVal = 0;*

* if(strlen(gBtMsg) > 0) {*
* numVal= atoi(gBtMsg);*
* }*

* if(numVal == 1){ *
* btConnect = true;*
* }*
* BtSend("---"); *
* }*
* }*

* digitalWrite(ledPin,LOW);*
}
void setup() {

* pinMode(ledPin, OUTPUT);*
* pinMode(isMaster, INPUT);*

* digitalWrite(ledPin,LOW);*

* BtInit();*
}
*void receiveMsg(){ *
* for(int i = 0; i < 10; i++){*
* if (Serial.available() > 0) {*
* // read the incoming byte:*
* incomingByte = Serial.read();*
* if(incomingByte == 'R'){*
* digitalWrite(ledPin, LOW);*
* delay(50);*
* digitalWrite(ledPin,HIGH);*
* }*
* }*

* delay(100);*
* }*
}
void sendMsg(){
* digitalWrite(ledPin,LOW);*
* if (buttonState == HIGH) { *
* Serial.print("R");*
* digitalWrite(ledPin,HIGH);*
}
}
void loop()
{
* if(msgToken == 1){*
* digitalWrite(ledPin,HIGH);*
* sendMsg();*
* delay(1000);*
* }else{*
* digitalWrite(ledPin,LOW);*
* receiveMsg();*
* }*
}
Please give me your thoughts.
Thank You
MG

Please go back and modify your post to put your code within code tags (the # button) so it looks like this. The instructions are in How to use this forum

It is much too long to read the way it is at the moment.

Have you written a couple of short sketches to figure out how to send a byte from one Arduino to the other using Bluetooth with nothing else in the sketches?

...R