Introduction: Control Your Projects With Bluetooth Low Energy.
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...
Step 1: Gathering Components :-
Here I've listed all the components along with best buy links.
- Arduino UNO
Link for US
Link for Europe - Bluetooth Module (I've used AT-09. You can use HM-10/HC-05)
Link for US
Link for Europe - Breadboard. (I recommend you get this kit.)
Link for US
Link for Europe - LEDs.
Link for US
Link for Europe - 1k resistors. (Can be found in any local electronics store.)
Link for US
Link for Europe - Smart Phone ( with Bluetooth 4.0 or above.)
- 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
Step 2: Making Connections :-
- 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...
Step 3: Writing & Uploading Code :-
- 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.
Attachments
Step 4: Connecting Smartphone :-
- To connect the phone to Bluetooth first you need a Bluetooth Serial App. I've used Bluetooth Serial Terminal.
- 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.
5 Comments
4 years ago
Again, not BLE... just old classic serial bluetooth.
Reply 4 years ago
Go through this pdf, It might help you understand better
http://www.ti.com/lit/ds/symlink/cc2540.pdf
Reply 4 years ago
I understand and use BLE... I'm saying that your project is mis-labeled -- it is NOT BLE.
Question 4 years ago on Step 3
Hello
thanks for sharing that sketch, it worked well, i am trying to add outputs without much luck. I am trying to control a 8 channel relay bank, is that possible.
i added the following
int led1 = 4;
int led2 = 5;
int led3 = 6;
int led4 = 7;
int led5 = 8;
int led6 = 9;
int led7 = 10;
int led8 = 11;
then added the flags
int flag1 = 0;
int flag2 = 0;
int flag3 = 0;
int flag4 = 0;
int flag5 = 0;
int flag6 = 0;
int flag7 = 0;
int flag8 = 0;
then outputs
pinMode(led1,OUTPUT); //Set LED pins as output
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT); //Set LED pins as output
pinMode(led4,OUTPUT);
pinMode(led5,OUTPUT); //Set LED pins as output
pinMode(led6,OUTPUT);
pinMode(led7,OUTPUT); //Set LED pins as output
pinMode(led8,OUTPUT);
then i modified the second output command of your sketch
}
if(data == '3') //checks if data is '3'
{
if(flag3 == 0) //checks if flag is 0
{
digitalWrite(led3,HIGH); //if flag is 0 turns LED 3 on
Serial.println("LED 3 is on"); //prints on terminal
flag3 = 1; //sets flag to 1
}
else if(flag3 == 1) //checks if flag is 1
{
digitalWrite(led3,LOW); //if flag is 1 turns LED 3 off
Serial.println("LED 3 is off");
flag3 = 0; //sets flag to 0
}
}
}
}}
are you able to help at all
Regards
Answer 4 years ago
It should work, if you are facing any errors , please share the screen shot.