Mid-Senior Engineers: Reinvent your career with Robotics, earning $100k-$200k+ in the next 90 days. Learn More

Bluetooth Low Energy (BLE) Tutorial for Arduino

Liz Miller Learn Robotics

About the Author, Liz Miller, Founder/CEO @ Learn Robotics

Liz graduated with a degree in Robotics Engineering from Worcester Polytechnic Institute and researched drones at UPenn's GRASP Lab. Liz is a former Raytheon Engineer, where she managed major $MM automation projects worldwide. Today, she's the driving force behind Learn Robotics, offering the Robotics Career Blueprint for Engineering Professionals and beginner courses through the Online Robotics Class. Liz is a third-generation entrepreneur who is all about the application of innovation in robotics, automation, and AI. Follow Liz on LinkedIn and Facebook.

Disclosure: Some of the links below are affiliate links. This means that, at zero cost to you, Learn Robotics will earn an affiliate commission if you click through the link and finalize a purchase. Learn Robotics is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a way for websites to earn advertising revenues by advertising and linking to Amazon.com.

Join our Private Discord Server, MakeRobots! Sign Up

I am back again with a simple electronics tutorial for beginners. In this post, I will show you how to get started with the Bluetooth Low Energy (BLE) 4.0 module to control LEDs. This project can be adapted to also control relays or robots. BLE is not like normal HC05/06 modules, because it works on Bluetooth V4.0.  To be able to connect to this module, your smartphone must have bluetooth version 4 or higher.

Materials for BLE Arduino project

  1. Arduino Uno
  2. Bluetooth Module (AT-09 or HM-10)
  3. Breadboard, LED, and Resistors Kit
  4. Smart Phone (with Bluetooth 4.0 or above.)
  5. Serial Bluetooth Apk.

NOTE: Most of the GUI control apps do not work with BLE modules.

BLE Arduino Wiring Diagram

First, connect the bluetooth module on the breadboard. The bluetooth module RXD pin requires 3.3V, while the Arduino supplies a 5V output. Therefore, we will create a voltage divider using 1K and 2K Ohm resistors to adjust this voltage.

When you’re finished, make the following connections (Bluetooth Module -> Arduino):

  • VCC  -> 5v
  • GND -> GND
  • TX -> RX
  • RX -> TX

Be sure to connect the resistors to the bluetooth module as shown in the picture. Then, connect one end of resistor (2 KΩ) to GND and other resistor (1 KΩ) to TX pin of the Arduino. The BLE modules have a different pinouts, so make sure you read the labels carefully before connecting.

Now, connect two LEDs on breadboard in series with 1 KΩ resistors. Then attach the LEDs to pins 8 and 9 on the Arduino. Here’s what it should look like when you’re done.

Arduino BLE Code

Now, let’s write a code to control LED’s using Smartphone over Bluetooth. We will achieve this using Serial communication. First, initialize the variables and pins as shown bellow:

int led1 = 8; //First LED to Arduino pin 8
int led2 = 9; //Second LED to pin 9

int data; //Variable to store serial data

int flag1 = 0; //Variable to store LED1 state
int flag2 = 0; //Variable to store LED2 state

Then write the setup() method to set the pins as Outputs and enable Serial communication.

void setup()
  Serial.begin(9600); //Start serial communication
  pinMode(led1, OUTPUT); //Set pin 8 as output
  pinMode(led2,OUTPUT); //Set pin 9 as output

Finally, we need to write the loop() method to execute the main logic for control.

void loop()
  while(Serial.available()) //While bluetooth is receiving data
    data == Serial.read(); //Accept & store data in the variable "data"
    if(data == '1') //If received data = 1
      if(flag1 == 0) //Check if flag = 0
        digitalWrite(led1,HIGH); //turn led1 on
        Serial.println("LED 1 is on"); //print message on serial monitor
        flag1 = 1; //set flag as 1
      else if(flag1 == 1) //If flag is already 1
        digitalWrite(led1,LOW); //Turn off led1
        Serial.println("LED 1 is off"); //print message
        flag1 = 0; //set flag as 0
    if (data == '2') //if data received is 2
     if(flag2 == 0) //if flag value is 0
        digitalWrite(led2,HIGH); //turn led2 on
        Serial.println("LED 2 is on"); //print message
        flag2 = 1; //set flag2 as 1
       else if(flag2 == 1) //if flag2 is already 1
         digitalWrite(led2, LOW); //turn led2 off
         Serial.println("LED 2 is off"); //print message 
         flag2 = 0; //set flag as 0

With that done, we can now upload the code to the Arduino board. Make sure you disconnect the bluetooth module before uploading the code. (The TX/RX pins are used by Serial Communication when uploading sketches.)

Download the example code below!

Download BLE Arduino Code (.ino)

Use your BLE Smartphone with Arduino

To connect your phone to Bluetooth first you need a Bluetooth Serial App. I’ve used Bluetooth Serial Terminal.

After the connection is established, press the ‘M1’ key to assign it a value. Assign ‘M1’ = 1 and ‘M2’ = 2.

Now power up the Arduino and Click M1 on the Smartphone App. You should see the first LED turn on. Click M1 again to turn the LED off. Repeat this process with M2 for the second LED.

And that’s it! Now that you know how to control LEDs with Arduino through Bluetooth, you can tinker around with this tutorial and modify the code to control your own projects.

If you have any questions or face any difficulty, feel free to ask in the comments below. In next tutorial, I will show you how to make bluetooth controlled robot.

Would you like to learn basics of robotics? Check out our new Robotics eCourse.

Experienced Engineer (Mechanical, Electrical, Computer, Software): If I offered to help you upgrade your engineering career to robotics, earning $100k-$200k+ in the next 90 days, would you take me up on that offer? Click here for details.
Liz Miller Learn Robotics

🚀 Pre-Launch: Become a "MakeR" with MakeRobots!

Hey Reader, 👋

Liz Miller, Founder/CEO, here with some Exciting News!

Learn Robotics just acquired MakeRobots™, an Online Robotics Community, and are prepping its Official Learn Robotics Debut in Late 2023.

MakeRobots™ is your one-stop-shop for learning, gaining coding, electronics, and robotics skills, connecting, and building robots for one low monthly membership!

Join MakeRobots™ at our Special Pre-launch Rate!
🤖 Access our Private Community & Robotics Courses
💬 Network, Collaborate, Connect with Other Makers
🔓 Only $5.99/month – locked in for life
⏱️ Pre-launch deal is Limited to the first 1,000 subscribers

This is a perfect opportunity for you to get into the fastest growing robotics community on the internet, at our ground-level, pre-launch membership rates.

👇 Click the button below to Claim your Pre-launch Membership and become a MakeR in the MakeRobots Community, today!

Learn Robotics Botly Favicon