Arduino Nano Control LED via Bluetooth

This tutorial instructs you how to program Arduino Nano to control a LED through either Bluetooth or BLE.

This tutorial gives instructions for both modules.

We will use the Bluetooth Serial Monitor App on a smartphone to send commands to Arduino Nano.

These commands include:

Arduino Nano LED Bluetooth

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×HC-05 Bluetooth Module
1×(Alternative) HM-10 BLE Module
1×LED
1×220 ohm resistor
1×Breadboard
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino Nano
1×(Recommended) Screw Terminal Adapter for Arduino Nano

Or you can buy the following sensor kit:

1×DIYables Sensor Kit 30 types, 69 units
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. We appreciate your support.

Overview of LED and Bluetooth Module

If you are unfamiliar with LED and Bluetooth Module (pinout, how it works, how to program ...), the following tutorials can help you:

Wiring Diagram

  • If you desire to manage LED through Bluetooth, the HC-05 Bluetooth module should be used in accordance with the wiring diagram below.
The wiring diagram between Arduino Nano and LED Bluetooth

This image is created using Fritzing. Click to enlarge image

  • If you wish to manipulate an LED through BLE, the HM-10 BLE module should be utilized in accordance with the wiring diagram below.
The wiring diagram between Arduino Nano and LED BLE

This image is created using Fritzing. Click to enlarge image

Arduino Nano Code - controls LED via Bluetooth/BLE

The code functions for both the HC-10 Bluetooth module and the HM-10 BLE module. It is applicable to both.

/* * 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-control-led-via-bluetooth */ #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 } } }

Detailed Instructions

  • Download the Bluetooth Serial Monitor App to your smartphone.
  • Open the code in Arduino IDE and click the Upload button to upload it to the Arduino Nano. If you have trouble uploading, disconnect the TX and RX pins from the Bluetooth module, upload the code, and then reconnect them.
  • Launch the Bluetooth Serial Monitor App on your phone and select Classic Bluetooth or BLE according to the module you used.
Bluetooth Serial Monitor App
  • Connect the Bluetooth App to the HC-05 Bluetooth module or HM-10 BLE module.
Bluetooth Serial Monitor pairing
  • Enter either “LED ON or “LED OFF and press the Send button.
Bluetooth Serial Monitor App
  • Check out the LED's state on the Arduino Nano board. It will be either ON or OFF.
  • Additionally, we can view the LED's state on the Bluetooth App.
  • Finally, check the outcome on the Android App.
Bluetooth Serial Monitor App

You may be curious as to how Arduino Nano can interpret a full command? For example, when we send “OFF”, how does Arduino Nano determine whether the command is “O”, “OF” or “OFF”?

When sending a command, the Bluetooth App adds a newline character ('\n') by choosing the “newline” option on the App. Arduino Nano will read data until it encounters the newline character. The newline character serves as a command separator.

If you find the Bluetooth Serial Monitor app helpful, kindly give it a 5-star rating on Play Store. We would be grateful for your support. Thank you!

Video Tutorial

Function References