Set hm10 mode programatically

I need to set the ble hm10 mode programatically in my app, but can't seem to figure out how.
If someone could please tell me how, i would really appreciate it.

Are you talking about the role?

On setup() you should send AT+ROLE=1 OR 0 in case of other AT command you only have to look for him on the hm-10 at commands doc. And send it using write.

So I should just write on setup: AT+Mode=2 or AT+MODE2?

What I don't get is how am I supposed to write something to the bt module in the aetup.
I don't know if that's possible, and if it is, I think I would do something like


if I am not mistaken

are you talking about role or mode? Both are two different commands in the hm10 AT commands list. Anyways for either of them you need to use the SoftwareSerial library and initialize any pins as tx rx and then serial write the AT command in the same format as you do on the serial monitor.

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(3, 4); //

void setup()
BTSerial.begin(9600); // check for the default baud rate of your HM 10 module
void loop(){

BTSerial.write(“AT+ROLE0”); // use whatever command you want

Hope this helps.