Arduino Bluetooth Basic Tutorial

Ever thought of controlling any electronic devices with your smartphone? Controlling your robot or any other devices with your smartphone will be really cool. Here is a simple and basic tutorial for interfacing Bluetooth with Arduino

Things you need

Hardware

  1. Bluetooth Module HC 05/06
  2. Arduino
  3. LED
  4. 220Ω Resistor
  5. Android device
    Thing u need

Software

  1. Arduino IDE
  2. Android Studio (Not Really required I will  provide the android application :D)

Watch how does it work?

Watch the video tutorial

 

good

Let’s Start Building

The circuit is so simple and small, there is only few connections to be made

Arduino Pins           Bluetooth Pins

RX (Pin 0)     ———->      TX
TX (Pin 1)     ———->      RX
5V             ———->      VCC
GND            ———->      GND

Connect a LED negative to GND of Arduino and positive to pin 13 with a resistance valued between 220Ω – 1KΩ. And you are done with the circuit

Note: Don’t  Connect RX to RX and TX to TX of Bluetooth to Arduino
you will receive no data, Here TX means Transmit and RX means Receive

hc-05-LED blink Circuit

Upload the Code

/*
* Bluetooh Basic: LED ON OFF - Avishkar
* Coder - Mayoogh Girish
* Website - http://bit.do/Avishkar
* Download the App : https://github.com/Mayoogh/Arduino-Bluetooth-Basic
* This program lets you to control a LED on pin 13 of arduino using a bluetooth module
*/
char data = 0; //Variable for storing received data
void setup()
{
    Serial.begin(9600); //Sets the baud for serial data transmission                               
    pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
}
void loop()
{
   if(Serial.available() > 0)  // Send data only when you receive data:
   {
      data = Serial.read();        //Read the  incoming  data and store it into variable data
      Serial.print(data);          //Print Value inside data in Serial monitor
      if(data == '1')              // Checks whether value of data is equal to 1
         digitalWrite(13, HIGH);   //If value is 1 then LED turns ON
      else if(data == '0')         //  Checks  whether value of data is equal to 0
         digitalWrite(13, LOW);    //If value is 0 then LED turns OFF
   }
}

How Does it Work??

HC 05/06 works on serial communication.here the android app is designed sending serial data to the Bluetooth module when a certain button is pressed. The Bluetooth module at other end receives the data and send to ardunio through the TX pin of the Bluetooth module(RX pin of Arduino). The Code fed to Arduino check the received data and compares.
If received data is 1 the LED turns on turns OFF when received data is 0

Open the serial monitor and watch the received data

Serial1Serial2

Android Application

In this tutorial, I will not be covering tutorial on android app development. You can download the android application from here and the source code of the entire projectandroid-logo

How to use the app?

Watch in the video how to pair to the Bluetooth module

  • Download the Application from here or here
  • Pair your device with HC 05/06 Bluetooth module
    1) Turn ON HC 05/06 Bluetooth module
    2)Scan for available device
    3)Pair to HC 05/06 by entering default password 1234 OR 0000
  • Install  LED application on your android device
  • Open the Application
    Splash
  • Press paired devices
  • Select your Bluetooth module from the List (HC 05/06)paired deviceavaiable device
  • After connecting successfully
  • Press ON button to turn ON LED and OFF button to turn OFF LED
    LEDAbout
  • Disconnect button to disconnect from the Bluetooth module

 

This is just a basic tutorial on interfacing Bluetooth  module with Arduino
This project can be improved to a higher level like Home automation using a smartphone, Smartphone controlled robot and much more

 

Subscribe to blog for newsletters and like my facebook page for receiving new post notification

42 thoughts on “Arduino Bluetooth Basic Tutorial

  1. hi I have 1 problem . I cant upload the code it a message like this :

    Arduino: 1.6.13 (Windows 10), Board: “Arduino/Genuino Uno”

    Sketch uses 1,756 bytes (5%) of program storage space. Maximum is 32,256 bytes.
    Global variables use 187 bytes (9%) of dynamic memory, leaving 1,861 bytes for local variables. Maximum is 2,048 bytes.
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x99
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x99
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x99
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x99
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x99
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x99
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x99
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x99
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x99
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x99
    Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

  2. Hi,

    Could you also publish your Android code? I want to do a similar application and your app would be a good starting point.

    Thanks!

  3. When I push the “ON” and “OFF” buttons using your app, I see the character “ÿ” in the serial monitor screen. I’ve tried a couple other apps and still get that same character when using the buttons. Any ideas? I’m using an Arduino Uno and an iteadstudios bluetooth module v2.2 alongside a Galaxy S7 for app.

  4. First of all, thanks so much Mayoogh, this was super helpful. For expanding this, do you know how to connect multiple HC-05s to a single Android?

    1. It’s a very nice project……also it run successfully……but it will be great if you tell us how to control more than one led….. waiting for your reply…..

  5. I have a problem. When i try to switch the led on by my phone i have short blink on TX led and RX led and thats all, but its okay when i try to switch the led on by monitor port.
    What’s wrong with it?

  6. I have a question how do you use the resistor in the video I can’t see where did you use the resistor. I have 220-ohm resistor where do i have to plug the resistor can you please help me.
    thankyou

  7. When I push the “ON” and “OFF” buttons using your app, I see the character “ÿ” in the serial monitor screen.
    I have tried many times..Even baud rate is also same 9600 in serial monitor and code. Could u please tell me what to do for?

  8. Hi, Thanks for the tutorial but I having problem.. I can get connected with hc-05 but arduino doesnt receiving and data

  9. Hi Mayoogh I can’t paired the bluetooth, I’m using a SH-BT-BOARD V1.3 bluetooth, Can you help me please? It’s a great project, and I’m learning with. Thank you

  10. Thanks Alot….
    Very Helpful For My Science Exhibition Project…..
    I used ur code to control my relays….
    Urs was d only website that had a HC-05 config that was absolutely right….

  11. Programming HC-06 is very easy. There are already a lot of Sample programs and projects in the Internet. Why didn’t you include the tutorial of the program? Isn’t it your program? In you Hackster.io post of this, you said the tutorial for the Android App can be found here. That is why I’m here to see the App program code so I can learn from it. Don’t you think its wise you Post it here? I expect you will. Regards.

  12. What I mean of the program is the Android App program that I expect you posted the code in here. It’s just disappointing I came from Hackster.io and found link there of this page just to find out the Android App tutorial is not Posted, only the user’s tutorial guide.

  13. Sorry i’m a french student and when i run your script this appear “Connection Failed. Is it a SPP Bluetooth? Try again”. What should i do?

Leave a Reply

Your email address will not be published. Required fields are marked *