Arduino Bluetooth Interfacing – Simplest tutorial on Bluetooth Basics

From our STAR Maker: Mayoogh Girish

arduino bluetooth

Ever thought of controlling any of your electronic devices with your smart phone? Your robot or any other device? Won’t it be cool to control them with your smartphone? Here is a simple and basic tutorial for interfacing an Android Smartphone with Arduino via Bluetooth. Arduino bluetooth Basic Tutorial!

What are the stuff required to do this project?

arduino bluetooth

Hardware

  1. Bluetooth Module HC 05/06
  2. Arduino & Battery (with cable)
  3. LED
  4. 220Ω Resistor
  5. Android device

Software

  1. Arduino IDE
  2. Android Studio.

 

The android studio is not really required here, since I will provide you with the android application I made. You can install the given .apk file to use the application. :)

How does it work?

There are three main parts to this project. An Android smartphone, a bluetooth transceiver and an Arduino.

arduino bluetooth

HC 05/06 works on serial communication. Here the android app is designed to send serial data to the arduino bluetooth module when a button is pressed on the app. The arduino bluetooth module at other end receives the data and sends it to the Ardunio through the TX pin of bluetooth module(connected to RX pin of Arduino). The code uploaded to Arduino checks the received data and compares. If received data is 1 the LED turns ON. And it turns OFF when received data is 0. You can open the serial monitor and watch the received data while connected.

STEP 1: Connecting the Arduino Bluetooth hardware

arduino bluetooth

The circuit is so simple and small. There are only four connections to be made between Arduino & Bluetooth module!!

Arduino Pins     Bluetooth Pins

RX (Pin 0)     ———>     TX

TX (Pin 1)     ———>      RX

5V                 ———>      VCC

GND             ———>      GND

Connect an LED positive to pin 13 of Arduino through a resistance(valued between 220Ω – 1KΩ). Connect its negative to GND. And you are done with the circuit! :)

arduino bluetooth

You can connect the Bluetooth module to the Arduino using a set of jumper wires and a connector.

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

STEP 2: Upload Sketch to Arduino

char data = 0;                //Variable for storing received data
void setup() 
{
  Serial.begin(9600);         //Sets the data rate in bits per second (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
    Serial.print("\n");        //New line 
    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
  }                            
 
}

Upload the given sketch to Arduino using the Arduino IDE software, you can also get it from here: Github

STEP3: Install the android application

arduino bluetooth

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

  • Download the Application from Amazon App Store or Github
  • Pair your device with HC 05/06 bluetooth module:
  • 1. Turn ON HC 05/06 bluetooth module by powering the Arduino.
  • 2. Scan smartphone for available devices.
  • 3. Pair to HC 05/06 by entering default password 1234 OR 0000.
  • Install LED application on your android device.
  • Open the Application

arduino bluetooth

  • Press paired devices
  • Select your Bluetooth module from the List (HC-05/06)

arduino bluetooth

  • After connecting successfully, press ON button to turn ON LED and OFF button to turn OFF LED.
  • Disconnect button to disconnect from bluetooth module.
arduino bluetooth

And here is how it works!!

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.

You can watch the video tutorial over here:


 

Mobile controlled robot

Mayoogh Girish – STAR Maker at DIY Hacking

-Submitted by Mayoogh Girish

A young maker from India and a huge Arduino fan.

Recommended Posts
Showing 14 comments
  • Dongksi
    Reply

    hi can I ask? is that possible that I will change the code “if(data == ‘1’) ” to if(data == ‘on’) ? do I have to change the source code of the app?

  • mohd azhan hj hashim
    Reply

    how to program coding for control 5 led using bluetooth…?

  • Mike
    Reply

    dont you need logic level shifter on RX pin on bluetooth from 5v to 3v?

    • mike
      Reply

      never mind, saw answer already.

  • Amit
    Reply

    Is it possible to connect the led to HC 05 PIO pin and control the same ping via mobile application ?

  • anas
    Reply

    Please guide me to send a data from arduino to phone

    • Mayoogh Girish
      Reply

      Bluetooth uses serial communication

      Serial.print(5);
      The above statement will send 5 from arduino

  • Alex Vasilas
    Reply

    Hello.
    I have a problem.
    I upload the script my arduino and I take out error.

    Arduino: 1.6.11 (Windows 7), Board: “Arduino/Genuino Uno”

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

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

    • Mayoogh Girish
      Reply

      Did you connected the TX RX pins of module to arduino board while uploading ? If so there is a chance of error , try after removing the connection to TX RX pins

  • Zernan Hernandez
    Reply

    please provide code of the android application.
    I really want to know how to send data and communicate from android to arduino.

  • sheshan kumar
    Reply

    How to create code and upload code in arduino for bluetooth interface please provide a video.

  • Amal Shajan
    Reply

    Sholud have used an voltage divider biasing to conver 5v arduino logic to 3.3v. It is more auitable for HC 05.

    • Spartan Velanjeri
      Reply

      AmalShajan

      Voltage divider biasing need not be required for small projects like this. However it may be needed when you are transmitting and receiving large amount of data

Leave a Comment

50 + = 54

Start typing and press Enter to search