Arduino Nano - BLE

This tutorial instructs you how to use Arduino Nano to control BLE HM-10 Module. In detail, we will learn:

Arduino Nano BLE

The purpose of this tutorial is to:

It is important to take into account that this tutorial is focused on Bluetooth Low Energy (BLE, Bluetooth 4.0). If you need information regarding Classic Bluetooth (Bluetooth 2.0), please refer to the similar tutorial Arduino Nano - Bluetooth.

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×HM-10 Bluetooth Module
1×Jumper Wires
1×Breadboard
1×(Recommended) Screw Terminal Expansion Board for Arduino Nano
1×(Recommended) Breakout Expansion Board for Arduino Nano
1×(Recommended) Power Splitter For Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of HM-10 Bluetooth Module

The HM-10 is a Serial BLE module which acts as a Serial to Bluetooth Low Energy converter. It has the capability to:

  • Receive data from the Serial RX pin and transmit it to a paired device like a smartphone over BLE
  • Receive data from BLE (from the paired device) and send it to the Serial TX pin.

When an Arduino Nano is used to communicate with a smartphone app (Android/iOS), the following steps take place:

  • The Arduino Nano is connected to the HM-10 Bluetooth module via the Serial/SoftwareSerial pins
  • The HM-10 Bluetooth module is paired with the smartphone app
  • Data is sent from the Arduino Nano to the smartphone app by sending it to the Serial/SoftwareSerial
  • Data is received from the smartphone app by the Arduino Nano by reading it from the Serial/SoftwareSerial
  • No extra BLE code is necessary on the Arduino Nano.

The BLE HM-10 Module Pinout

BLE pinout

The HM-10 BLE Module has 6 pins:

  • BKR pin: This pin is used to control the behavior of the module. Beginners should ignore this pin.
  • RX pin: This is a serial data pin, which should be connected to the TX pin of Arduino Nano. Data received from this pin will be sent to Bluetooth.
  • TX pin: This is a serial data pin, which should be connected to the RX pin of Arduino Nano. Data received via BLE will be sent to this pin as serial data.
  • GND pin: This is a power pin, which should be connected to the GND of the power source.
  • VCC pin: This is a power pin, which should be connected to 3.3V of Supply voltage.
  • STATE pin: This pin indicates the working states:
    • Blink in standby mode - repeat 500ms pulse;
    • On in connection state - high level.

    ※ NOTE THAT:

    • Only four pins are required for the HM-10, which are VCC, GND, RX, and TX.
    • Some producers make the HM-10 with only these four pins.

Overview of Bluetooth Serial Monitor App

To use the Bluetooth Serial Monitor App, you must first connect your Arduino Nano board to an HM-10 Bluetooth module. Then, download and install the app on your smartphone. Finally, open the app and establish a connection with the HM-10 Bluetooth module.

Once the steps are finished, you will be able to transmit and receive data from the Arduino Nano as if you were using the Serial Monitor in the Arduino IDE, without having to make any changes to the existing Arduino Nano code or adding any Bluetooth-specific code.

Wiring Diagram

The wiring diagram between Arduino Nano and BLE

This image is created using Fritzing. Click to enlarge image

The Table of Wiring. A Table for Wiring

Arduino Nano Pins HM-10 Bluetooth Pins
RX (Pin 0) TX
TX (Pin 1) RX
5V VCC
GND GND
BKR (NOT connected)
STATE (NOT connected)

※ NOTE THAT:

The Arduino Nano code can utilize other pins by substituting the Serial object with an alternative like Serial1, Serial2, or SoftwareSerial (if available).

How To Program For Bluetooth

No specific Bluetooth programming is required, only Serial programming is necessary.

Arduino Nano sends data to Bluetooth App on Smartphone

To send data from an Arduino Nano board to a Bluetooth application on a smartphone, the following Arduino Nano code can be utilized. This example shows transmitting the message “Arduino here, command me!” from the Arduino Nano to the smartphone app every one second.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-ble */ void setup() { Serial.begin(9600); } void loop() { Serial.println("Arduino here, command me!"); delay(1000); }

Detailed Instructions

  • Scan for available devices and select the HM-10 module.

To use the code and establish a connection between an Arduino Nano board and a smartphone using BLE, follow these steps:

  • Download and install the Bluetooth Serial Monitor App on your smartphone.
  • As per the wiring diagram, connect the HM-10 Bluetooth module to the Arduino Nano board.
  • Open the Arduino IDE, copy the code provided, and upload it to the Arduino Nano board. If you experience difficulty uploading the code, disconnect the TX and RX pins from the Bluetooth module, upload the code, and then reconnect the RX/TX pins.
  • Launch the Serial Monitor on the Arduino IDE.
  • On your smartphone, open the Bluetooth Serial Monitor App and switch to the BLE mode.
  • Look for available devices and select the HM-10 module.
Bluetooth Serial Monitor App
  • Connect the smartphone to the HM-10 Bluetooth module.
Bluetooth Serial Monitor pairing
  • Take a look at the outcome on the Android App.
Bluetooth Serial Monitor App
  • Take a look at the output displayed in the Serial Monitor of the Arduino IDE.
COM6
Send
Arduino here, command me! Arduino here, command me! Arduino here, command me! Arduino here, command me! Arduino here, command me!
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

