Mechatronics Exercises

Workspace Navigation

Bluetooth background communication based actuating system

We are implementing an actuating system that is based on bluetooth background communication.


  1. Aim of the project
    The aim of our project is to create a device which utilises mobile background communication protocols, bluetooth in our case, for device identification and data collection. Depending on the detected device our receiver might then be told to do various actions. For example, when a specific device is identified in the module’s receiving range, an actuator can be employed to turn on a light. This kind of device can be derived for a wide variety of applications. The key is that you don't have to be paired with the bluetooth module in order to it detecting you, you can just keep your phone in your pocket, enter the bluetooth modules range, and the module will detect your phone.

  2. First steps and materials 

    This project will be done using a mobile phone and an Arduino, in which a HC-05 Bluetooth module is connected. At first, our goal is to examine which kind of signals we are able to detect with the module without having to pair the two devices. Our desired result is to inconspicuously automate the identification. Once the identification of devices is successful, we can further develop the system for different operations.

                
                                                                         HC-05 Bluetooth module

    List of required parts for the project:

    • Arduino Uno
    • HC-05 Bluetooth module (Our module is the version 3.0), Datasheet
    • Voltage divider for the BT-module (resistors).
    • Mobile phone (The bluetooth protocols differ a bit between different phones/operating systems).


                           Voltage divider for the HC-05 module

  3. Schedule

    The project was started on week number 9 by gathering information on existing devices. By week number 11 the device is functioning and we are able to identify different mobile devices based on their background communication data.
    Next step is to deploy the device for different actions.



                
                                          Device ready to use


                
                                                                Data gathered by the system


  4. Challenges

    One of the main challenges is the restrictions in the background communication data of mobile devices. Bluetooth Low-Energy is a fairly new technology and the availability of BLE-beacons might be limited.

  5. Further development

    The device can be harnessed for an extensive amount of applications. BLE-beacons could be spread out to gather live data of the amount of people (with bluetooth capable mobile phones) there are in the range of the beacons. This kind of proximity sensing could be useful if one might want to restrict the amount of people in specific premises. Next step could be to utilize the bluetooth signal strength data we get from the device, or to use Wi-Fi signals to identify devices in the same manner as with BLE. 

  6. Implementation

    1. Connect the HC-05 bluetooth module to the Arduino board using a appropriate voltage divider, which in this case was made with 4700 and 10 000 ohm resistors. The HC-05 module is connected to the arduino by following:
      1. TX to arduino TX.
      2. RX to arduino RX.
      3. VCC to arduino 5V output through voltage divider.
      4. GND to arduino GND.
      5. Key pin unconnected (will be connected later). 
    2. Apply the code. 
    3. With the HC-05 module (version 3.0) that we used, the procedure to gain access to full AT-mode, and thus to the features that we needed, is following:
      1. Power up the module with the key pin disconnected. The LED in the module will flash quickly.  
      2. Push and hold the tiny button which is located in the bottom of the HC-05 module, and while holding the button, connect the Key pin of the HC-05 module to arduino 5V. When the key pin is connected, you can release the button. The led on the HC-05 module should now be on continuously. We are in full AT-mode.
      3. The module starts to search for devices in its range (since we've told it to do so in the code), and will list their bluetooth addresses. The list can be monitored via serial monitor. 
      4. In the code you can decide which bluetooth addresses (ie. which devices) will trigger different actions. We chose to light up a led, which is connected to the PIN 13 of arduino, but you can connect basically anything to the pin of your choice, and with just adding the pin output to the code you can actuate pretty much anything. When the device leaves the range of the bluetooth module, the pin output will turn off, and in our case the led is turned off. In our code, the LED was triggered by Aleksi's phone (BT address 9809:CF:68C85A).

The serial monitor should look like in the following picture, 4851:B7:209607 and D004:1:63AEB4 being bluetooth addresses of two different devices.               



7. Useful links

Instructions of how to set up the device: https://youtu.be/7OW8-IkG3j0

Demonstration of the device: https://youtu.be/VEvT3lUetMc

HC-05 Datasheet: http://www.linotux.ch/arduino/HC-0305_serial_module_AT_commamd_set_201104_revised.pdf

HC-05 Bluetooth device inquiry: https://electronics.stackexchange.com/questions/98160/how-to-get-rssi-of-bluetooth-specfically-hc-05/98168#98168

HC-05 Troubleshooting: https://arduino.stackexchange.com/questions/50974/how-to-solve-problem-atinq-error-1f-atinit-error17-on-bluetooth-module-hc


8. Code


#include <SoftwareSerial.h>

#include <String.h>

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

char c = ' ';

String address;

String rx_string;

int i;

int k;

String address_list[10] = {"0","0","0","0","0","0","0","0","0","0"};

long counter[10]={0};

char crx_string[50];

int led1=12;

char INQ[10];

char type[10];

char strength[10];

String parse_address(String rx_string){

  String address;

  if (rx_string.startsWith("+INQ:")){

    k=0;

    for (i=0; i<=rx_string.length(); i++){

      if (rx_string.charAt(i)==','){

      k=1;

      }

      if (i>4 && k==0){

        address.concat(rx_string.charAt(i));

      }

    }

  }

  return address;

}

void delayAndRead()

{

  delay(50);

  while(mySerial.available())

  {

    c = mySerial.read();

  }

  delay(1500);

}

void initHC05ToInq()

{

    mySerial.println("AT+CMODE=1");// Enable connect to any device

    delayAndRead();

    mySerial.println("AT+ROLE=1");// Set to master in order to enable scanning

    delayAndRead();

    mySerial.println("AT+INQM=1,10,24");//RSSI, Max 10 devices, ~30s

    delayAndRead();

    mySerial.println("AT+CLASS=0");// Disable COD filter

    delayAndRead();

    mySerial.println("AT+INIT");// Init.

    delayAndRead();

}

void setup(){

  initHC05ToInq();

  Serial.begin(9600);

  pinMode(9, OUTPUT);

  digitalWrite(9, HIGH);

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

  pinMode(led1, OUTPUT);

  mySerial.begin(9600); //9600 is the default value (BAUD4)

}

void loop(){

  k=0;

  i=0;

  while (Serial.available())

    mySerial.write(Serial.read());

  while (mySerial.available()){

    c=mySerial.read();

    rx_string.concat(c);

  }

    address=parse_address(rx_string);

    for (i=0; i<10; i++){

      counter[i]++;

      if (address.compareTo(address_list[i])==0){

        counter[i]=0;

        address="0";

        continue;

      }

      if (address_list[i].compareTo("0") == 0){

        address_list[i]=address;

        counter[i]=0;

        address="0";

        continue;

      }

      if (counter[i]>=10){

        address_list[i]="0";

        counter[i]=0;

        continue;

      }

    }

    Serial.print("DETECTED ADDRESSES:");

    for (i=0; i<10; i++){

      if (address_list[i]!="0"){

        Serial.println(address_list[i]);

      }

    }

    Serial.println();

    for (i=0; i<10; i++){

      if ((address_list[i].equals("9809:CF:68C85A")) || (address_list[i].equals("D004:1:63AEB4"))){

        Serial.println("LEDHIGH"); 

        digitalWrite(led1, HIGH);

        break;

      }

      else{

        digitalWrite(led1, LOW);

      }

    }

    rx_string.remove(0);

    address.remove(0);

    counter[i]++;

    delay(1000);

}
















  • No labels
  File Modified
JPEG File 2021-04-06 11.11.44.jpg Apr 06, 2021 by Aleksi Laakso
JPEG File 2021-04-06 12.02.32.jpg Apr 06, 2021 by Aleksi Laakso
PDF File BLE-majakka Wiki.pdf Mar 15, 2021 by Pietari Reijonen
PNG File Screenshot 2021-03-14 at 10.06.09.png Mar 15, 2021 by Pietari Reijonen
PNG File Screenshot 2021-03-14 at 10.06.51.png Mar 15, 2021 by Pietari Reijonen
PNG File Screenshot 2021-03-14 at 10.07.36.png Mar 15, 2021 by Pietari Reijonen
PNG File Screenshot 2021-03-14 at 10.07.59.png Mar 15, 2021 by Pietari Reijonen