top of page

Interfacing the HC-04 Bluetooth Module to the Arduino to Control a Led

In this tutorial, I'm going to show you how to Interface the Hc-04 Bluetooth module to the Arduino uno and switch on a led wirelessly.

ITEM REQUIRED

Jumper Wires

Bluetooth module HC-05

1 x Arduino board (I am using An Arduino Uno).

1 x USB cable

1 x Computer with Arduino software installed

1 x Breadboard

1 x Led

Android Application (Download link Below)



Circuit Theory:

The Hc-05 is a Bluetooth module that can be interfaced to the Arduino so that you can control different electronic circuits remotely. Using this technology you can control a robot,Lights from the comfort of your bed using your smartphone.


The Hc-05 contains 6pins namely the enable pin, Vcc,Ground, Tx Transmitter,Rx receiver and State pin.

The HC-05 is a module which can add two-way (full-duplex) wireless functionality to your projects. You can use this module to communicate between two microcontrollers like Arduino or communicate with any device with Bluetooth functionality like a Phone or Laptop. There are many android applications that are already available which makes this process a lot easier. The module communicates with the help of USART at 9600 baud rate hence it is easy to interface with any microcontroller that supports USART. We can also configure the default values of the module by using the command mode. So if you looking for a Wireless module that could transfer data from your computer or mobile phone to microcontroller or vice versa then this module might be the right choice for you.

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


Here are some Specifications of the board:


  • Serial Bluetooth module for Arduino and other microcontrollers

  • Operating Voltage: 4V to 6V (Typically +5V)

  • Operating Current: 30mA

  • Range: <100m

  • Works with Serial communication (USART) and TTL compatible

  • Follows IEEE 802.15.1 standardized protocol

  • Uses Frequency-Hopping Spread spectrum (FHSS)

  • Can operate in Master, Slave or Master/Slave mode

  • Can be easily interfaced with Laptop or Mobile phones with Bluetooth

  • Supported baud rate: 9600,19200,38400,57600,115200,230400,460800.

SETUP


Step 1:

Connect the circuit as per Circuit diagram



Hc-05 Interfaced to Arduino
Circuit Diagram


Assembled Circuit
Assembled Circuit

Step 2:

Open a new window in the arduino terminal and type the code.


 

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

}

}


 

Note:

Serial.available()- Get the number of bytes (characters) available for reading from the serial port. This is data that’s already arrived and stored in the serial receive buffer (which holds 64 bytes).


Step 3:

Connect the Arduino to your pc and upload the code to the Arduino board. Open your app Select the Hc-05 module from the list displayed on the screen. Now you can switch off and on the led using the buttons displayed on the screen as shown in the images below.


LED App
App Interface-1
LED App
App Interface-2


Here I have demonstrated how you can turn on a led using the app, this project can be extended by connecting a bulb or tube light by using an external circuitry.



Download the app here

253 views

Commentaires


bottom of page