Control Your Projects With Bluetooth Low Energy.

by Harsh Dethe in Circuits > Arduino

8580 Views, 17 Favorites, 0 Comments

Control Your Projects With Bluetooth Low Energy.

IMG_20180516_100941-01.jpeg

In this Instructable I'll show you how to get started with Bluetooth Low Energy and and How you can control your projects with it. This will be basic and I'll try to keep it simple for beginners. I'll be using AT-09 BLE v4.0 which is a HM-10 compatible Bluetooth module. BLE stands for Bluetooth Low Energy , It is based on Bluetooth 4.0 technology. So this module won't work with older phones. Click Here to know more about BLE. If you don't have HM-10/AT-09 module you can use regular old HC-05. So lets get started...

Gathering Components :-

IMG_20170626_094257.jpg
IMG_20180514_153143.jpg
IMG_20180514_153200.jpg
IMG_20180514_153016.jpg
IMG_20180514_153303.jpg
IMG_20180514_153231.jpg

Here I've listed all the components along with best buy links.

  1. Arduino UNO
    Link for US
    Link for Europe
  2. Bluetooth Module (I've used AT-09. You can use HM-10/HC-05)
    Link for US
    Link for Europe
  3. Breadboard. (I recommend you get this kit.)
    Link for US
    Link for Europe
  4. LEDs.
    Link for US
    Link for Europe
  5. 1k resistors. (Can be found in any local electronics store.)
    Link for US
    Link for Europe
  6. Smart Phone ( with Bluetooth 4.0 or above.)
  7. Serial Bluetooth Apk.

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

All the components can be found at UTsource.net

Making Connections :-

Screenshot (37)-01.jpeg
IMG_20180514_175534.jpg
IMG_20180514_180841.jpg
IMG_20180514_181157.jpg
IMG_20180514_181408.jpg
  • Connect the Bluetooth module on bread board.
  • We need to divide the voltage sent to the receive pin because Arduino's pins output is 5v and our bluetooth module's receive pin needs 3.3v so we make a voltage divider using a 1k and a 2k ohm resistors.(as I didn't have a 2k resistor I've use two 1k resistors in series)
  • Now make the following connections :-

VCC -> 5v

GND -> GND

TX -> RX

RX -> TX

NOTE :- Connect the resistors to bluetooth module as shown in the picture. Then connect one end of resistor(2k) to GND and other resistor (1k) to TX pin of arduino.

  • Now connect two LEDs on breadboard in series with 1k resistors. and connect the LEDs to arduino's pin no. 8 and 9.
  • After the connection is done, We move on to the next part i.e coding...

Writing & Uploading Code :-

Screenshot (34).png
Screenshot (35).png
  • First open the Arduino IDE and write the following code. (I recommend you write it as it will be easy to understand than just coping it.)
int led1 = 8;
int led2 = 9;

int data;

int flag1 = 0;
int flag2 = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(led1, OUTPUT);
  pinMode(led2,OUTPUT);
}

void loop()
{
  while(Serial.available())
  {
    data == Serial.read();
    if(data == '1')
    {
      if(flag1 == 0)
      {
        digitalWrite(led1,HIGH);
        Serial.println("LED 1 is on");
        flag1 = 1;
      }
      else if(flag1 == 1)
      {
        digitalWrite(led1,LOW);
        Serial.println("LED 1 is off");
        flag1 = 0;
       }
    }
    if (data == '2')
    {
     if(flag2 == 0)
      {
        digitalWrite(led2,HIGH);
        Serial.println("LED 2 is on");
        flag2 = 1;
       }
       else if(flag2 == 1)
       {
         digitalWrite(led2, LOW);
         Serial.println("LED 2 is off");
         flag2 = 0;
        }
      }
    }
 }
  • Once you have written the code compile it and before you upload you first have to do one thing. Remove the connection to TX & RX pins of arduino. When you have removed the pins upload the code to arduino and you are ready to go.
  • But before you reconnect the pins. Open the Serial monitor of arduino IDE and enter 1 and you should see the LED turn on similarly entering 2 will turn on second LED and entering the same numbers will turn the LEDs off.

After this is done we move on to connect our setup with Smartphone.

Downloads

Connecting Smartphone :-

Screenshot_Serial_Bluetooth_Terminal_20180514-190700.png
Screenshot_Settings_20180514-190722.png
Screenshot_Serial_Bluetooth_Terminal_20180514-190731.png
Screenshot_Serial_Bluetooth_Terminal_20180514-190759.png
Screenshot_Serial_Bluetooth_Terminal_20180514-190809.png
Screenshot_Serial_Bluetooth_Terminal_20180514-191002.png
  • After connection is established long press the 'M1' to assign it a value. Assign 'M1' = 1 and 'M2' = 2.
  • Now power up the arduino and clicking M1 will turn on a LED and clicking again will turn it off, Same with M2.

That's all now you know how to control LEDs with Arduino through Bluetooth. Now you can tinker around to control your own projects.

If you have any questions or face any difficulty feel free to ask.

In next tutorial , I will share how you can make Bluetooth controlled car/bot. Follow me to get notified.