Bluetooth HC-06. Arduino. Send. Receive. Send text file. Multitouch. Image

It would also help to set global Volt to Bluetooth.ReadText inside that if/then before announcing Volt in a Label.

34.- App sends a number as text via Bluetooth and Arduino converts it to binary. Return.

p9A2_ConvertirBinario.aia (9.5 KB)

bluetoothjuanantonio7

a) It converts it to binary with 8 bits.

void setup() {
  Serial.begin(9600); 
}

void loop() {
  if (Serial.available()) {
    int num = Serial.parseInt(); // Read number received as text

    String binary = String(num, BIN); // To binary
    while (binary.length() < 8) {
      binary = "0" + binary; // Fill 0 left
    }

    Serial.println(binary); // Print binary number and return.
  }
}

bluetoothjuanantonio4

oooooooooooooooooooooooooooooooooooooooooooooooooo

b) Binary Positional.
[Start in position 0]

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    int num = Serial.parseInt(); // Read number received as text

    String binary = "";
    for (int i = 0; i < 48; i++) {
      if (i == num) {
        binary += "1"; // Agregar "1" en la posición correspondiente al número
      } else {
        binary += "0"; // Agregar "0" en las demás posiciones
      }
    }

    Serial.println(binary); // Print binary number and return.
  }
}

oooooooooooooooooooooooooooooooooooooooooooooooooo

c) It converts it to BCD (Binary-Coded Decimal).
[It is necessary that the input has 4 digits: 1256]

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    String textReceived = Serial.readStringUntil('\n'); 

    if (textReceived.length() == 4) {
      for (int i = 0; i < 4; i++) {
        int num = textReceived.charAt(i) - '0';  // Get numeric value.
        String bcd = String(num, BIN);  // To BCD
        bcd = ("0000" + bcd).substring(bcd.length());  //  BCD with 4 bits
        Serial.print(bcd + " ");  // Print binary number and return.
      }
      Serial.println();
    }
  }
}

bluetoothjuanantonio8

A post was merged into an existing topic: HC 05 Flow rate

35.- Arduino sends two random numbers with decimals, separated by commas.

pA0_Bluetooth_Arduino_envia.aia (10.7 KB)

float temperature = 0.0;
float humidity = 0.0;
String tempera_humidity;

void setup() {
  Serial.begin(9600);
}

void loop() {
  temperature = random(20, 40) * 5.555;
  humidity = random(50, 95) * 3.333;

  tempera_humidity = String(temperature, 3) + "," + String(humidity, 3);
  Serial.println(tempera_humidity);
  delay(1000);
}

bluetooth_basico36

1 Like

36.- Ultrasound SR04 sends distance to App by Bluetooth.

pA0_Bluetooth_Arduino_Ultrasonido.aia (3.0 KB)

Arduino Library Ultrasonic.zip:
http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm#ultrasonido

#include <Ultrasonic.h>
Ultrasonic ultrasonic(12,13); // (Trig PIN, Echo PIN)

void setup() {
  Serial.begin(9600);
}

void loop(){
  Serial.println(ultrasonic.Ranging(CM));
  delay(500);
}

1 Like

Hello, I tried this and it's not working, when connecting to HC-05 Bluetooth module it works but on the Check Temperature button when I click it it just freeze. Any help? thanks

I already set the DelimiterByte the value 10, still not working

Not working on me

Well, now it's working, after extensive research and checking the hardware parts I used, the app was not the issue, the problem was the power supply, the wire I use was longer, then I try shorter wire, now it works, the problem was power supply shortage.

2 Likes