Advices for a bluetooth project, how to connect to external bluetooth device (ANT BMS)

Hello everyone,
I want to use an arduino board (probably mega 2560 mini pro) to connect to an ANT BMS (which has embeded bluetooth).

So far I haven't found anyone else to use arduino to connect to Ant BMS but there are a few projects using a raspberry pi, as I already have an mega2560 board talking with an Energy Meter on Serial1, with my MPP Solar inverter on serial2, I want to use the same board to also talk with the BMS that monitors the battery.

  1. My first concern is regarding about HOW I WILL PAIR Arduino's HC-05 bluetooth module with AntBMS? I haven't found any tutorial yet, only the other way around, smartphone pairs with arduino bluetooth. I belive using AT commands? but it would be great if the pairing could be done in the code, eventually in the void setup() section.

  2. My second problem is regarding sending commands over bluetooth, I don't have any experience regarding sending commands, I just started now 2 weeks ago when I needed to connect to MPP Inverter, and with the help of a few guys on the forum, I have my arduino board running smoothly in the last week, talking to my inverter every 2 seconds, pushing data to my local server every 5 seconds.
    I made a code that theoretically should send the command to AntBMS and print the response to serial, I don't know why the guys that made the python code use the decode(hex) function. In the Communication Manual of Ant BMS it just says to send "0XDBDB00000000 return 140 byte date"

ANT_communication_protocol_EN.pdf (47.5 KB)

Does my code looking correct ?


while True :
   ser.write (test.decode('hex'))
 if(ser.isOpen() == False):
 Antw33 =

 data = (Antw33.encode('hex') [(74*2):(75*2)])
 data2 = (Antw33.encode('hex') [(111*2):(114*2+2)])


String Q1 = "0XDBDB00000000";

