Bluetooth Projects

Bluetooth 4.0 HM-10 cc2541 Duplex

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).


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.

Bluetooth 4.0 HM-10 Master Slave Module

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

On your computer, open Arduino.
Make sure you select the correct usb serial port.
Open Serial Monitor and make sure the baud rate is 9600, this is the default baud rate.

Type in

you should get OK+NAME:HMSoft

If it says nothing, check your connections.

Now we can talk to BLE with AT command and the rest is simple.

See more AT Commands at the very end of the post.

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.


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+ROLE[0] to BLE A
Send AT+ROLE[1] 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.

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.

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.

int led = 3;           // the pin that the LED is attached to
Servo myservo;  // create servo object to control a servo

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'
  myservo.write(80);              // tell servo to go to position in variable 'pos'


void loop() {

  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'
      analogWrite(led, 255);

  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 {
  presensorValue = sensorValue;



Source: Bluetooth 4.0 HM-10 cc2541 Duplex


Leave a Reply

Your email address will not be published.

Back to top button