Sending data from Leonardo to Android via bluetooth

Hi guys!
i have a few question for you.

This is an example of code which allow arduino to read data sended from android via bluetooth.

void loop() {
 
  if(Serial1.available() > 0){ 
      state = Serial1.read(); }
        
  if (state == '3') {
      digitalWrite(EngineON, HIGH);}   //digital pin (relay)
}

but... tell me how it should look like if i would like to SEND same data via bluetooth to android ? do i need any additional libraries ?
im asking because i have configurated temperature sensor everythink works fine in "Serial Port Monitor" but i would like to SEND teperature from arduino to android.

i really need your hint.

tell me how it should look like if i would like to SEND same data via bluetooth to android ?

If Serial1 is connected to the bluetooth device, and available() and read() get data from it, then write(), print(), and println() send data to it.

just like that? :

void loop() {
 
  if(Serial1.available() > 0){ 
      state = Serial1.read(); }
      sensors.requestTemperatures();
      Serial.print(sensors.getTempCByIndex(0));
      temp = sensors.getTempCByIndex(0);
      write(temp);

 if (state == '3') {
      digitalWrite(EngineON, HIGH);}
}

just like that?

No. Properly formatted for one thing.

      sensors.requestTemperatures();
      Serial.print(sensors.getTempCByIndex(0));
      temp = sensors.getTempCByIndex(0);
      write(temp);

What does write() do? Is that supposed to be Serial1.write()? If so, why do you want to use both print() (send a string) and write() (send binary data)?

Why are you calling getTempCByIndex() twice?

PaulS:
Why are you calling getTempCByIndex() twice?

Only to make sure that it works fine in arduino. it will be deleted in final version :slight_smile:

so the only one error is that i wrote write(temp); instead Serial1.write(temp) ?
Am i able to send this as a string to easly display it in android app ?
which way is better , to send temp as string or binary data ?

sorry for newbie questions but iam beginner... with interesting idea creating on-board computer in my car fiat 126p.

Am i able to send this as a string to easly display it in android app ?

Send me your Arduino and your phone, and I'll test it for you.

which way is better , to send temp as string or binary data ?

Depends on what you are going to do with the data.

Send me your Arduino and your phone, and I'll test it for you.

im creating android app in app inventor its in *.aia extension , its ok ? but I do not have a code sequence which should be responsible for displaying the temp. arduino app is done so i will send both on pw, ok ?

Depends on what you are going to do with the data.

i just want to display it :slight_smile: beacuse arduino does all the calcullation.