I have arduino nano and hc06 bluetooth. bluetooth tx pin to arduino rx pin, bluetooth rx pin to arduino tx pin, when I connect to hc06 with my android mobile, everything works if Serial port monitor is open, but if serial monitor not opened, nothing works. do you have any idea for this problem ? I want my code works without opened serial monitor
What do you mean 'everything works'? What are you doing with it? What code?
int ledPin = 9;
int led2Pin = 5;
void setup(void) {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(led2Pin, OUTPUT);
}
void loop(void) {
char z ;
if(Serial.available())
{
z=Serial.read();
if(z=='0')
{
Serial.println("greenledon");
digitalWrite(ledPin, HIGH);
digitalWrite(led2Pin, LOW);
}
else if(z=='1')
{
Serial.println("redledon");
digitalWrite(led2Pin, HIGH);
digitalWrite(ledPin, LOW);
}
}
}
if serial port monitor open, I can connect arduino nano via bluetooth, and if i send "0" to arduino from bluetooth serial program which installed my android mobile, green led open, if I send "1" to arduino red led open.. But if arduino serial monitor is not open, i am sending from my mobile but no leds open.
What do you see in serial monitor when it's working? Do you see your messages only once per command or does it constantly spam the same message until you change to the other?
If you also printed z's value, you'd see what was happening.