Lesson 6

Lesson 6 modules are ADVANCED subjects and may be too difficult for Arduino beginners!

>> Jump to: Compass Module (ADVANCED)
>> Jump to: Bluetooth Module (ADVANCED)
>> Jump to: Bluetooth Controller Software
>> Jump to: Bluetooth Module Commands
The information contained within Lesson 6 is extremely advanced. Most teams may not have the skills to implement the compass or Bluetooth modules. Even still, they have been included in each RoboGames "official kit" to prove us wrong and show us your mad-skillz. Be awesome, level-up!

Compass Module (ADVANCED) Back to Top

Using the HMC5883L Three-Axis Electronic Compass (ADVANCED)

You will need the following Arduino Libraries in order to compile the code.
Ensure this module is mounted flat, otherwise it may provide incorrect readings

This code example will show your heading... "0" being North, values will increase to 360 degrees, such as: East(90), South(180), West(270).
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>


Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345); //COMPASS I2C

void setup() {
  Serial.begin(9600); //SERIAL MONITOR
  mag.begin(); //COMPASS
  sensor_t sensor; //COMPASS
  mag.getSensor(&sensor); //COMPASS

void loop() {
  sensors_event_t event;
  float heading = atan2(event.magnetic.y, event.magnetic.x);
  float declinationAngle = 0.22;
  heading += declinationAngle;
  if(heading < 0) heading += 2*PI;
  if(heading > 2*PI) heading -= 2*PI;
  float headingDegrees = heading * 180/M_PI;

Bluetooth Module (ADVANCED)Back to Top

Using the Bluetooth HC-05 / HM-10 Transceiver (ADVANCED)

Bluetooth is considered an ADVANCED Arduino module and will require further assistance for most teams. There is two modules available, one type, "HC-05" is included by default in each kit and should work with both Android and computers. If you are attempting Bluetooth on an IOS device, email help@robogames.ca to arrange for the alternative "HM-10" module to be delivered when Brad visits for onsite training. It is expected that most teams will have difficulty with the Bluetooth modules, so if you have trouble, move onto using other sensors instead.

Connecting the Bluetooth module:TX to RX, RX to TX

To make a link between your Arduino and bluetooth , do the following :

Ensure Bluetooth is TURNED ON.

Search for the new Bluetooth device, our module will appear as "HC-05", "HM-10", "HMSoft" or possibly "Unknown".

Add the device.

Default Pairing Code (aka. Password) is: blank, "1234" or "0000"

After make a pairing, we can now program the Arduino and upload a sketch to send or receive data from Computer.

*** If you can connect to the Bluetooth, but nothing happens on the Arduino when you send a command, you may have the RX/TX pins backwards.You need to connect RX on the Bluetooth module to TX on the Arduino. And TX on the Bluetooth module to RX on the Arduino.

This code example will turn on the built-in pin 13 LED when you send "on" or "off" with a Bluetooth connected program.
This code example does not require any special drivers.
String readString;

void setup() {
  pinMode(13, OUTPUT);

void loop() {
  while (Serial.available()) {
    char c = Serial.read();
    readString += c;
  if (readString.length() >0) {
    if (readString == "on")    
      digitalWrite(13, HIGH);
    if (readString == "off")
      digitalWrite(13, LOW);

Bluetooth Controller SoftwareBack to Top

USB Dongle Help

When you insert the Bluetooth dongle into the USB port of your PC, Windows will install the necessary drivers automatically. When it's done, it will display a system message stating the installation was a success.

You will then see the Bluetooth icon in your system tray or on your desktop. Click on it to see a menu with a number of options such as Show Bluetooth Devices. Click on it and follow the slides.

Select Add Devices or Show Bluetooth Devices.

If your Arduino Bluetooth serial transceiver is wired properly, your device name should show up on the list. Click on it and then click Next.

You will be prompted to enter your Bluetooth devices' pairing code/password. The default for most Bluetooth devices is either 1234 or 0000.  Click Next.

If the pairing is successful, you will see a system message saying so.

Now, both your PC's Bluetooth and the Arduino's Bluetooth are connected as if by serial cable.

Run Tera Term on your PC (or any similar terminal emulator) and select the COM port number specified by the pairing.

Bluetooth Module CommandsBack to Top

This is the AT commands to customize the Bluetooth module

Upload a "blank" sketch to your Arduino.
void setup() {


void loop() {


Hold down the RESET button on the Bluetooth module. This will bring it into "command mode".
The Bluetooth RESET button must be held down while it is unpowered, still pressing it while you hook up power to it essentially.

While holding the "RESET", open the Arduino Serial Monitor and the light on the module should blink steadily.

If your module does not have a reset button, you will have to apply power to the STATE pin on the Bluetooth module to enter the command mode instead.
Ensure it is set to 38,400 baud.

Make sure to use:
Both NL and CR option in Serial Monitor.

Check if the device is responding by using the "AT" command, it should return with "OK"

Querying the Name

Setting the Name

Querying the Password

Setting the Password

Complete List of AT Commands

"AT Commands" used by HC-05, HC-06, HM-10 and most of other Bluetooth Devices

ATTest UART Connection
AT+RESETReset Device
AT+VERSIONQuery firmware version
AT+ORGLRestore settings to Factory Defaults
AT+ADDRQuery Device Bluetooth Address
AT+NAMEQuery/Set Device Name
AT+RNAMEQuery Remote Bluetooth Device Name
AT+ROLEQuery/Set Device Role
AT+CLASSQuery/Set Class of Device CoD
AT+IACQuery/Set Inquire Access Code
AT+INQMQuery/Set Inquire Access Mode
AT+PSWDQuery/Set Pairing Passkey
AT+UARTQuery/Set UART parameter
AT+CMODEQuery/Set Connection Mode
AT+BINDQuery/Set Binding Bluetooth Address
AT+POLARQuery/Set LED Output Polarity
AT+PIOSet/Reset a User I/O pin
AT+MPIOSet/Reset multiple User I/O pin
AT+MPIO?Query User I/O pin
AT+IPSCANQuery/Set Scanning Parameters
AT+SNIFFQuery/Set SNIFF Energy Savings Parameters
AT+SENMQuery/Set Security & Encryption Modes
AT+RMSADDelete Authenticated Device from List
AT+FSADFind Device from Authenticated Device List
AT+ADCNQuery Total Number of Device from Authenticated Device List
AT+MRADQuery Most Recently Used Authenticated Device
AT+STATEQuery Current Status of the Device
AT+INITInitialize SPP Profile
AT+INQQuery Nearby Discoverable Devices
AT+INQCCancel Search for Discoverable Devices
AT+PAIRDevice Pairing
AT+LINKConnect to a Remote Device
AT+DISCDisconnect from a Remote Device
AT+ENSNIFFEnter Energy Saving mode
AT+EXSNIFFExit Energy Saving mode