问题
So i've been trying to connect my HC-05 BT module to PC. I'm sure i connected everything correct, i'm not new with arduino stuff. What i try to do now is i want to communicate with arduino using uart connection via BT. I have arduino leonardo, and here is my code:
void setup()
{
Serial1.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
if (Serial1.available()>0) {
String ainfo;
ainfo = Serial1.readStringUntil('\n');
if (ainfo.equals("ON"))
{
digitalWrite(LED_BUILTIN, HIGH);
Serial1.println("LED On");
}
else if (ainfo.equals("OFF"))
{
digitalWrite(LED_BUILTIN, LOW);
Serial1.println("LED Off");
}
}
}
(i use Serial1, because Leonardo...) I connected HC-05 with PC, i mean i 'paired' it, because this is where the problem occurs.
My HC-05 is blinking, and when i open port 20, it stops blinking all the time, instead it blinks twice ever 2 seconds (blink twice, not two second blink). When i type anything to serial monitor, nothing happens. Arduino's RX diod doesn't even blink (i don't know if it should, but when i send data from another app through USB cable, it's blinking, so i think in this example it also should). I've downloaded an app on my phone, and tried to do send anything with a hope it will work, but it didn't, of course HC-05's diod behaved same as when i tried to send data from PC (blinks twice every two seconds). I hope you will find a mistake i make, or maybe the code is bad and that's the reason it's not doing anything.
Every Answer would be appreciated.
来源:https://stackoverflow.com/questions/58547303/problems-with-connecting-hc-05-bluetooth-module-to-pc