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

Overview of Bluetooth

HC-05 Bluetooth Module
HC-05 Bluetooth Module

HC-05 is a Bluetooth device used for wireless communication with Bluetooth-enabled devices (like smartphones). It communicates with microcontrollers using serial communication (USART).

The default settings of the HC-05 Bluetooth module can be changed using certain AT commands.

As the HC-05 Bluetooth module has a 3.3 V level for RX/TX and the microcontroller can detect 3.3 V level, so, there is no need to shift the TX voltage level of the HC-05 module. But we need to shift the transmit voltage level from a microcontroller to RX of the HC-05 module.

For more information about the HC-05 Bluetooth module and how to use it, refer to the topic HC-05 Bluetooth module in the sensors and modules section.

 

Connection Diagram of HC-05 Bluetooth Module with MSP-EXP430G2 TI Launchpad

Interfacing HC-05 Bluetooth Module with MSP-EXP430G2 TI Launchpad
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 the default PIN (password) for connection is either “0000” or “1234”.

 

Send SMS using HC-05 Bluetooth Module with MSP-EXP430G2 TI Launchpad

Here, we will transmit data from a 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 the 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.

 

HC-05 Bluetooth Module Code for MSP-EXP430G2 TI Launchpad

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");
      }
    }
}

 

Video of HC-05 Bluetooth Communication using MSP-EXP430G2 TI Launchpad


Components Used

TI Launchpad MSP-EXP430G2
TI Launchpad MSP-EXP430G2
1
Bluetooth Module HC-05
Bluetooth is a wireless communication protocol used to communicate over short distances. It is used for low power, low cost wireless data transmission applications over 2.4 – 2.485 GHz (unlicensed) frequency band.
1

Downloads

Bluetooth_Interfacing_With_TI_Launchpad_INO Download
Ad