HC-05 Bluetooth Module Interfacing with MSP-EXP430G2 TI Launchpad
Introduction

HC-05 is a Bluetooth device used for wireless communication with Bluetooth enabled devices (like smartphone). It communicates with microcontrollers using serial communication (USART).
Default settings of HC-05 Bluetooth module can be changed using certain AT commands.
As HC-05 Bluetooth module has 3.3 V level for RX/TX and the microcontroller can detect 3.3 V level, so, there is no need to shift TX voltage level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module.
For more information about HC-05 Bluetooth module and how to use it, refer the topic HC-05 Bluetooth module in the sensors and modules section.
Interfacing Diagram

Interfacing HC-05 Bluetooth Module with MSP-EXP430G2 TI Launchpad
Note : For the TI Launchpad board, P1.1 is the Rx pin and P1.2 is the Tx pin when the jumpers are positioned for using Hardware Serial. Here, we are using, Hardware Serial, hence P1.1 is the Rx pin and P1.2 is the Tx pin.
When jumpers are positioned for software serial, P1.1 acts as the Tx pin and P1.2 acts as the Rx pin.
Note : Default Bluetooth name of the device is “HC-05” and default PIN (password) for connection is either “0000” or “1234”.
Example
Here, we will transmit data from Smartphone via Bluetooth to the MSP-EXP430G2 TI Launchpad. If data received is 1, LED is turned ON and a message is sent to Smartphone. If data received is 0, LED is turned OFF and a message is sent to Smartphone. If any other data is received, a message is sent asking the user to send either 1 or 0.
Download and install a Bluetooth terminal application on your phone and use it to connect to the HC-05 Bluetooth module.
Data is sent from the Smartphone using the Bluetooth terminal application.
Note : Make sure that \r and \n are not sent along with data sent by deselecting the \r and \n options in the settings of Bluetooth terminal. If \r and/or \n are sent along with 1/2, you will get Select Proper Option output along with LED ON/OFF on the terminal.
Tread Carefully : MSP-EXP430G2 TI Launchpad board has a RAM of 512 bytes which is easily filled, especially while using different libraries. There are times when you need the Serial buffer to be large enough to contain the data you want and you will have to modify the buffer size for the Serial library. While doing such things, we must ensure that the code does not utilize more than 70% RAM. This could lead to the code working in an erratic manner, working well at times and failing miserably at others.
There are times when the RAM usage may exceed 70% and the codes will work absolutely fine, and times when the code will not work even when the RAM usage is 65%.
In such cases, a bit of trial and error with the buffer size and/or variables may be necessary.
Sketch
void setup() {
Serial.begin(9600); /* Define baud rate for serial communication */
pinMode(12, OUTPUT);
}
void loop() {
if (Serial.available()) /* If data is available on serial port */
{
char data_received;
data_received = Serial.read(); /* Data received from bluetooth */
if (data_received == '1')
{
digitalWrite(12, HIGH);
Serial.write("LED turned ON");
}
else if (data_received == '2')
{
digitalWrite(12, LOW);
Serial.write("LED turned OFF");
}
else
{
Serial.write("Select either 1 or 2");
}
}
}
No comments:
Post a Comment