Arduino Bluetooth Basic Tutorial

Ever thought of controlling any electronic devices with your smart phone ?Controlling your robot or any other devices with your smartphone will be really cool. Here is 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 works ?

Watch the video tutorial

 

good

Let’s Start Building

The circuit is so simple and small , there is only few connection 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 your 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 Works ??

HC 05/06 works on serial communication.here the android app is designed sending serial data to the bluetooth module when certain button is pressed.The Bluetooth module at other end receive the data and send to ardunio through the TX pin of 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 video how to pair to 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 bluetooth module

 

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

 

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

Advertisements

20 Comments Add yours

  1. job tielens says:

    nice project, and works well after changing the baudrate, “thanks” the BLUETOOTH connection, will give it a try for the lamp

    Like

  2. Chandra says:

    Nice project.Well explained!. It is working for me
    Thank you,
    C.

    Like

  3. fidan says:

    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.

    Like

    1. Remove the connection on the TX RX pin of arduino, and try uploading the sketch

      Like

  4. Lucas says:

    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!

    Like

  5. Ricky says:

    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.

    Like

    1. Check the baud rate of serial monitor. Check whether it is 9600

      Like

      1. Ricky says:

        The baud rate in the code and the serial monitor are both set to 9600.

        Like

  6. Thomas says:

    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?

    Like

    1. Yes you can use multiple serial communication.
      Look for SoftwareSerial Library

      Like

      1. Thomas says:

        Will do, thank you!

        Like

  7. Jerry Hanna says:

    Great tutorial!
    Would it be possible for a tutorial on writing the Android app?

    Like

  8. Dmitry says:

    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?

    Like

  9. Milad says:

    are you planning on doing it? My phone wont let me install the apk because of security..

    Like

    1. Yes , I will do it

      Like

    2. You can turn on the Unknown source option in security settings

      Settings>Security>Unknown source
      Allow installation of app from unknown source

      Like

  10. Milad says:

    Hi, any chance of getting the app from google play store??

    Like

    1. Sorry I haven’t uploaded in play store till now

      Like

  11. Harshil Patel says:

    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

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s