Hi!
I’m working on a simple program to send and receive text between my phone and the Arduino Leonardo with a HC-05 Bluetooth module. The problem I have is that I can send text from my phone (using the app Arduino BlueControl) to the serial monitor, but not from the serial monitor to the phone. I have the Rx and Tx connected on the dedicated pins (PD0 and PD1) on the Leonardo. This is my code:
#include <SoftwareSerial.h>
char c = ' ';
// BTconnected is false when not connected and true when connected
boolean BTconnected = false;
// connect the STATE pin to Arduino pin 4
const byte BTpin = 3;
void setup()
{
// set the BTpin for input
pinMode(BTpin, INPUT);
// start serial communication with the serial monitor on the host computer
Serial.begin(9600);
while (!Serial){}
Serial.println("Arduino is ready");
Serial.println("Connect the HC-05 to a device to continue");
// wait until the HC-05 has made connection
while (!BTconnected)
{
if ( digitalRead(BTpin)==HIGH)
{
BTconnected = true;
};
}
Serial.println("HC-05 is now connected");
Serial.println("");
Serial1.begin(9600);
while (!Serial1){}
}
void loop()
{
// Keep reading from the HC-05 and send to Arduino Serial Monitor
if (Serial1.available())
{
c = Serial1.read();
Serial.write(c);
}
// Keep reading from Arduino Serial Monitor input field and send to HC-05
if (Serial.available())
{
c = Serial.read();
Serial1.write(c);
}
}
Is there something wrong with the code?
The code does work when I use SoftwareSerial and set the Rx and Tx to some other pins.
Thanks in advance!
Edit: I’ve debugged the code using Serial.println(“test”) in the last if statement, which was printed in the serial monitor. so the serial port is available and it should execute the Serial1.write(c) line.