If you take the necessary steps and execute the code, you will see that the data shown on the Serial Monitor of the Arduino IDE and on the Android application will be the same.

Bluetooth App Send data To Arduino Nano

The code below carries out the following tasks:

  • Sending data from the Bluetooth app to the Arduino Nano board
  • The Arduino Nano board reading the incoming data and then sending a response back to the Bluetooth device.
/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-ble */ // NOTE: change the Serial to other Serial/Software Serial if you connects Bluetooth module to other pins void setup() { Serial.begin(9600); } void loop() { Serial.println(F("Arduino here, command me!")); if (Serial.available()) { // if there is data comming String command = Serial.readStringUntil('\n'); // read string until meet newline character if (command == "LED OFF") { Serial.println("LED is turned OFF"); // reports action to smartphone app // TODO: control your LED here } else if (command == "LED ON") { Serial.println("LED is turned ON"); // reports action to smartphone app // TODO: control your LED here } } delay(500); }

Detailed Instructions

Here are the steps to use the code with Arduino Nano and an Android app:

  • Launch the Arduino IDE and copy the code provided.
  • Click the Upload button to transfer the code to the Arduino Nano board.
  • Open the Serial Monitor from the Arduino IDE.
  • Start the Android App and pair it with the HM-10 Bluetooth module following the instructions given in a previous example.
  • After connecting, type "LED ON" or "LED OFF" in the Android app and press the "SEND" button.
Bluetooth Serial Monitor App
  • The Arduino Nano board will receive the data and print a response to the Serial port. Afterwards, this data will be transmitted to the Bluetooth app. Lastly, the result can be viewed on the Android app.
Bluetooth Serial Monitor App
  • Examine the output displayed on the Serial Monitor of the Arduino IDE.
COM6
Send
Arduino here, command me! Arduino here, command me! Arduino here, command me! Arduino here, command me! Arduino here, command me! Arduino here, command me! LED ON LED is turned ON Arduino here, command me! Arduino here, command me! Arduino here, command me! LED OFF LED is turned OFF Arduino here, command me! Arduino here, command me!
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Once you have finished the steps above,. you will observe that the data displayed on the Serial Monitor of the Arduino IDE and the Android app match.

Arduino Nano Code - Control LED with smartphone App via BLE

The following Arduino Nano example code makes use of commands “ON” and “OFF” obtained through the Bluetooth Serial Monitor App to switch on/off an integrated LED.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-ble */ #include <SoftwareSerial.h> #define SOFT_RX 4 // The Arduino Nano pin connected to the TX of the bluetooth module #define SOFT_TX 5 // The Arduino Nano pin connected to the RX of the bluetooth module #define LED_PIN 12 // The Arduino Nano pin connected to the LED SoftwareSerial bluetooth(SOFT_RX, SOFT_TX); void setup() { Serial.begin(9600); bluetooth.begin(9600); pinMode(LED_PIN, OUTPUT); // set the digital pin as output: } void loop() { if (bluetooth.available()) { // if there is data comming String command = bluetooth.readStringUntil('\n'); // read string until meet newline character if (command == "LED OFF") { digitalWrite(LED_PIN, LOW); // turn off LED bluetooth.println("LED is turned OFF"); // reports action to smartphone app } else if (command == "LED ON") { digitalWrite(LED_PIN, HIGH); // turn on LED bluetooth.println("LED is turned ON"); // reports action to smartphone app } } }

You can find further information on the instructions in the tutorial titled Arduino Nano controls LED via Bluetooth/BLE. For a more detailed look at the instructions, refer to the Arduino Nano controls LED via Bluetooth/BLE tutorial.

Arduino Nano Code - Control Servo Motor with smartphone App via BLE

  1. The Arduino Nano code below is used to receive an angle value from the Bluetooth Serial Monitor App. 2. This angle value is then used to control the angle of a servo motor.
/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-ble */ #include <Servo.h> #include <SoftwareSerial.h> #define SOFT_RX 4 // The Arduino Nano pin connected to the TX of the bluetooth module #define SOFT_TX 5 // The Arduino Nano pin connected to the RX of the bluetooth module #define SERVO_PIN 12 // The Arduino Nano pin connected to the servo motor SoftwareSerial bluetooth(SOFT_RX, SOFT_TX); Servo servo; // create servo object to control a servo int pos = 0; // variable to store the servo position void setup() { Serial.begin(9600); bluetooth.begin(9600); servo.attach(SERVO_PIN); } void loop() { if (bluetooth.available()) { // if there is data comming int angle = bluetooth.parseInt(); if (angle >= 0 && angle <= 180) { servo.write(angle); // rotate servo bluetooth.print("Rotated servo to angle: ");// reports action to smartphone app bluetooth.println(angle); } else { bluetooth.print("Invalid angle: ");// reports invalid value to smartphone app bluetooth.println(angle); } } }

You can get a more detailed look at the instructions in the Arduino Nano controls Servo Motor via Bluetooth/BLE tutorial. For a closer look at the instructions, please check out the Arduino Nano controls Servo Motor via Bluetooth/BLE tutorial. If you would like to have a better understanding of the instructions, please refer to the Arduino Nano controls Servo Motor via Bluetooth/BLE tutorial.

If you find the Bluetooth Serial Monitor app helpful, please rate it 5 stars on Play Store. Your appreciation is much appreciated!

Video Tutorial

Function References

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!