converstion value of ecg sensor

Hello
I have an ECG sensor that receives values between 50 and 100 I want to convert the VALUE of this section into a binary format I tried to convert, but I found it difficult to convert INT to string, what should i do ?
thank you.

const char LED = 13;
String msg_codee = "";
#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>
//  Variables
const int PulseWire = 0;
const int LED12 = 12;
int Threshold = 550;
PulseSensorPlayground pulseSensor;


void setup() {
  Serial.begin(9600);
  /************************************************************************************************/

  pulseSensor.analogInput(PulseWire);
  pulseSensor.blinkOnPulse(LED12);
  pulseSensor.setThreshold(Threshold);


  if (pulseSensor.begin()) {
    Serial.println("We created a pulseSensor Object !");
  }

  /************************************************************************************************/
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);

}
void loop() {
  /************************************************************************************************/
  {
    int myBPM = pulseSensor.getBeatsPerMinute();

    if (pulseSensor.sawStartOfBeat()) {
      Serial.println("♥  A HeartBeat Happened ! ");
      Serial.print("BPM: ");
      Serial.println(myBPM);
    }
    delay(20);
  }
  /*********************************************************************************************/

  coding();  //transform the message received from pc into a binary sequence
}

//********************************** coding *********************************

void coding() {


  String character = "";
  int f = 0;
  String msg_bin = myBPM;
  Serial.print("bpm in bin :");
  for (int i = 0; i < msg_bin.length(); i++) {

    char myChar = msg_bin.charAt(i);

    for (int j = 7; j >= 0; j--) {
      byte bytes = bitRead(myChar, j);
      Serial.print(bytes, BIN);
      character += bytes;
    }
  }
  Serial.println("");
  msg_codee = character;
  f++;
}
}// endof the coding

not sure what you mean by binary (all data is in binary)

    Serial.print ("bpm in bin: 0x");
    Serial.print (myBPM, HEX);

#1
i need to display the value of ecg sensor by binairy array for example if the ecg sensor give us value 78 i need to convert it to binairy foramt to sent it with ook modulation

light__fidelity:
…I want to convert the VALUE of this section into a binary format…

I hope hope you realise that the ‘0’ and ‘1’ you get when doing:

Serial.print(bytes, BIN);

are ACTUALLY ASCII Characters (ie ‘0’ =0b00110000 , ‘1’=0b00110001)

and NOT the bit value 0 and 1

if you want to output the value of the bits in ‘myBPM’ to a digital pin, then try something like this:

int temp = myBPM;
for (int j=0; j < sizeof(temp)*8; j++) {
      Serial.print((temp>>j)&0x01,DEC); // LSB first. 
                               //replace Serial.print with digitalWrite(pin,(temp>>j)&0x01)
}

Hope that helps…

sherzaad:
are ACTUALLY ASCII Characters (ie '0' =0b00110000 , '1'=0b00110001)

and NOT the bit value 0 and 1

thank you sur,
yes i know about ASCII Characters ,so i need to dispaly them in bin array to send them with ook modulation

light__fidelity:
thank you sur,
yes i know about ASCII Characters ,so i need to dispaly them in bin array to send them with ook modulation

I think you have the wrong idea of how that would work.... please post your OOK modulation code to understand better your intent

i think it what you’re trying to do

#define LED 10
#define ON  LOW
#define OFF HIGH

#define Period  100

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin(9600);

    digitalWrite (LED, OFF);
    pinMode      (LED, OUTPUT);

    char s [80];
    sprintf (s, "BPM %d", 123);
    transmit (s);
}

// -----------------------------------------------------------------------------
void loop() {
}

// -----------------------------------------------------------------------------
void bitOutput (
    bool  bit )
{
    Serial.print (" ");
    Serial.print (bit);

    digitalWrite (LED, bit);
    delay (Period);
}

// -----------------------------------------------------------------------------
void transmit (
    const char *s)
{
    Serial.println (s);

    for (unsigned n = 0; n < strlen (s); n++)  {
        byte c      = s [n];
        Serial.print   (c);

        bitOutput (0);

        bool parity = 0;
        for (unsigned i = 8; i > 0; i--, c >>= 1)  {
            bitOutput (c & 0x01);
            parity ^= c & 0x01;
        }
            
        bitOutput (parity);
        bitOutput (1);
        bitOutput (1);

        Serial.println ();
    }
}

light__fidelity:
I think you have the wrong idea of how that would work.... please post your OOK modulation code to understand better your intent

I have data from the ECG sensor, and I would like to convert these values into binary format,
This is the symbol for converting a text to a binary character, knowing that I enter the letters through the serial screen, but in my ideal, this is for the value sensor, it is not taken from the serial screen, but is taken directly from the sensor in the form of int, and that is why I found it difficult to convert it

light__fidelity:
I have data from the ECG sensor, and I would like to convert these values into binary format,
This is the symbol for converting a text to a binary character, knowing that I enter the letters through the serial screen, but in my ideal, this is for the value sensor, it is not taken from the serial screen, but is taken directly from the sensor in the form of int, and that is why I found it difficult to convert it

see the code snippet in reply #3