MATLAB Answers

Test connection failed in arduino hardware setup for HC 05 bluetooth module

36 views (last 30 days)
I am trying to connect Arduino Uno via Bluetooth to the MATLAB. I have programmed the Arduino Uno with libraries- I2C, SPI and Servo and configured the Bluetooth module HC-05 successfully. But when I check the test connection, it says "Test connection failed. Go back to check your settings". Also, my device’s Bluetooth is turned on and connected to the module.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 11 Jun 2021
Edited: MathWorks Support Team on 11 Jun 2021
Please follow the steps below:
a) Upload the IOserver onto Arduino Uno from the Upload Server screen after selecting 'Bluetooth' as the connection type in the selection screen.
NOTE: Do not connect HC-05 to the Arduino board yet.
b) Configure HC-05 if not done already. Follow the steps on the hardware setup screen.
NOTE: This step can be done independently of step a).
c) Skip step b), if already configured. Connect HC-05 to Arduino Uno. See the LED on HC-05 should blink rapidly.
NOTE: Do not unplug Arduino Uno while connecting the Bluetooth device.
d) Enter the Bluetooth address of the device. Test the connection. See the debugging tips below if you are facing any issue. It is normal to see the LED on HC-05 blink slowly in between and it should start blinking rapidly thereafter. Slow blinking confirms that communication between HC-05 and the computer is established. Thereafter, the Arduino object is constructed internally with the Bluetooth address provided. Rapid blinking confirms that Bluetooth communication is released.
e) To check if PC/MATLAB can communicate with the Bluetooth module, create an Arduino object.
a = arduino ('btspp://98D371F5EBF9','Uno')
a = arduino('HC-05','Uno')
should work when:
a) correct IOserver is uploaded onto Arduino Uno.
b) HC-05 is configured properly.
Some debugging tips to configure the HC 05 module and Test connection are mentioned below: 
  • Check if the HC-05 is configured properly. Connect the HC-05 module to the PC's COM port. On the "Configure Bluetooth Device" hardware setup screen, select the correct COM PORT and click 'configure'. Please refer to the hardware connections provided on the previous setup screen "Connect Bluetooth Device to Host Computer". This step configures the Baud rate of the HC-05 to 115200 at which the Arduino board can communicate with HC-05 over serial. 
To configure HC-05, first it needs to be put under configuration mode. For that, connect the device's 5V supply pin to Arduino Uno's 5V pin while pressing the 'reset' button on the HC-05. The LED on the module should blink slowly. Now, click on 'configure'. If it blinks rapidly, it means the module is under operation mode and the configuration will fail. 
  • If a correct IOServer is uploaded and HC-05 is configured properly and still ‘Test Connection’ won’t go through, try reconnecting HC-05 ( unplug 5V wire and reconnect it). After that, try creating a Bluetooth object on the MATLAB command window using the following commands:
>> b = Bluetooth('HC-05', 1); 
>> fopen(b);  
>> fclose(b); 
  • If Bluetooth object creation fails, check if HC-05 is paired with the computer. Please try below:
i) Turning off/on the computer's Bluetooth.
ii) Repower the HC-05 module. Try Bluetooth object construction again. 

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!