简体   繁体   中英

Arduino HC-05 Bluetooth module disconnects when sending data

I'm new to Arduino. I'm trying to build a program to control a breadboard through Arduino using the bluetooth module HC-05. At the moment I don't have anything on the breadboard and I'm just trying to test the connection. This is what I've done so far:

I put the module on the breadboard and I've paired it with the computer. When it's paired, the red led starts blinking slowly. I've connected the bluetooth Rx to Arduino Tx and Arduino Rx to bluetooth Tx following this tutorial: http://playground.arduino.cc/Learning/Tutorial01

I've also implemented both Java and Arduino programs following that tutorial. Here they are:

JAVA

public class Arduino extends PApplet{

public void connect(){
    String[] serials = Serial.list();
    Serial port = new Serial(this, Serial.list()[0], 9600);
    port.write('H');
    port.dispose();
}

ARDUINO

 void setup() {
  Serial.begin(9600);
  Serial.println("Start");
}

void loop() {
  if(Serial.available()){
   int a = Serial.read();
   Serial.print(a);
 }
}

The Java part should send the letter H to Arduino and Arduino should detect that and print it on the Serial monitor. But what actually happens is that I send data, and the led on the HC-05 starts blinking faster (which means the connection is lost). Why does that happen? I'm pretty confused. For the communication I'm using the port COM6 and COM7. It depends on how it connects. To see what port to use I just run the Java program: if the port is not correct, it will just get stuck and send nothing.

Any help is appreciated. Thanks!

In the end, I've solved this problem by removing this line of code:

port.dispose();

It would never work with it because I was getting rid of the connection. I don't know what I was thinking at the time I did that. That was very silly of me.

Ok so I had this problem. If you are using the L293D motor shield, you'll be running the arduino of the same power supply, which I think must affect the power output the the bluetooth HC05 module. Take out the jumper plug on the L293D motor shield, and run the arduino of a separate power source (eg PP3 battery) and the problem disappears, OK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM