Help Using an Arduino Nano 33 BLE to send ECG Data via BLE to an Android Phone

Hello All,

I am currently working on a project in school where my team and I are trying to use an Arduino Nano 33 BLE to record an analog signal from an electrocardiogram we have constructed, and send this data to an android phone using BLE.

For data input, we are currently using a function generator connected to an Arduino UNO R3 in Tinkercad Circuits to simulate the input of a sine function with frequency 10, amplitude 3.3 V, and DC offset of 1.65 V. Here is the code that we have written for this portion:

int out[100];

void setup()
{
  Serial.begin(9600);
 // pinMode(13, OUTPUT);
 //	pinMode(A0, INPUT//);
 // analogReadResolution(12)
}

void loop()
{
 // analogReadResolution(12);

  for( int i = 0; i < 100; i++){
    out[i] = analogRead(A0); 
      //delayMicro(int) ds(100); //microseconds
    Serial.println(out[i]); 
  }  
}

The main hurdle now is sending the data using BLE. I am trying to use code, written by Klaus_K, but I do not know how to adapt it to fit the previous code. Here is the BLE code, written by Klaus_K:

#include <ArduinoBLE.h>

//----------------------------------------------------------------------------------------------------------------------
// BLE UUIDs
//----------------------------------------------------------------------------------------------------------------------

#define BLE_UUID_TEST_SERVICE               "9A48ECBA-2E92-082F-C079-9E75AAE428B1"
#define BLE_UUID_FILE_NAME                  "2D2F88C4-F244-5A80-21F1-EE0224E80658"

//----------------------------------------------------------------------------------------------------------------------
// BLE
//----------------------------------------------------------------------------------------------------------------------

BLEService testService( BLE_UUID_TEST_SERVICE );
BLECharacteristic fileNameCharacteristic( BLE_UUID_FILE_NAME, BLERead | BLEWrite, 20 );

String fileName = "";

void setup()
{
  Serial.begin( 9600 );
  while ( !Serial );

  BLE.begin();
 
  // set advertised local name and service UUID:
  BLE.setDeviceName( "Arduino Nano 33 BLE" );
  BLE.setLocalName( "Arduino Nano 33 BLE" );
  BLE.setAdvertisedService( testService );

  // BLE add characteristics
  testService.addCharacteristic( fileNameCharacteristic );

  // add service
  BLE.addService( testService );

  // set the initial value for the characeristic:
  fileNameCharacteristic.writeValue( fileName );

  // start advertising
  BLE.advertise();

}

void loop()
{
  // listen for BLE peripherals to connect:
  BLEDevice central = BLE.central();

  if ( central )
  {
    Serial.print( "Connected to central: " );
    Serial.println( central.address() );

    while ( central.connected() )
    {
      if ( fileNameCharacteristic.written() )
      {
        fileName = fileNameCharacteristic.value();
        Serial.print( "New file name: " );
        Serial.println( fileName );
      }
    }

    Serial.print( F( "Disconnected from central: " ) );
    Serial.println( central.address() );
  }
}

Any help would be greatly appreciated and I apologize if the answer is simple; I have little to no experience with programming Arduinos.

Thanks,
Tgab1000

Have a look into the following post reply #11

https://forum.arduino.cc/index.php?topic=659562.0

The example you found has a characteristic that is written to by a smartphone app and then the data is printed in the Serial Monitor window of the Arduino IDE.

The example I posted in the post mentioned above is very similar but it also has characteristics that are set by the Arduino and can be read by a smartphone app. So, this will be a lot closer to what you want to do.

You should load the example into your Arduino and then connect a smartphone BLE app. I use BLE Scanner on iPhone. There are others as well, I am sure you can find one for Android as well. This will help you understand how everything works.

Try to read trough the code and feel free to ask specific question about things you find unclear.

The Arduino BLE Reference can also tell you what each function and object are doing.

@Tgab1000 , I had similar problem. See my solution :

https://forum.arduino.cc/index.php?topic=660532.0

BTW it base on Klau's code. The key is to declare characteristic correctly for the data you want to transfer. There is an example to transfer string and char array (20 bytes) .I think for your project you will have to write some handshaking protocol to avoid loss of data. On Android side I recommend LightBlue scanner.