Programming Arduino to check for HC-05 status

Hi folks,

Probably a question like this one was addressed before, but I wasn't able to find a proper answer. Let me give you a little background on my project:
I have an Arduino Uno, a couple of sensors and a HC-05 Bluetooth module which is being used to send the sensors' data to an Android application. I'm using the Serial.begin/Serial.print to effectively start sending/writing the infos to the application - and the said sending is happening whether or not there's a connection.
By here, all the things are running smoothly, but I can't quite figure out how to set up the the following thing:
It may sound weird, but basically what I'm trying to do is to program the Arduino Uno to check the HC-05 Bluetooth's status:

  1. If the module is not connected to anything, no serial data should be sent;
  2. If there's an active connection going on - as the status should read 1 or High or something like that, only then should the Arduino start sending the serial data by using Serial.begin.

How could I get the program to check the module's status and only after that to start sending the data, if the status reads there's an active connection? Is the STATE pin of the module of any use?

Thanks y'all!

Good discussion of monitoring the state pin here
https://forum.arduino.cc/t/hc-05-state-pin/573388

1 Like