Introduction: How to Use Bluetooth 4.0 HM10
In this example, I will show you how to communicate one micro controller to another micro controller BOTH WAYS via serial with cc2541 (BLE-HM-10). https://www.youtube.com/watch?v=6zXYH9arHMI For board design and code please download BLE_Duplex
Introduction
HM-10 is a BLE module for embedded system to get BLE wireless communication with BLE capable devices (e.g. iPhone and iPad). It is fully configurable by a rich and well documented AT command-set and allows transparent data communication via serial UART (default baudrate 9600bps). The Bluetooth 4.0 HM-10 is basically a breakout board for cc2541, it broke out the LED pins, RX/TX and also adding the voltage regulator that regular 5v to 3.3 v.
Step 1: Setup With FTDI + Arduino Serial Monitor + AT Command
Setup with FTDI + Arduino Serial Monitor + AT Command
There are so many things that you can do with Bluetooth 4.0 HM-10, but first you need to setup with FTDI cable to understand what and how it's doing.
You will need a FTDI cable and 4 female to male wires to hook up to Bluetooth 4.0 HM-10 / BLE



Step 2: Sending & Receiving (Both Ways ) Setting the Master-Slave Mode
With this method, you can turn the device on and have them talk to each other right away, without pairing, without initializing ... it is wonderful. The data goes both ways.
First you will need to Query the native MAC address using AT Command AT+ADDR?
You will get something like this 20C38FF61DA1, each BLE has a unique MAC address.
Use AT+CON[param1] and AT+ROLE[param1] to pair to another device.
Example
BLE A has Mac Address 11C11FF11DA1, I used AT+ADDR? to figure it out BLE B has Mac Address 22C22FF22DA2, I used AT+ADDR? to figure it out
Send AT+CON22C22FF22DA2 to BLE A Send AT+CON11C11FF11DA1 to BLE B (Send the B address to A, A address to B)
Send AT+ROLE0 to BLE ASend AT+ROLE1 to BLE B (Doesn't matter which one)
Now it's ready to use on you ATMEGA 328P, Arduino or Attiny. The red light will stay solid after the connection has been made on both BLE. This should take less than a second.
Find out AT Command here
https://www.seeedstudio.com/wiki/images/c/cd/Bluetooth4_en.pdf
Step 3: Sending & Receiving Both Ways on ATMEGA 328P / Arduino
It's very easy to talk to ATMEGA 328P / Arduino with the BLE, you can just use the hardware serial. Software serial should work for Attiny 44 to talk to BLE.
The data can talk both ways! Just Serial.println(Whatever you want); In the code below, the ATMEGA 328Ps "analog reads" the potentiometer data and sends serial data via BLE to each other turn each other's servo.
Step 4: Example Board
I took out the FTDI cable pads and upload my program with ISP pins to save some space on my board. I want this board to be part of my wearable project, that is why it's ULTA compact.
I did not use any SMD male pins to save some vertical space, because this needs to be wearable.
Each micro controller below runs the same code! So as soon as the BLE is on, it starts to look for the assigned address, it takes less than a second. The solid RED LED indicator on the BLE means the connection has been establish.
To make this wearable and flat, I have flexible cable coming out of it.
The Arduino Code
//receiving
int led = 3; // the pin that the LED is attached to #include Servo myservo; // create servo object to control a servo
//sending int sensorValue = 0; int presensorValue = 0;
void setup() { pinMode(led, OUTPUT); myservo.attach(A2); // attaches the servo on pin 9 to the servo object myservo.write(90); // tell servo to go to position in variable 'pos' delay(500); myservo.write(80); // tell servo to go to position in variable 'pos' Serial.begin(9600);
}
void loop() {
//receiving while (Serial.available() > 0) { int pos = Serial.parseInt(); if (pos > 1 && pos < 180) { myservo.write(pos); // tell servo to go to position in variable 'pos' //Serial.println(pos); analogWrite(led, 255); } sender(); } sender();
analogWrite(led, 10);
}
void sender() {
// Sending // read the input on analog pin 0: //sensorValue = analogRead(A1); sensorValue = map(analogRead(A3), 0, 1024, 5, 175);
//with noise reduction if (sensorValue == presensorValue || sensorValue - 1 == presensorValue || sensorValue + 1 == presensorValue) { } else { Serial.println(sensorValue); } presensorValue = sensorValue;
delay(50);
}

Participated in the
Arduino All The Things! Contest
27 Comments
6 years ago
Hey there, I need help!
I've a HM-10 and I need to connect to another BLE device that's suppose to supply my HM-10 with a bunch of data every few second.
My current condition is pairing with the device using AT+CON[mac] works and returns AT+CONNA and ends up with AT+CONNF.
I'm not sure what am I missing here. I've tried pairing it with my Android using a bluetooth terminal app and it works perfectly!
Is there any step that I'm missing like pairing or something?
Thanks!
Reply 4 years ago
Hi, I want to connect hm10 to my android phone but getting msg "Connection rejected " , could you please help me ?
Reply 5 years ago
hi,
i am also having the same issue..have u got any solution?
4 years ago
wasn't working for me as I had the version v.520(see "AT+VERR?" ) what i did is to upgrade its firmware and now it's working, also I did setup on the central (AT+ROLE1) with AT+IMME1 and AT+DISC? then AT+CONN[P1] where P1 is the index of the address of the peripheral
Reply 4 years ago
also if you want it to connect when starting set AT+IMME0 on the central after the setup
5 years ago
Hi,
i want to connect HM-10 with another BLE device (VNA-BT). i am able to connect that device on ble serial app in mobile but not with HM-10.can anybody help me ?
Thanks
5 years ago
Hello,
thanks for great job. I am using hm-10. it takes too long to pair with android app. I don't pair it via phone; I open the app and via app pair the hm-10. any suggestion to faster the paring time?
6 years ago
What means: "
exit status 1
'myservo' was not declared in this scope
I'm using Arduino IDE v1.8.3. This sketch does not pass verification. Is it supposed to be complete?
Reply 6 years ago
Disregard Q. Code is missing library call and instantiation:
#include <Servo.h>
Servo myservo;
Thanks.
6 years ago
hello guys, i need a help to proceed with ble
I have BLE HM 10 module and FTDI module . when i start giving AT commands
it responds to following AT COMMANDS
COMMANDS RESPONSE
1. AT - OK
2. AT+ADDR? - 00:15:83:00:57:E2
3. AT+VERSION? - Firmware V3. 0. 6 Bluetooth V4 . 0 .LE
4.AT+NAME? - NO RESPONSE
Please let me know the further procedure (AT COMMANDS) to test and how to connect with android phone.
THANKS!!!
6 years ago
Where did you buy your hm-10 modules. I had a horrible problem with getting fakes online. Also, the voltage level question....
You are using a FTDI cable that operates at 5 VOLTS. Do you need to use a voltage divider circuit (1k ohm/2k ohm) to bring down the voltage level to 3.3V at ftdi-TX/hm10-RX.
I have to ask because i had blown up several hm-10 modules (and a usb aerial module) before figuring this out
6 years ago
There is an app for iOS that makes using the HM-10 easy to use. It is for a single pin output. There is also a link the sketch for it. I used it with Arduino Nano, HM-10, a Relay, junction box, and an outlet to turn my room light off at night without getting out of my bed. The app is FatBeard HM10 here https://itunes.apple.com/us/app/fatbeard-hm10/id1198432512?mt=8
6 years ago
Check out this android app:
https://play.google.com/store/apps/details?id=com.optimist.bleCentral&hl=en
7 years ago
Hi,
If you are using the bare HM-10 module, make sure to cross connect RTS and CTS (pins 3 and 4, P1_4 and P1_5, UART_CTS and UART_RTS) otherwise the serial comms won't work. Note: Pins count from 1 top left, counter clock to 34 top right with the CC2541 chip facing you, antenna at the top. The manufacturers manual is confusing as it shows the antenna terminating on the right (Section 1.1 HM-10 Schematic), when it is in fact terminating on the left. Both diagrams in this instructable are correct.
Also note device is a DTE, so TX (pin 1, P1_6, UART_TX) is an output and RX (pin 2, P1_7, UART_RX) is an input.
The diagram in Step 1 eludes to this by cross coupling the TX and RX lines to an FTDI, effectively forming a NUL modem interconnection.
The AT command parser is poor quality (as you would expect), it requires all command strings be entered upper case (other than the name string). A command is considered entered once the interchar timer has been exceeded (for that given baud rate). ie no terminating character '\r'. There is no SReg support to set this via S3 (carriage return character). This means you will need to pre-store any commands and issue all in one go, back to back at your selected baud. This prevents the usual method of typing by hand and hitting enter as with all modem devices. Though to be fair the manual does mention this.
I found that the only consistent way to get activate changes was to either issue AT+RESET or power cycle the module.
Final note, changes are written to flash. ie they are permanent. Power cycling won't get rid of them.
Rgds
SQ
Reply 6 years ago
Thank you for these useful infos.
I succeeded thanks to you.
Reply 6 years ago
You're welcome
7 years ago
Dan,
Thanks for this instructable. Very informative. I hao 1tve an idea for a project that will aconnect 2 arduinos via bluetooth, but also be able to connect a phone 1 of the arduinos via bluetooth. The 2 arduinos will be connected together by default, using your method described above. But if I wanted the phone to connect, I would first need to disconnect them some how. Obviously, I want this to happen automatically. Do any modes support multiple connections in the HM-10. Do you have any idea how to make this work?
Thanks again for your work above. Fantastic!
Reply 7 years ago
I tried connecting two BLE modules by making one of them Master and the other Slave. The two pairs automatically. However if I try to discover the slave device using an iPhone the slave module is not shown on the device unless I disconnect the master. Is there any workaround for this ?
Reply 7 years ago
I also have the same problem - vajee
7 years ago
Very nice tuts. I would like to connect my hm10 module to andruino ide. But ide doesnt recognize that. I connected gnd to black , vvc to red, tx to green and rx to remained led and have plugged that to usb port on my comp.
What is me doing wrong? Thank you.