HELP Bluetooth coding help

Hello,

I use an Arduino Mega 2560, HC-06 bluetooth module.

I would like to turn on and off an led with keys on the keyboard through bluetooth. When I try this piece of code and connect the TX and RX to RX0 and TX0 (default receive and transmit pins) then it works :

char blueToothVal;           //value sent over via bluetooth
char lastValue;              //stores last state of device (on/off)

void setup()
{
 Serial.begin(9600); 
 pinMode(13,OUTPUT);
}


void loop()
{
  if(Serial.available())
  {//if there is data being recieved
    blueToothVal=Serial.read(); //read it
  }
  if (blueToothVal=='n')
  {//if value from bluetooth serial is n
    digitalWrite(13,HIGH);            //switch on LED
    if (lastValue!='n')
      Serial.println(F("LED is on")); //print LED is on
    lastValue=blueToothVal;
  }
  else if (blueToothVal=='f')
  {//if value from bluetooth serial is n
    digitalWrite(13,LOW);             //turn off LED
    if (lastValue!='f')
      Serial.println(F("LED is off")); //print LED is on
    lastValue=blueToothVal;
  }
  delay(1000);
}

Though when I try to assign the RX and TX pins somewhere else to pin19 and 18, it wont work or send/receive anything.

Here is my modified code:

#define BT_SERIAL_TX 19
#define BT_SERIAL_RX 18
#include "SoftwareSerial.h"

SoftwareSerial BSerial(BT_SERIAL_TX, BT_SERIAL_RX);
char blueToothVal;           //value sent over via bluetooth
char lastValue;              //stores last state of device (on/off)

void setup()
{
 BSerial.begin(9600); 
 pinMode(13,OUTPUT);
}


void loop()
{
  if(BSerial.available())
  {//if there is data being recieved
    blueToothVal=BSerial.read(); //read it
  }
  if (blueToothVal=='n')
  {//if value from bluetooth serial is n
    digitalWrite(13,HIGH);            //switch on LED
    if (lastValue!='n')
      BSerial.println(F("LED is on")); //print LED is on
    lastValue=blueToothVal;
  }
  else if (blueToothVal=='f')
  {//if value from bluetooth serial is n
    digitalWrite(13,LOW);             //turn off LED
    if (lastValue!='f')
      BSerial.println(F("LED is off")); //print LED is on
    lastValue=blueToothVal;
  }
  delay(1000);
}

Thanks in advance! Urgent help please.

#define BT_SERIAL_TX 19
#define BT_SERIAL_RX 18
#include "SoftwareSerial.h"

SoftwareSerial BSerial(BT_SERIAL_TX, BT_SERIAL_RX);

Only some pins on the Mega can be used for SoftwareSerial. It makes NO sense, even if pins 18 and 10 CAN be used, to use hardware serial pins to do software serial. If the pins are available, use SerialN, where N is the number that corresponds to those pins. I don't have a Mega in front of me to know which instance of the hardware serial class pins 18 and 19 are used for.

Pins 18,19 are hardware Serial1, as clearly marked on the board. Using software serial on hardware serial pins is the kiss of death. Using software serial on [u]any[/u] pins on a Mega is a bad idea unless you have already used up all four hardware serial ports.

Ooo it works now. Thank you!