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


3 thoughts on “HC-05 fs-040 State Pin

  1. Pingback: Quick Links | Martyn Currey

  2. You added wire from BT state pin to arduino pin 4.
    When you say “As a quick visual indicator you can put a LED + suitable resistor on the STATE pin”, how do you add the LED ? I have tried, but even when BT is connected, the LED is not lightning…
    I’m beginner with arduino. I want to use a blue LED but I don’t witch resistor to choose for a blue led, and I don’t how to connect the led (+ to BT module and – to arduino or reverse).
    Can you help me ?
    Thank’s in advance

    • First, not all modules are the same. Confirm that the one you have actually sets the STATE pin.

      When connected the STATE pin goes HIGH to 3.3v so the pin is providing the power. To the pin connect the LED and a resistor and then to GND. You can calculate the value of the resistor with Ohm’s law. Or use a resistor around 220ohm or 330ohm.

      The longer pin on the LED goes to the STATE pin. The longer pin is almost always the + or Anode.

      Also look at http://www.instructables.com/id/Identifying-LED-pins/

Leave a Reply

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

4 − two =

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>