HC-05 fs-040 State Pin

This post follows on from Arduino With HC-05 Bluetooth Module in Slave Mode

The STATE pin on the HC-05 zs050 board is connected to the LED 2 pin on the small bluetooth module and the LED 2 pin is used to indicate when there is an active connection. This means the Arduino can connect to the STATE pin and determine when we have a connection. The STATE pin is LOW when the HC-05 is not connected and HIGH when the HC-05 is connected.

As a quick visual indicator you can put a LED + suitable resistor on the STATE pin. When the module is connected the LED will light.

You can also use the Arduino to read the value of the STATE pin.

Add a wire from the STATE pin on the HC-05 to the D4 pin on the Arduino



Upload the following sketch. The sketch now waits until pin D4 goes HIGH before starting the software serial and making a connection to the HC-05.

This sketch does not copy what you enter in the serial monitor input field to the serial monitor main window.

// Basic Bluetooth sketch HC-05_03 Using the state pin 
// Connect the HC-05 module and communicate using the serial monitor
// The HC-05 defaults to communication mode when first powered on.
// The default baud rate for communication mode is 9600
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
// Connect the HC-05 TX to Arduino pin 2 RX. 
// Connect the HC-05 RX to Arduino pin 3 TX through a voltage divider.
// Connect the HC-05 STATE pin to Arduino pin 4.
char c = ' ';
// BTconnected will = false when not connected and true when connected
boolean BTconnected = false;
// connect the STATE pin to Arduino pin D4
const byte BTpin = 4;
void setup() 
    // set the BTpin for input
    pinMode(BTpin, INPUT);   
    // start serial communication with the serial monitor on the host computer
    Serial.println("Arduino is ready");
    Serial.println("Connect the HC-05 to an Android device to continue");
    // wait until the HC-05 has made a connection
    while (!BTconnected)
      if ( digitalRead(BTpin)==HIGH)  { BTconnected = true;};
    Serial.println("HC-05 is now connected");
    // Start serial communication with the bluetooth module
    // HC-05 default serial speed for communication mode is 9600 but can be different
void loop()
    // Keep reading from the HC-05 and send to Arduino Serial Monitor
    if (BTserial.available())
        c = BTserial.read();
    // Keep reading from Arduino Serial Monitor input field and send to HC-05
    if (Serial.available())
        c =  Serial.read();

After uploading the sketch HC-05_03 open the serial monitor. You should see:
HC-05_03 Serial Monitor

Connect a device to the HC-05

And as soon as the Arduino notices that the HC-05 is connected (pin 4 goes HIGH) it will display the message “HC-05 is now connected”
HC-05_03 Serial Monitor

You can now send messages between the Arduino and the Android device. For more on how to do this see Arduino With HC-05 Bluetooth Module in Slave Mode


One thought on “HC-05 fs-040 State Pin

  1. Pingback: Quick Links | Martyn Currey

Leave a Reply

Your email address will not be published. Required fields are marked *

− one = 6

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>