Connect my arduino ble to my phone via bluetooth

That's the tricky part because generally, your boxer can punch faster than the system can process the data.


I think trying to display values in boxes on the App will be fruitless since they can change faster than the eye can tolerate watching them. I therefore suggest adding the values to a Blocks List and at the end of the session use the App Gui to display meaningful information. That would be the time to calc things like the power of the punches.

So like this (not sure at the moment if four values should be sent?)



You are asking the same questions in other forums. You will get yourself a bad reputation as a time waster. Instead, you could be researching and experimenting with your setup.

One thing I have noticed is that others describe the Nano Sense as relatively new and relatively buggy. So your project is in for a bumpy ride in many ways. :thinking:

Ensure you install the latest drivers for the Nano 33 BLE via the Arduino Boards Manager plus the LSM9DS1 sensor driver.

I have been trying to make sense (no pun intended) of your Arduino Sketch. The most convincing guide I found was on, but I'm uncertain if the Characteristics UUID will work (it sounds right). On compilation of the Sketch, there are several warnings about Arduino BLE lib dependencies, hence the reputation for being buggy, but the Sketch does compile. :thinking:

BleToAppPunchBag.txt (4.7 KB)

//Reference: //IMU Sensor //
//NOTE: Arduino NANO 33 BLE Sense runs at 3.3V (Both digital and analog pins)

#include <ArduinoBLE.h>
#include <Arduino_LSM9DS1.h>

float fgOldX = 0.0;  //previous values
float fgOldY = 0.0;
float fgOldZ = 0.0;

bool bgCentralConnected = false; //connection check
unsigned long lgUpdateTime;      //Loop time interval

BLEService dataService("180C"); //User defined service

BLEStringCharacteristic dataCharacteristic("2A56", BLERead, 13); // standard 16-bit characteristic UUID
                                                                 //remote clients will only be able to read this

void setup()
          Serial.begin(9600); //115200 // initialize serial communication. Virtual serial port to connect with App via BLE
         Serial1.begin(9600); //Second serial port @ the RX0 and TX1 pins to connect with Arduino Serial Monitor //For test phase

          //begin BLE initialization
          if (!BLE.begin())
              Serial1.println("starting BLE failed!");
              while (1);

          BLE.setLocalName("SacDeFrappe");                   //Set name for connection
          BLE.addService(dataService);                       //Add service
          BLE.setAdvertisedService(dataService);             //Advertise service
          dataService.addCharacteristic(dataCharacteristic); //Add characteristic to service
          BLE.advertise();                                   //Start advertising

          Serial1.print("Peripheral device MAC: ");

          if (!IMU.begin()) {
              Serial1.println("Failed to initialize IMU!");
              while (1);

          Serial1.print("Accelerometer sample rate = ");
          Serial1.println(" Hz");
          Serial1.println("Acceleration in G's");

         lgUpdateTime = millis();

void loop()
         //Execute Comms approx every 250 milli seconds - this can be tweaked during physical trials
	     if(millis() - lgUpdateTime > 250)
               lgUpdateTime = millis();

               if (bgCentralConnected == false)
                         //BLE central (App)
                         BLEDevice central = BLE.central();
                         if (central) 
                              Serial1.print("Connected to central: ");
                              //the central's BT address:
                              bgCentralConnected = true;


               if (bgCentralConnected == true)
                         bgCentralConnected = false;
                         Serial1.print("Disconnected from central: ");       

void updateValue() 
//Sending 3 values to App
float fNewX = 0.0;
float fNewY = 0.0;
float fNewZ = 0.0;
         if (IMU.accelerationAvailable()) 
               IMU.readAcceleration(fNewX, fNewY, fNewZ); // Read new data
               if ( int(fNewX) != int(fgOldX) || int(fNewY) != int(fgOldY) || int(fNewZ) != int(fgOldZ) ) //compare integers (floats are rarely going to be the same)
                         //Send to App
                         Serial.print(fNewX,2);  //Two decimal places
                         Serial.print('|');      //note, tabs were used but they are not recognised in App Inventor
                         Serial.println();        //End of BLE Data
                         //dataCharacteristic.writeValue((String(x))); //Think of a characteristic as a fixed value describing type of data shared
                         //save the values for next comparison
                         fgOldX = fNewX;
                         fgOldY = fNewY;
                         fgOldZ = fNewZ;
               Serial1.println("IMU acceleration not available");

On the Blocks side, it could be easier to register for Strings instead of Bytes. The values received by the App would arrive as a single string, like so: x|y|z - which is convenient to quickly store in a list, for extraction later. However, it depends on the byte size of the string as there is typically only 23 bytes available.

For example: "200.22|300.33|400.44" = 22 bytes [UTF-8] or 44 bytes [UTF-16], including end of data mark.

We can however, if required, increase the MTU (Minimum Transmission Unit) since your Phone is using BLE v5.0

I can't find the blocks " set global COMMENT" ....

sorry but it's a project for school and i have to send it left only 2 weeks...
yes i have installated it

this arduino sketch do not allow me to connect my phone with my arduino even if i use nRf connect ... what have you modified ?
my last program worked with nRf connect
sorry for all my questions i am a beginner

Study the Sketch carefully and read my notes.

So "Less Haste More Speed". The App Inventor Blocks need to be matched with the Sketch. Can you show me what the X, Y, Z values looked like out of nRf connect? It is the size of the numbers that is of interest.

I think we may need to test a very simple Sketch to establish how to connect. I'm surprised that your last program worked with nRF connect - was that the file "bluettoth accelerometer"? That Sketch has a lot of issues that I have tried to take out. The Arduino compiler is not great at picking up syntax errors but also it can't read minds - your code is trying to send data to two different targets but it is only using one Serial, so what goes where is a throw of the dice. This is why I ask you to study everything carefully, you cannot expect to leave stones unturned and get the setup to work. Look at the notes in my Sketch - did you follow those?

find attached an updated Sketch that sends a string. Note, the only BLE Characteristic required should be BLENotify - that should be listened for by the App after Registering For Strings. The Strings Received Block will do just that - receive strings sent to the App. If we can send the data for each punch as a single string, the process should be fast enough. The speed of the process is increased by only storing values until the session has ended. Then the App can use the data collected as required (Graph?)

Other subtle changes:-

  1. Updated ArduinoBLE lib to version 1.2.0 (should show-up in your Arduino IDE libs list, search for ArduinoBLE). This has removed some of the Lib warnings, but added others!
  2. Set the Local Name to "PunchBag" - the name must not exceed 8 ASCII characters

BleToAppPunchBag2.txt (4.7 KB)

Jumping ahead - once you have got the hardware running, you can tweak the time interval of the Sketch Loop to be as fast-but-stable as possible. If you set a test that is always 10 punches, in the first test the punches should be thrown in "slow motion", such that each punch takes around 0.5 seconds. If the data recording is successful, tweak the time interval to be faster and test with slightly faster punches - and so on.

You should try to set the full 128-bit UUID in appinventor. I think in the sketch as well. Maybe then it will work.