Sending Numbers to Arduino BT

Hi Everyone,

I'm trying to get my Arduino BT (OSEPP Bluetooth) to receive a number from my phone then play a tone. Eventually each number will have a unique tone (replicating DTMF tones). The problem I am having is that when I read the character (eg '1'), it doesn't store that character, instead it seems like its storing part of a header file but I'm not sure.

#include <SoftwareSerial.h>   //Software Serial Port
#define RxD 0		// Arduino Tx and Rx pins as labeled on board
#define TxD 1
#define SOP '<'
#define EOP '>'
int led =13;
int toner = 11;
bool started = false;
bool ended = false;

SoftwareSerial blueToothSerial = SoftwareSerial(RxD,TxD);

void setup() 	{	// runs every time the Arduino is plugged in to power
  Serial.begin(9600);	// set baud rate
  pinMode(RxD, INPUT);	// set Receive pin to input 
  pinMode(TxD, OUTPUT);	// set Transmit pin to output	
  setupBlueToothConnection(); 	// initialize Bluetooth connection
  pinMode(led, OUTPUT);
} 

void loop() {		// runs continuously after startup 
  char recvChar;	// temp variable to buffer a received character
  while(blueToothSerial.available() >0){ //Runs when data is incoming
    ledBlink(500); //displays that there is data available
    recvChar = blueToothSerial.read(); // if so, buffer the character
    blueToothSerial.write(recvChar);	// Send char to BT connection ...not working...
    
    if(recvChar == SOP){
      started = true;
      ledBlink(2000);
    }
    else if(recvChar == EOP){
      ended = true;
      ledBlink(1000);
    }
    else {
      if(recvChar == '1'){
        playTone();
      }
    }
    if (started == true && ended == true){
      digitalWrite(led, HIGH);
      delay(5000);
      digitalWrite(led,LOW);
    }
  }
}

void setupBlueToothConnection() {
  blueToothSerial.begin(9600); //Set Bluetooth BaudRate to default (38400)
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the Bluetooth to slave mode
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave Bluetooth inquirable 
  Serial.println("The slave Bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}

void playTone(){
        tone(toner, 4800, 500);
        delay(1000);
}

void ledBlink(int length){ //lights the led for length
       digitalWrite(led, HIGH);
       delay(length);
       digitalWrite(led,LOW);
}

Does anyone have any clues as to why it would not be storing a '1' in recvChar?

Does anyone have any clues as to why it would not be storing a '1' in recvChar?

Because SoftwareSerial does not work on the hardware serial pins.

Why not?

In one of your previous posts, you set this up in a very similar way, which was to store the incoming data in an array. Why wouldn't I be able to store just one?

In one of your previous posts, you set this up in a very similar way, which was to store the incoming data in an array.

Not using the hardware serial pins. If the device you are reading from is connected to pins 0 and 1, and Serial is already connected to those pins, then just use Serial to read from the device!

i have bluetooth bee , arduino uno and an android phone , i want those devices to turn off and on a bulb ,, i am facing a problem in comunication between bluetooth and arduino , i tryed to comunicate with my bluetooth , by Putty and by serial monitor , but alas nothing happen .. pls i need a code for this project , i need your advice ,, thnk u ..

Alright. Removing the blueToothSerial intantiation allowed us to receive characters back on the phone but it is not what we sent it.

If I send a '1' it returns with 35 bytes of gibberish. Always a bunch of spaces followed by 2 question marks in a diamond.

Well, we played around with it a bit more and found that part of the mess up was from how we were setting up Bluetooth. We ended up getting a different tone to play for a different number sent to the board. If anyone wants that code. Ask here or PM me.