Tutorial : HC-05 Bluetooth Module

Description:

The Bluetooth Module HC-05 is a very useful module for wireless project with low cost & with distance less than ~5 meter such as car control through phone connection. Although the module has a voltage regulator of 3.3V, the RX pin on bluetooth module recommended should be 3.3V by using a voltage divider to protect this bluetooth module and the communication will be more stable. Connect our circuit with an Arduino as the diagram below, we can use a module called AMS1117 3.3V to replace the voltage divider circuit.

Coding: 

#include <SoftwareSerial.h> 
SoftwareSerial bluetooth(2, 3); // RX | TX 
int command = 0; 
int LED = 8; 
void setup() 
{   
 Serial.begin(9600); 
 bluetooth.begin(9600); 
 pinMode(LED, OUTPUT); 
 Serial.println("Ready to connect\nDefualt password is 1234 or 000"); 
} 
void loop() 
{ 
 if (bluetooth.available()) 
   command = bluetooth.read(); 
 if (command == '1') 
 { 
   digitalWrite(LED, HIGH); 
   Serial.println("LED ON"); 
 } 
 else if (command == '0') 
 { 
   digitalWrite(LED, LOW); 
   Serial.println("LED OFF"); 
 } 
} 

Step:

  • Connect the circuit as diagram above, plug in the USB cable with Arduino &  laptop installed with ArduinoIDE.
  • Copy and paste the code in ArduinoIDE, make sure that the setting on ArduinoIDE is correct (Tools >> Board & Port) before uploading the code. If can't find the port, open the device manager to define the port. 
  • Take up the phone and open google play store, (this module is not compatible with IOS), search an application called Android RC, another compatible application can be used too in this project.
  • Install the application, launch it when done. 
  • Connect phone with bluetooth module, edit the command as the arduino's command (0 & 1). 
  • Then, begin the play. HAVE FUN!!!~ 

Note: If using China Version Arduino, install the CH340 driver for the problems on undefined port. 

Android Phone

  • Launch the application>> Click on Proceed and Select the HC-05 to connect. (Remember open your bluetooth connection first before launch the program)

  • Enter "1234" or "0000" to connect with Bluetooth Module, the module should not blink after connected unless there're a command send to this module. Then,go to "Controller Mode"

  • Press on "Set Commands" and edit the commands.

  • Edit your Commands as below then back to the Controller Mode. Click on the button that has been set and try to play and observe the LED.