LED Control Using Arduino Bluetooth and Android. (Part 1)

73,149

60

11

Intro: LED Control Using Arduino Bluetooth and Android. (Part 1)

This instructable is a simple tutorial explaning how to control one LED using Android’s Bluetooth.

You will need:

  • Arduino UNO
  • Resistors 300Ω (3x)
  • Resistor 150Ω
  • LED
  • Jumpers;
  • Bluetooth Module (HC-06/other);
  • Android Phone;
  • SPP Bluetooth Apk (unWired Lite);
  • C programming skills

Step 1: HC-06 and Arduino

Bluetooth is a type of wireless communication used to transmit voice and data at high speeds using waves of radio. It’s widely used in mobile phones for making calls, headset and share data. This type of communication is a cheap and easy way to control something remotely using arduino.

HC-06 module has 4 pins to be connected to arduino, they are:

  • RXD
  • TXD
  • VCC
  • GND

RXD will receive data from arduino; TXD will send data to arduino; VCC is the power supply (3.3V 6.6V) and GND is the ground.

You gotta pay attention about the RXD level, some modules work with 5V, but this one works with 3.3V, and arduino TX will send a 5V signal, then it needs a voltage divider.

Voltage divider with R1 = 300Ω:

Vout = R2/(R2+R1) * Vin

3.3 = R2/(R2+300) * 5

3.3*R2 + 990 = 5*R2

R2 = 990/1.7

R2 ~ 600Ω

If you have a different resistor:

R2 = (3.3 * R1)/1.7Ω

Setting up:

1ª Connect the HC-06 module (See Pict.):

Arduino-------------HC-06

RX-------------------TXD

TX-------------------RXD

+5V-----------------VCC

GND----------------GND

2ª C code:

The sketch for this Project is very simple, all you have to do is check the serial port if there’s data available.

Using an android phone with a spp bluetooth apk, the command is sent to bluetooth (RX/TX). What happens is the bluetooth module communicates with android's bluetooth using a profile called SPP (Serial Port Profile). It emulates a USB Port connected to arduino and android.

Define all the pins and variables.

char command;
String string;
#define led 8

The default baud rate of HC-06 module is 9600. The void setup code:

  void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
}

Void loop:

void loop()
{ if (Serial.available() > 0)
{string = "";} while(Serial.available() > 0)
{ command = ((byte)Serial.read());
if(command == ':')
{
break;
}
else {
string += command;
}
delay(1);
}
if(string == "LO")
{
LEDOn();
}
if(string =="LF")
{
LEDOff();
}
}

There are two functions in the code. Actually their names says everything.

    void LEDOn()
{
digitalWrite(led, HIGH);
}
void LEDOff()
{
digitalWrite(led, LOW);
}

Step 2: UnWired Lite and Pro

unWired is an spp aplication that connects to arduino’s bluetooth modules and plot realtime data. You can try this one or other you’ve already known.

unWired Lite

unWired Pro

Before running the apk, pair the bluetooth module.

The first screen of the apk is shown in Pict. 01, click at ‘Paired Devices’. It’ll list all the paired devices, then you selected the bluetooth module you’ve paired before.

The second screen (Pict. 02) is where you write the commands to send to bluetooth. The commands are LO for Led On, and LF for Led Off.

You can download unWired Pro if you want to plot realtime data.

Done!

Now you know how to set up bluetooth modules to arduino and send commands to it.

You can also acquire data with the spp bluetoot apk, all you have to do is change the functions.

The next tutorial is:

LED Control using Arduino Bluetooth and Android. (Part 2) - Making An Android Application

Share

    Recommendations

    • Optics Contest

      Optics Contest
    • Electronics Tips & Tricks Challenge

      Electronics Tips & Tricks Challenge
    • Plastics Contest

      Plastics Contest

    11 Discussions

    0
    None
    ClareM30anjeloc

    Reply 1 year ago

    I was wondering the same thing! did you get it working with the AT09?

    0
    None
    IrwandaF

    1 year ago

    it can't work with HC 05 :(. Please help me.

    0
    None
    IrwandaF

    1 year ago

    it can't work with HC 05 :(. Please help me.

    0
    None
    sayedur26

    2 years ago

    Is this works with Bluetooth Module (HC-05) ?

    I mean, can I use HC-05 instead HC-06 ?

    4 replies
    0
    None
    Deysonsayedur26

    Reply 2 years ago

    Hi. Yes, you can use HC-05, but you need to set it as a slave.

    0
    None
    pvelazquez gomezliverpoolfan

    Reply 2 years ago

    It´s already set as a slave, HC-05 can be slave or master but HC-06 only can be salve

    0
    None
    SrujanR2

    2 years ago

    can u pleasesend the code for 4 leds

    0
    None
    Dhinadhinesh

    2 years ago

    I am getting avrdude sync error while uploading. Can you help me?