Controlling an LED light using a mobile app and Bluetooth

This tutorial will show you how to control an LED light on an Arduino using a mobile app and a Bluetooth wireless connection.

Parts required

Here is what you’ll need:

  • An Android phone or iPhone
  • A free mobile app
  • Arduino Uno board
  • Breadboard
  • 220 Ohm resistor
  • 6 male-to-male jumper wires
  • HM-10 BLE Bluetooth 4.0 module (see bottom of page for exact model used in this tutorial)
  • An LED light
  • Arduino IDE software

Wiring it up

Wire up the project using jumper wires by following these instructions or checking out the circuit diagram and images below.

  1. Connect VCC on Bluetooth module to 3.3V on Arduino
  2. Connect GND on Bluetooth module to GND on Arduino
  3. Connect TXD on Bluetooth module to digital pin 7 on Arduino
  4. Connect RXD on Bluetooth module to digital pin 8 on Arduino
  5. Connect the long pin from the LED on the breadboard to digital pin 2 on Arduino
  6. Connect the short pin from the LED on the breadboard to a 220 Ohm resistor and from there to GND on the Arduino

Note: The STATE and EN pins on the Bluetooth module do not need to be connected to anything in this project.

Bluetooth

Here are some images showing the LED turned on and everything wired up.

IMG_1905

IMG_6092

IMG_5111

Arduino code

Create a new sketch in the Arduino IDE and add the following code. Then upload the sketch to your Arduino board.

#include <SoftwareSerial.h>
int led = 2;

SoftwareSerial Bluetooth(7, 8);

void setup() {  
  Serial.begin(9600);
  Bluetooth.begin(9600);
  pinMode(led, OUTPUT);
}

void loop() {  
  int command;
  
  if (Bluetooth.available()) {
    command = Bluetooth.read();  
    Serial.println("Input received:");
    if (command != 0)
    {
      // A non-zero input will turn on the LED
      Serial.println("0 / ON");
      digitalWrite(led, HIGH);
    }
    else
    {
      // A zero value input will turn off the LED
      Serial.println("1 / OFF");
      digitalWrite(led, LOW);
    }  
  }
}

Controlling the Arduino via Bluetooth

To connect your Android or iOS mobile device to the Arduino you will need to download a free app (or you could also make your own app) that can connect to the HM-10 Bluetooth module and send commands. You can search your device’s app store to find a free app that will work for this project but for this example we will use the free Bluetooth Terminal app on iOS.

Tip: If you search the iOS App Store or Google Play app store using the keywords “bluetooth arduino” or “bluetooth hm-10” you should be able to find a suitable app.

The steps below are for the Bluetooth Terminal app on iOS but will be similar for other apps on other devices:

  1. Open the app and connect to the Bluetooth module (in this case it is called CC41-A but the name will vary depending on the model you have).
    IMG_4901
  2. Tap ‘Select characteristic’ and then select FFE1 (at the bottom of the list).
    IMG_4902
  3. Select Decimal.
  4. Using the on-screen keypad, you can enter different decimal values. Enter 1 and tap the Send button. The LED light should turn on. Enter 0 and tap the Send button. The LED should then turn off. If you don’t see anything happen, click Tools > Serial Monitor in the Arduino IDE and then set the baud date to 9600 bauds. Check if any input is being received and displayed in the serial monitor when you send the 0 or 1 commands to the Arduino from the app.
    IMG_4903

Where to from here?

You can use Bluetooth to control other projects such as a robot or car. You can also try receiving data from the Arduino – eg. send sensor readings to your phone.

Which Bluetooth module should I use?

There are several different Bluetooth modules that should work with this tutorial. The one used in this project was purchased on eBay and is called “HM-10 CC2540 CC2541 BLE Bluetooth 4.0 Wireless Module“.