Lesson 22: Check Bluetooth MAC Address


Written by Jonathan Sim

You can find this lesson and more in the Arduino IDE (File -> Examples -> Andee). If you are unable to find them, you will need to install the Andee Library for Arduino IDE.

Works on iOS and Android
If you want to create applications that will either shut out unauthorised users or just display different user interfaces to different sets of users, one way to do this involves filtering users by their smartphone Bluetooth MAC address.

A MAC address is a hardware address that is unique to each and every Bluetooth device.

In this lesson, I'll show you how to retrieve the MAC address of the connected smartphone and display it on the screen, like this:



Top of the Code

#include <SPI.h>
#include <Andee.h>

// We'll use a display box to show the current MAC address
AndeeHelper displaybox;

char strBuffer[30]; // String to store the retrieved Bluetooth info
char current_mac_id[18]; // String to store the extracted MAC address


void setup()
  Andee.begin();  // Setup communication between Annikken Andee and Arduino
  Andee.clear();  // Clear the screen of any previous displays
  setInitialData(); // Define object types and their appearance


void setInitialData()
  displaybox.setTitle("Connected MAC Address");


void loop()
  if( Andee.isConnected() ) // Do this only when Andee is connected
    // Send command to the Andee to get some Bluetooth device information
    // and store it in the string buffer
    Andee.sendCommand("GET CONNECTED MAC_ID", strBuffer);
    // As the retrieved information contains more than just the MAC address,
    // we'll need to extract the MAC address and store it in another string
    strncpy(current_mac_id, strBuffer, 17); // Extract MAC address
  delay(500); // Always leave a short delay for Bluetooth communication
comments powered by Disqus