String bms_response;
void setup() {

//Protocol Asynchronous serial interface
//Baud Rate   9600 baud
//#Start bits 1
//#Data bits  8
//#Stop bits  1
//Parity      None

void loop() {
  Serial.println ("Sending command to Ant BMS");
  Serial.println ("Printing reply from ANT BMS:");
    bms_response = Serial2.readString();
      Serial.println (bms_response);
          bms_response = "";
  1. When I initialize the serial2 communication do I need to explicitly set those parameters also: Start bits 1, Data bits 8, Stop bits 1,Parity None? Or those are default values anyway ? If yes can you help me with the commands ?

Thank you

Nobody around to help me with this Bluetooth project ?

I the last days I googled a lot to learn what should be my next steps, so I know now I will need to set my bluetooth module to MASTER (only HC-05 can be master, HC-06 won't work)

I connected HC-05 to RX and TX pins of my mega and issued the commands in serial monitor (set to 38400 and Both NL & CR)

// responded : OK
// responded : OK
// responded : +ROLE:1
// responded : ERROR:(16)

I also tried to send the AT+INIT or AT+RESET like in this post but after any of those commands the led starts flashing quickly and it does not accept any other commands :frowning:

// responded: +STATE:INQUIRING
// OK

My next step is to find my external device (ANT BMS) address, and I was hoping to find it using the AT+INQ command, which results in error 16 ... anyone around to help me with this ?

Hello Sibianul.
My sorry I can't help you here, as I'm about in the same situation as you are.
But I will follow this post, as I'm also looking for a solution to read out my 30 calls ANT BMS over bluetooth via arduino.
I could find already some 'Smart BMS' examples, but these seems different from the Ant BMS.
Thanks to all more advanced users posting some useful info here !

@BartDePauw I don't know if I have problems with my bluetooth module or I'm doing something wrong, but I ordered a new one , I ordered 2 different modules , one HC-05 module, and an HM-11 BLE module .. but it will take some time till it comes from china :slight_smile:

Have you tried to connect the bluettoth module and pair with your ant bms trough arduino ? I'm stuck at error 16 when I send the command AT+INQ .. if I send the command AT+INIT the led of HC-05 starts flashing fast and it does not accept any other commands...

In the mean time, I used an RaspberryPi Zero w (has bluetooth and wifi built-in) I posted the modified code on the other forum where I found a python script made by someone else, but that used grafana and influx database, instead I needed to send the informations from ant bms to my local server trough http requests.

It does work great so far, I only tested a few days, and today or tomorrow I plan to bring the battery from my workshop to my house, it's quite heavy at ~160kg

That may depend on what a BMS is. If it is a plain vanilla SPP Bluetooth device, you might try connecting it to a phone so that you can retrieve the address, and then configure HC-05 to auto connect with it. See the Martyn Currey website

You obviously need to know which commands you can send. Once you do, you send them. - something like:

You don't need any of that stuff.

Thank you Nick.

I wanted to use the HC-05 device to find available bluetooth addresses , and there is where I failed as I couldn't get any reply from the AT+INQ command, as I always got ERROR(16) as mentioned in my second post.
If I also tried to send AT+INIT the bluetooth led started to flash fast and no commands are accepted after that :frowning: I don't know why others can send commands after AT+INIT .. but I will try again when I will have another module

If I understand you correctly, there is no surprise there. You cannot be in AT mode and comms mode at the same time with an HC-05, and I don't suppose you can do that with the other bluetooth either.

You cannot be in AT mode and comms mode at the same time with an HC-05

Comms mode ? I use an ArduinoMega2560, on serial0 my computer "talks" with arduino, on serial2 arduino communicates with HC-05 module, but when I sent AT commands I plugged in the HC-05 module on serial0 to send commands directly to the module.
I just wanted to be able to view all the online bluetooth devices in my office, to find out the address of Ant BMS. I couldn't find a way to find the address on my iPhone, and neither the Ant BMS app for iOS doesn't show the BT address of the BMS, so I wanted to use the same HC-05 module, to list all available bluetooth devices.

As I know the command to list available BT devices is : AT+INQ
In my case, this returns ERROR(16)
When I checked the documentation, error(16) means: SPP Lib not initialized

I googled now to find again the documentation which has all the errors meaning, as the one posted above doesn;t have the errors, but I found something else which I think might be the reason, it seems there is another pin on the BT module which needs to be high when initializing it with AT+INIT .. I don't know the state of that pin, the module came with a heat-shrink wrap around it ... I will cut that and check it.


Here are all the error of the HC-05 module:

//Appendix 1:Introduction of AT command error code
//The form of error ---- ERROR:(error_code)
//error_code(Hexadecimal) Note
0 AT command error
1 Default result
2 PSKEY write error
3 Too long length of device name (more than 32
4 No device name
5 Bluetooth address: NAP is too long.
6 Bluetooth address: UAP is too long.
7 Bluetooth address: LAP is too long.
8 No PIO number’s mask
9 No PIO number
A No Bluetooth devices.
B Too length of devices
C No inquire access code
D Too long length of inquire access code
E Invalid inquire access code
F The length of passkey is 0.
10 Too long length of passkey (more than 16 bytes)
11 Invalid module role
12 Invalid baud rate
13 Invalid stop bit
14 Invalid parity bit
15 Authentication device is not at the pair list.
16 SPP lib hasn’t been initialized.
17 SPP lib has been repeated initialization.
18 Invalid inquire mode
19 Too long inquire time
1A No Bluetooth address
1B Invalid safe mode
1C Invalid encryption mode 

talking wirelessly to another Bluetooth device. When it is doing that it is not in AT mode.

Normal, no choice.

Normal and sensible practice for a Mega.

Really? that's fine if you send a pre-written stream of commands, but rather pointless on a Mega where HC-05 normally sits somewhere else.

Some Android phones will do this without persuasion. Those that can't require a Mac address finder. I can only assume that such an app is available for iPhone but, since iPhone is incompatible with HC-05, it might not work. I think it will because it only has to sniff it.

You are probably alluding to the second level of AT commands, which cannot be accessed by merely pushing the button. Setting the EN pin high will probably fix this but you may have to access pin 34. See the Martyn Currey website. Either way, I would not have thought you would need to cut the sleeve. Further, you might check to ensure Bluetooth is indeed an HC-05, with the full complement of six pins on the breakout board.

Finding the bluetooth address is not that difficult.
I suppose you also have the ANT app on you mobile ? You can read the address from there.
You just need to use it with "," in place of the ":"
Also found a nice Android app to test sending to the ANT Bms : Serial Bluetooth Terminal
You can program the buttons below. Program one with 5A 5A 5A 00 00 5A DB DB 00 00 00 00 0D 0A ( you need to put it in HEX mode ) and the BMS answers with 140 bytes. Will now also start with a HC05 and a ESP8266.

I finished my project using an RaspberryPi Zero as it has BT and wifi onboard.

I posted the code for the raspberry pi on this forum

I have the iOS app for AntBMS and there is no option to see the BT address of the ant bms, this is why I wanted to find the address using arduino, but in the end I found the address using the raspberryPi, when scanning 2 addresses show up , the one that worked in my case was the one that DOESN'T HAVE "BLE" word in it, the first one worked:

BMS-ANT24H AA:BB:CC:91:23:45

ANT-BLE24H AA:BB:CC:92:23:45

After I made it work with rPi I didn;t had more time to try with arduino, but also I haven't received yet the new modules I purchased :frowning:

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