Digital threshold

I have an HC05 Bluetooth transceiver, with Tx/RX connected to the Rx/Tx pins of a Nano via a logic level shifter and that works fine.

It would be useful to monitor the State pin of the HC05 so I've connected that directly to A6 of the Nano and set it to use the internal pull-up resistor.
(Unfortunately I have no spare pins on the level shifter breakout board, and there's not enough room to fit another on the stripboard.)

Everything I've read about the HC05 suggests its output level at Tx should be high enough to be read with digital.Read() on the Arduino, so I assumed the HC05 State pin would be too, but it's output change is not being registered by the Arduino.

I've tried using analogRead() and measured the voltage at A6.
Bluetooth connected ........... 673 analogRead() ......... 3.3v
Bluetooth not connected .... 72 analogRead() ........... 0.002v

I could use analogRead() and set a threshold of (eg) 300 to set a bool flag.
Or is there another way to work around this?

A6 has no internal pullup resistor. A6 and A7 on any atmega328 based board are analog only and have no digitital stage (input or output).

Oh ******! Didn't know that. Thanks.

At the moment I am using A3 as randomSeed(). If I swap that to A6 and connect the HC05 State pin to A6, that should work ... right?

Yes, A3 has the internal pullup capability and is a digital pin. And a unconnected A6 should float into an indeterminate (random[ish]) state.

Thanks.

Hmmm ...
Moved the HC05 State output to A3 on the Nano and I get exactly the same problem.

That is high when connected and low when not connected.

Why use the internal pullup. The state pin is not open drain. Martyn Currie's page on the HC05 state pin does not pull the input up. Connect the state pin directly to the digital input (or analog pin in digital mode).

Why use the pullup? Because I'm inexperienced, have got into the habbit, and didn't think it through.
But it's making no difference if I use it or not.

When your HC05 connects, does the LED on the HC05 module change its flash pattern?

I wired a HC05 to my Uno (sorry, I have no Nano) and wrote a very short code to monitor the state pin. It works well. Mind the baud rate. Serial monitor needs to be set to 115200 baud. Connect Nano pin 2 to HC05 TX and Nano pin 3 to HC05 RX through a voltage divider. Connect state directly to the Nano A3 pin. Also for a visual indicator you can connect the state pib to an LED to ground through a suitable current limit resistor. LED on = connected, LED off = not connected.

Having the serial port connected is not really necessary. The state pin will work without it.

#include <SoftwareSerial.h>

char conn[] = "Connected";
char notConn[] = "Not Connected";
SoftwareSerial ss(2, 3);

void setup()
{
   Serial.begin(115200);
   ss.begin(9600);
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 1000;
   if (millis() - timer >= interval)
   {
      timer = millis();

      bool stateState = digitalRead(A3);
      Serial.print(" state = ");
      if (stateState == HIGH)
      {
         Serial.println(conn);
      }
      else
      {
         Serial.println(notConn);
      }
   }
}

This works. I can connect and disconnect from my tablet and serial monitor and the LED follow the state of the connection.

If this still won't work, post your test code, properly formatted and in code tags, please.

Also post a diagram of your wiring. Photos can help, too.

To date, my circuit has been on a veroboard along with various other I/O.
What I've now done is move the Nano, HC05 and the logic level breakout board to a breadboard.

I've tried it with both your connections and your code using the IDE's serial monitor, and my code and (see below) and an I2C LCD display. The only difference with what your suggesting is that, rather than using a voltage divider between Tx/Rx on the Nano and Rx/Tx on the HC05, I am using a logic level shifter with Hv and Lv being supplied respectively from the 5v and 3.3v pins on the Nano.

In all cases, when the Android app says a connection is established with the HC05,

  1. the Arduino fails to recognise the change at the State pin.
  2. the flashing pattern of the LED on the HC05 changes .
  3. there is a change in voltage from (nominal) 0v to 3.3v at both the State pin of the HC05 and the Arduino pin it is connected to.

The small exception is that, with your code and the IDE's serial output monitor, once or twice out or 20 or 30 serial.Print() calls, the output randomly shows a connection when nothing has changed.
To me, this suggests the voltage at the HC05 State pin is almost high enough for digital.Read() == HIGH but not really high enough.

(I've also used a different baud rate. It is one I have seen widely recommended for the HC05 and one that seems to work consistently well for serial comms between the HC05 and my Samsung Android phone.)

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcdDisplay(0x27, 16, 2);

const int btConnectPin = 3;
bool bluetoothConnect = false;
//  int bluetoothConnect = 0;

void setup() 
{
  Serial.begin(38400);
  
  pinMode(btConnectPin, INPUT); 
  lcdDisplay.init();
  lcdDisplay.clear();
  lcdDisplay.backlight();
}

void loop() 
{
  bluetoothConnect = digitalRead(btConnectPin);
//  bluetoothConnect = analogRead(btConnectPin);
  lcdDisplay.setCursor(0,0);
  lcdDisplay.print(bluetoothConnect);
}

HC05 State

And before I forget ... thanks for your help!!!!

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