Arduino and Bluetooth HC-06 to Control the LED with Android Device

Hi everyone, In this project i will show you how to control LED light with your Android device along with Arduino. I am using Hc-06 bluetooth module for arduino to communicate with the android device.

To make this prototype I am using:

  1. Arduino Uno
  2. Hc-06 Bluetooth module
  3. 2pcs 10k ohm Resistor
  4. One Red LED
  5. Breadboard
  6. Jumper wire
  7. And my Nexus 5 🙂

Here is the Arduino Bluetooth updated version 1.1.0 of Android App.

Arduino-bluetooth-app-android

Purchase products to support us

 


Here is the video tutorial

Subscribe to our channel to get cool projects!

 

Circuit Diagram of Arduino bluetooth project.

Circuit Diagram

Arduino Bluetooth Code.

#include <SoftwareSerial.h>

int bluetoothTx = 2;  // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3;  // RX-I pin of bluetooth mate, Arduino D3

int led = 13;

int buttonPin1 = 7;
int buttonPin2 = 8;
int button1State = 0;
int button2State = 0;

int dataFromBt;

boolean lightBlink = false;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  Serial.begin(9600);  // Begin the serial monitor at 9600bps

  bluetooth.begin(115200);  // The Bluetooth Mate defaults to 115200bps
  bluetooth.print("$");  // Print three times individually
  bluetooth.print("$");
  bluetooth.print("$");  // Enter command mode
  delay(100);  // Short delay, wait for the Mate to send back CMD
  bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600, no parity
  // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
  bluetooth.begin(9600);  // Start bluetooth serial at 9600
  pinMode(led, OUTPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
}

void loop()
{

  if (bluetooth.available()) // If the bluetooth sent any characters
  {
    // Send any characters the bluetooth prints to the serial monitor

    Serial.println((char)bluetooth.read());
    dataFromBt = bluetooth.read();

    //Serial.println(dataFromBt);
    if (dataFromBt == '1') {
      Serial.println("led on");
      digitalWrite(led, HIGH);
      bluetooth.print("1");
    }
    if (dataFromBt == '0') {
      Serial.println("led off");
      digitalWrite(led, LOW);
      bluetooth.print("0");
    }
    if (dataFromBt == 'b') {
      Serial.println("a");
      lightBlink = true;
    } else {
      lightBlink = false;
    }

  }

  if (Serial.available()) // If stuff was typed in the serial monitor
  {
    // Send any characters the Serial monitor prints to the bluetooth
    //String myStr = (String)Serial.read();
    //char myStr1[] = "hello this is testing!";

   // uint8_t payload[myStr.length() + 1];
    //    myStr.getBytes(payload, myStr.length()+1);

    int bytes=Serial.available();
    //Serial.readBytes(buffer, startPosition, bytes);

    bluetooth.print((char)Serial.read());

  }

  // and loop forever and ever!
  if (lightBlink) {
    digitalWrite(led, HIGH);
    bluetooth.print("1");
    Serial.println("HIGH");
    delay(500);
    digitalWrite(led, LOW);
    bluetooth.print("0");
    Serial.println("LOW");
    delay(500);
  }

  //------arduino push button code----------------

  button1State = digitalRead(buttonPin1);
  button2State = digitalRead(buttonPin2);
  if (button1State == HIGH) {
    digitalWrite(led, HIGH);
    bluetooth.print("1");
    Serial.println("on");

  }
  if (button2State == HIGH) {
    digitalWrite(led, LOW);
    Serial.println("off");
    bluetooth.print("0");
  }
}

Related Post

30 Comments
  1. Ed 2 years ago

    Very nice.. What is the download URL for the Android tablet app.

    Thanks

  2. Rakesh kr. Ranjan 2 years ago

    please give me apps name so that I can download from google play

  3. Tarang 2 years ago

    plz give me google app link or source code..

  4. vinod 2 years ago

    Very nice,
    please give me apps name so that I can download from google play

  5. Vinod 2 years ago

    Please send android app name or URL so that I can check.

  6. Jawad 2 years ago

    how to do the same thing with Arduino Ethernet shield

  7. Michal 2 years ago

    Hi mate any chance you can tell me what is that app name so I can download it please ?

  8. ailton 2 years ago

    Please send this application to me or at least his name … like more .. I will be grateful

  9. tripoli post 2 years ago

    very nice and gooooooooood
    pleeeeez how to make app pleeeeeez video

  10. arogya reddy g 2 years ago

    Dear friend,

    can you give us the android code please

    thanks in advance.

  11. Feri 2 years ago

    Very interesting, but how they are using the buttons? How change the button state?

  12. libyan oby 2 years ago

    Minus code. what abut push button

  13. arogya reddy 2 years ago

    very nice project,

    how can we develop android studio code for this app?
    can you please explain the steps to develop this app in android studio.

    thanks in advance.

  14. arogya reddy 2 years ago

    dear friend,

    please give me the android studio code for this app,

    my email id is: regs1613@gmail.com

    thanks in advance.

  15. Gribate 2 years ago

    Its very interesting but there is some buttons code missing

  16. arogya reddy 2 years ago

    can i buy android studio code for this project?

  17. ankita 2 years ago

    please give the android code for this app

  18. Neethan 2 years ago

    Could you send me the Android code for the app please ??

    • poorna 1 year ago

      if you get the code pls give it to me pls

  19. Romualdo 1 year ago

    The HC-06 RX and TX pins work in 3V3 logic level but you didn’t use any logic level converter or even (recommended) a voltage divider (not recommended but it’s ok), why???

  20. ScottieD369 1 year ago

    Hi there I really like this app you use to control it.
    Would you please have the source code available?
    I need help!

  21. Amir 1 year ago

    can anybody help me? I want to make bluetooth controlled 1 ch relay..can anybody give me the code..i have tried to modify the code but it did’n works

  22. Nitya 1 year ago

    I downloaded the app from google store. But when I’m trying to connect it with bluetooth module, it’s responding ‘connection error’. The application is unable to connect with any other devices via bluetooth. Can you please help us how to make that connection.

  23. aldemir 1 year ago

    Adorei o programa mas não consegui fazer o led acender acionando o botão. O restante tudo funcionou

  24. poorna 1 year ago

    can i have the software serial.h Library link or soft copy to my mail pls pls pls pls pls pls pls pls pls pls pls pls pls pls pls pls pls pls pls pls

    and my mail is “purnachandra468@gmail.com” pls,,,,,,,,,,……………,,,,,,,,,,,,,,,,.

  25. Hello world! 5 months ago

    https://goo.gl/rwLB3k

    Link for the app

  26. Harry 2 months ago

    Can someone help me please? I can’t control the arduino from my phone, just I can see if it’s on or off, but i can’t send any order from my phone, can you help me please? it’s very important for me to learn it, like and suscribed, thanks

  27. tony 1 month ago

    scusate ma a me non funziona con il bluetooth non riesco a comandare led
    con interruttori si

  28. Profile photo of Stark
    Stark 1 month ago

    Ciao io sono nuovo e da poco che adopero arduino
    ho provato questo progetto con i pulsanti il led si accende e si spegne
    con il bluetooth mando sul monitor uno zero ma il led non si accende
    spero mi potete aiutare il progetto e molto bella e utilissimo

    grazie
    tonino

Leave a reply

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

*

or

Log in with your credentials

or    

Forgot your details?

or

Create Account