"Serial.println" not working over Bluetooth.

I have an Arduino Uno connected to an HC-06 Bluetooth chip, which is reading to TeraTerm on my computer.

I have this simple code:

const int ledPin = 7;
int state = 0;
int flag = 0;

void setup() {
// put your setup code here, to run once:

pinMode(ledPin, OUTPUT);
Serial.begin(9600);
digitalWrite(ledPin, LOW);
Serial.println(“Keep your distance, Chewie.”);
}

void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()) {
state = Serial.read();
flag = 0;
}
if(state == ‘0’) {
digitalWrite(ledPin, LOW);
if(flag == 0){
Serial.println(“LED: Off”);
flag = 1;
}
}
else if(state == ‘1’) {
digitalWrite(ledPin, HIGH);
if(flag == 0) {
Serial.println(“LED: On”);
flag = 1;
}
}
}

That I got off the internet to test if my bluetooth is working and connecting to the Arduino. I revised it slightly so that it reads from the d0 and d1 instead of using SoftwareSerial, since I don’t really intend to ever have the usb connection and bluetooth going at the same time.

The Bluetooth is connecting to the computer, and I can type 0 and 1 in TeraTerm and it will turn the LED on and off no problem, but the Arduino is not returning the println strings to the computer. This is my first major project with Arduino. It vexes me that I can send data via the computer and Bluetooth, but can’t seem to receive. Any help would be appreciated.

6:15 CST Edit: Also, when I connect it directly to the computer via USB and use the Serial Terminal on Arduino, it prints normally.

Snaitf: Also, when I connect it directly to the computer via USB and use the Serial Terminal on Arduino, it prints normally.

OK, that proves there is nothing wrong with the code. This means the problem is just a matter of procedure.

Is the USB cable disconnected from PC?

Have you proven the bluetooth setup on the PC is kosher by using it with other devices?

You might find the following background notes useful

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

Thanks for the resources! I tried the script from the second link, and same issue: it's not showing the print-out over bluetooth, but it does on the normal terminal. As for your questions:

1) Yes, I've been very careful to make sure the Bluetooth chip and the USB are never connected at the same time. I've got 4 AA batteries hooked into the external power port on the Arduino, so it's getting power from that. 4 AAs gives about 6V if I did my math properly, so that should be plenty to run the board and Bluetooth, yes?

2) I haven't tried using the computer's Bluetooth with anything else. How would I go about testing that? Would a simple file transfer, like a picture, back and forth from computer to phone prove the point?

Another theory I have, and you can tell me if it's good or not. On the Arduino terminal when I hook it up over USB, there's an "enter" button, while on TeraTerm it just seems to transmit as soon as I type something. Is it possible it's not returning anything because it's constantly getting an input from TeraTerm, thus making Serial.available() always return true? If that's the case, it would be a problem with TeraTerm, not my Arduino/Bluetooth setup, yes?

8:36 CST update: I moved a picture from my phone onto the computer and a different picture from the computer onto my phone via Bluetooth. There was a lot of asking permission, but it worked.

Snaitf: 1) 4 AAs gives about 6V if I did my math properly, so that should be plenty to run the board and Bluetooth, yes?

No. Your maths are probably OK but your physics is sorely lacking. 4xAA may well be closer to 5v and the minimum requirement on the external power socket is 7v. This may be the sole cause of your problems. Buy two more and start again. Do not be tempted to use a 9v PP3.

2) I haven't tried using the computer's Bluetooth with anything else. How would I go about testing that? Would a simple file transfer, like a picture, back and forth from computer to phone prove the point?

I think just a successful pairing with your phone will suffice.

on TeraTerm it just seems to transmit as soon as I type something.

I'm not familiar with Terra but it should have a send button somewhere. I use RealTerm, which has a clear send procedure that Arduino listens for. Same applies to phone terminals.

Aha. I didn't know that about the power socket. I will get more batteries tomorrow to test it. Thank you very much, and if it works, I'll update the thread accordingly. :)