Arduino UNO not receiving serial data(TX) from Bluetooth module

Hello. I am using a HC-06 bluetooth adapter connected properly to the rx/tx pins on the arduino with an app running on my phone to send values of "1" and "2" to the module. Although my goal can be accomplished through the serial monitor on my pc, i cannot do it with my phone. Here is the code I found:

/*
simple LED test
*/

char val;         // variable to receive data from the serial port
int ledpin = 13;  // LED connected to pin 2 (on-board LED)

void setup()
{
  pinMode(ledpin = 13, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
 
  Serial.begin(9600);       // start serial communication at 115200bps
 
}
 
void loop() {
  if( Serial.available() )       // if data is available to read
  {;}
    val = Serial.read();         // read it and store it in 'val'
 
  if( val == '2' )               // if '0' was received led 13 is switched off

  {
   digitalWrite(ledpin, LOW);    // turn Off pin 13 off
delay(1000);                  // waits for a second   
Serial.println("13 off");
  }

if( val == '1' )               // if '1' was received led 13 on
 {
    digitalWrite(ledpin = 13, HIGH);  // turn ON pin 13 on
    delay(1000);                  // waits for a second
    Serial.println("13 on");
  }
}

any help to resolve this issue would be greatly appreciated. Here is the link to the tutorial I followed which has the app:

Well being that, that is my sample code you have, I'll help you out.

I see that you changed a few things, or it could be whoever else used it last, changed a few things. But here is the original.

/*
simple LED test
 */

char val;         // variable to receive data from the serial port
const byte ledpin = 13;  // LED connected to pin 13 (on-board LED)

void setup()
{
  pinMode(ledpin, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
  Serial.begin(115200);       // start serial communication at 115200bps
}

void loop() {
  if( Serial.available() > 0)       // if data is available to read
  {
    Serial.println("you have a connection");

    val = Serial.read();         // read it and store it in 'val'

    if( val == '0' )               // if '0' was received led 13 is switched off
    {
      digitalWrite(ledpin, LOW);    // turn Off pin 13 off
      delay(1000);                  // waits for a second   
      Serial.println("13 off");
    }

    if( val == '1' )               // if '1' was received led 13 on
    {
      digitalWrite(ledpin = 13, HIGH);  // turn ON pin 13 on
      delay(1000);                  // waits for a second
      Serial.println("13 on");
    }
  }
}

How is your wiring? You need to cross-wire the Tx and Rx pins from the BT module and Arduino, did you do that?
If you did, is the BT module paired to your phone indicated by the onboard LED. Blinking = not paired, Solid = paired.

Yes the Rx on the BT is connected to the TX on the arduino and vice versa. I used the exact original code you provided but no response. I can do all this through serial monitor. When I am connected the onboard led stops blinking and is solid, yet when I send values through my phone, neither the rx or tx led's on the arduino blink so obviously the code does not further execute. The application i am using also says "connected." I am using a custom appinventer app that sends value 1 & 2 through serial. I don;t understand why this does not work. I have also tried with standard bluetooth terminals. No matter what I try, I cannot turn on a LED wirelessly whether it's an android, pc, or pocket pc. Thanks for all the help!

Have you tried using Putty? There is an app called Bluetooth Chat for the android, it should work with your module.

UPDATE
now I can tell tell that all is working correctly. But is still not where it should be. When I send 1, the onboard starts blinking rapidly until i send 1, when it flashes a little, then powers off. I need a stable on/off.

I tried putty but when i connected, the terminal was blank and I could not type anything

What are you receiving from the phone? If you do Serial.println(val); you can see what your getting.

Added: you won’t see anything on putty unless you echo what you type, but you can still type.

ldar2020:
Hello. I am using a HC-06 bluetooth adapter connected properly to the rx/tx pins on the arduino with an app running on my phone to send values of "1" and "2" to the module. Although my goal can be accomplished through the serial monitor on my pc, i cannot do it with my phone.

OK, if you can get a result with the PC, it's probably just a little procedural thing with the bluetooth or, more likely, the phone and that is where you should look.

Some simple steps to prove the setup are here

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf

which might help, particularly the last bit............

I have followed the steps on the pdf and when I reset the arduino my android says the welcome message but as soon as I type in something, I get no response back. Its as if the arduino can send data to the phone but the phone can't send data back. I tested on the serial monitor on PC and all works well so it's not the code... I realize that this is a simple task but unfortunately, it is not working as it should be...

Hummm. The procedure IS simple, but the problem clearly isn't.

You have proven the code is kosher and the wiring to Arduino D0,D1 is the right way round.

You might still check the wiring i.e. right pin but bad connection.

I'm sure there is a simple way of testing the comms input on D0, but I'm afraid that is beyond me

Can you ensure Android is kosher by using it with PC or something? I'm afraid even that is not a full proof, but all my bluetooth problems, other than those that were self-inflicted, have been down to the gear at the other end - Arduino and Bluetooth have always been innocent. Further, and making matters worse, those problems remain utterly inexplicable.

Try this, this is as simple as it gets. If the phone sends anything at all, the LED should go on.

void setup()
{
  pinMode(13, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
  Serial.begin(9600);       // start serial communication at 115200bps
}

void loop()
{
  if( Serial.available() > 0)       // if data is available to read
  {
     digitalWrite(13, HIGH);
  }

  else 
  {
    digitalWrite(13, LOW);
  }
}

OK, the exact code you gave me worked after I made 1 modification, but if I simply change the onboard led to, for example, pin 2, it simply does not work. This makes 0 sence

Test it with the serial monitor, make sure you change all the number 13 to 2.

works fine with serial monitor

Have you tried it with Putty or any other terminal program other than the serial monitor? What program are you using on your phone?

on my phone I am using Bluetooth terminal. although I have used many Bluetooth communication applications. And I have tried with putty using the COM port of the BT module, but no success there either

currently using Bluetooth terminal application. It has not worked with putty

See if you can get Bluetooth Chat, that program should know works.

I have tried that. again, no success

Can you show me a video or post a picture of your setup? Bluetooth chat should have worked.