Is there a way to check if a bluetooth modul is connected?

Hello, I'm fairly new to arduino and I can't find anything to answer my question so I figured I could ask here. Basically I'm making a project with a LED strip with remote control (through HC-05) and I was thinking maybe it would be cool if the LEDs would blink red when connected to a source until the BT modul connects to the phone and I have no idea what "if" function should I use to achieve that. I tried to mess with the "bluetooth.available" thingy but that didn't work. Any help would be appreciated thank you.

#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>


#define LED_COUNT 180
#define LED_PIN  8      
#define BRIGHTNESS 100
#define RX 3
#define TX 2 
#define SATURATION 255
#define LED_TYPE WS2812B




int dir2 = 1;
int dir = 1;
int bright = 0;
int bright2 = 21;

SoftwareSerial bluetooth(TX, RX);

Adafruit_NeoPixel pixels(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

int tlac2_mod=0;
int tlac3_mod=0;

void setup() {


  strip.begin();      
  pixels.begin();
  
  bluetooth.begin(9600);
  bluetooth.println("Arduino zapnuto, test Bluetooth..");

  pinMode(LED_PIN, OUTPUT);  
  Serial.begin(9600);
}

void loop() {
  pixels.clear();
  byte BluetoothData;

The state output on the HC05 goes high when the module is connected to another device.

See HC-05 fs-040 State Pin | Martyn Currey

2 Likes

Extensive discussion on using the state pin here
https://forum.arduino.cc/t/hc-05-state-pin/573388

thank you, I'll look into it

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.