Transmission within the car - HC-05 & HC-06 FC114 (Bluetooth module)

Week 3 & Week 4

We were tasked to work on the transmission of sensor data within the car with the Bluetooth module, HC-06 FC114, hence eliminating the need of using wiring.
We are tasked to use the HC-05 FC-114 (master), and HC-06 FC-114(slave) Bluetooth module and pair them up to allow the communication of Arduino through Bluetooth transmission. 

http://www.martyncurrey.com/connecting-2-arduinos-by-bluetooth-using-a-hc-05-and-a-hc-06-pair-bind-and-link/


Figure 1: HC-06 FC-114 Bluetooth Modules


The HC-05 module can be used to be set as either the master or the slave, while the HC-06 module can only be set as the slave module. In this case, we will be using the HC-05 as the master and the HC-06 as the slave. To do so, pairing and linking of the modules' required. It is so that the modules will connect to each other automatically when powered up. To do so, the modules first have to be powered up and connected correctly. In this case, we are using the Soft.Serial instead of Hard.Serial (Pin 0/1 of Arduino Leonardo/Uno).


To enter the AT mode of the HC-05 and HC-06 modules, the following steps are to be followed:

HC-05

EN    > NC
VCC > 3.3v VCC
GND > GND
TX    > Pin 10 of Arduino Uno/Leonardo (Soft Rx)
RX    > Pin 11 of Arduino Uno/Leonardo (Soft Tx)
State  > NC

As the model of this module does not have the KEY pin, and has the EN pin instead, a manual connection of setting pin 34 to HIGH is required, in order to enter the AT mode. The module should be blinking 5 times consecutively per second, indicating that it is in the communication mode and looking for other Bluetooth device(s). After setting pin 34 to HIGH, re-connect the VCC pin and the LED should be blinking once every second, indicating that the module is in the AT mode. Finally, open the Serial.Monitor and select the baud rate of 9600 and "Both NL & CR". AT commands should then be able to function properly.

HC-06

Power up the module with the following connections, then open Serial.Monitor and the module should be in the AT mode.

EN    > NC
VCC > 3.3v VCC
GND > GND
TX    > Pin 10 of Arduino Uno/Leonardo (Soft Rx)
RX    > Pin 11 of Arduino Uno/Leonardo (Soft Tx)
State  > NC

Finally, open the Serial.Monitor and select the baud rate of 9600 and "No line ending". AT commands should then be able to function properly.


For both the Bluetooth modules, the baud rate and password/pin should be checked to make sure that they are the same as each other (HC-05 and HC-06).
After the connection has been set up, the code is then uploaded to the boards respectively.

HC-05 Code

///////////////////////////////////////////////////////////////////////////

#include ‹softwareserial.h›

SoftwareSerial Serial_One (10, 11); // RX, TX

void setup() 
{

Serial.begin(9600);
Serial.println("Enter AT commands:");

Serial_One.begin(9600);
Serial.println("Soft Serial 1 Started!");

//Serial_Two.begin(9600);
//Serial.println("Soft Serial 2 started!");

Serial.println("========================");
Serial.println();

Serial.println ("Temperature \t\tMotor 1 ");
Serial.println ("==============\t\t==========");

}

void loop()

{

if (Serial_One.available())
    {
    Serial.write(Serial_One.read());
    }
/*
if (Serial_Two.available())
    {
    Serial_Two.write(Serial.read());
    }
*/
if (Serial.available())
    {
    Serial_One.write(Serial.read());
    } 
}

////////////////////////////////////////////////////////////////////////

HC-06 Code

#include ‹SoftwareSerial.h›
SoftwareSerial BTSerial (10,11);                 //Rx | Tx
long randNumber_M1;                              // The variable which is supposed to hold the random number
double Raw_Value_T = 0;
 
void setup() 
{
    Serial.begin(9600);
    Serial.println("Arduino with HC-06 is ready");
 
    BTSerial.begin(9600);  
    Serial.println("BTserial started at 9600");

    Serial.println("=============================");

    randomSeed(analogRead(1));                     // Assigns random number from Motor 1 to pin A1
}
 
void loop()
{
  randNumber_M1 = random(1, 255);                // Generate a random number in place of Motor 1's pin 27

  Raw_Value_T = analogRead(A0);
  double Temp = (Raw_Value_T / 1023) * 500;
  
  //BTSerial.print("Temperature: ");
  //BTSerial.print(Temp); 
  //BTSerial.println(" degree celsius");

  //BTSerial.print("Raw pulse value from Motor 1: ");
  //BTSerial.println(randNumber_M1);

  //BTSerial.println ("Temperature \t\tMotor 1 ");
  //BTSerial.println ("==============\t\t==========");

  
  BTSerial.print (Temp); BTSerial.print(" degrees"); 
  BTSerial.print("\t\t");
  BTSerial.print (randNumber_M1); BTSerial.println(" pulses");
  BTSerial.println("==============\t\t==========");
  
  
  if (BTSerial.available())
      {
      Serial.write(BTSerial.read());
      }

  if (Serial.available())
      {
      BTSerial.write(Serial.read());
      }
  delay(1500);
}


After the code has been uploaded, the setting and pairing of the modules can be begin.

General commands

AT                                          // Checking if AT mode is activated
AT+VERSION                      // Checking AT version of module
AT+ADDR                            // Checking AT address of module
AT+NAMEHC-06                 // Change name to HC-06
AT+PSWD=1234                  // Changing password of HC-05 to 1234 (Must be 4 digits)
AT+PIN1234                         // Changing password of HC-06 to 1234 (Must be 4 digits)

HC-05 Master module commands

AT+RMAAD          //clears any previously paired devices.
AT+ROLE=1           //puts the HC-05 in Master Mode
AT+RESET             //reset the HC-05. This is sometimes needed after changing roles.

AT+CMODE=0      //allows the HC-05 to connect to any device
AT+INQM=0,5,9    //set inquiry to search for up to 5 devices for 9 seconds
AT+INIT //initiates the SPP profile.
                                //if SPP is already active you will get an error(17) which you can ignore.
AT+INQ                  //searches for other Bluetooth devices.


AT+RNAME? 3014,11,192230       // first part till comma, then change all the ' : ' to ' , '
AT+PAIR=3014,11,192230,9          // to pair within 9s, else error.
AT+BIND=3014,11,192230            // to bind

AT+CMODE=1                               // Set the HC-05 to only connect with paired devices.

AT+LINK=3014,11,192629            // Link to the HC-06 slave module.

* 3014,11,192629 = Address of HC-06, varies for diff modules.


After linking successfully, the modules should be linked up with each other, whereby the LED indication of each module will be changed. For the HC-05, the LED should be blinking twice consecutively every second, while for the HC-06, the LED should be fixed and not be blinking. If the LEDs of both modules are not blinking in this manner, VCC to both modules should be re-connected, and pin 34 (CMD) should be set to low again. The LEDs should then be blinking in the manner stated above.


Figure 1: Full AT command list of HC-05



Demonstration of HC-05/06 transmission

For the demonstration, the LM-35 is not connected, hence the values seen under Temperature are of wrong values and should be ignored. Part of the code generates a random number from 0-255 automatically from the slave module and automatically transmits to the master module, as seen under Motor 1, which is supposed to be a substitute of the PWM output from pin 27 of the motor controller.

Comments

Popular posts from this blog

Week 13 - Integration test - PLX-DAQ, Chase vehicle simulation, LoRa interface