General Bluetooth Handling


I am trying to build Bluetooth communication between a sensor and the main console. The hardware that I have in this particular instance is a Arduino DUE with a HC-10 module connected (this is my console) and an Arduino Nano that also has a HC-10 module. There are other sensors and modules connected which I can discuss if required, however I would like to focus entirely on Bluetooth in this instance.

I have paired the modules and established communication at the default baud rate of 9600.

The pseudo code of what i am trying to achieve is:

  1. Sensor generates a number (between 0 and 9999) and sends to bluetooth module (via print) - currently every second
  2. Console reads the BT serial and retrieves the number then stores it in a global variable
  3. Console displays this number on serial output (and on my screen but I know how to handle that)

So you can see - I am trying to achieve something pretty simple - but struggling as I cant find any tutorials to guide me on my way.

Future plans: The reason for this is because I intend to have a gyro wirelessly connected to the main console allowing me to move the object freely and see its x,y,z coordinates on a central unit easily (The Arduino due with screen).

If anyone has any guidance on this it is greatly appreciated!

testserver.ino (130 Bytes)

Bluetooth-Testing-Sensor.ino (710 Bytes)

Please put the code between proper tags </>.

IMO, you're better off starting with a couple wires between the two Arduinos. Simplify your setup so you don't need to worry if the Bluetooth modules are communicating or not.

Once you have the serial communication working as expected, add the Bluetooth modules.


I've sorted it now - I was significantly overcomplicating what I wanted to do. I also added a non-alphanumeric character after the value to speed up the parseInt() command - I was able to send a 6 figure int value every 1/1000th of a second in my testing!

Thanks for the initial responses!

My only remaining question is about handling multiple values. For now I am assuming that my values are being sent in the expected order - however I now want to add some checking. For example my sensor has x,y,z float values that are currently sent in the following format:


The current code for the receiver is:

  while (BT.available() > 0) {
    x = BT.parseFloat();
    y = BT.parseFloat();
    z = BT.parseFloat();
    Serial.print("x: "); Serial.println(x);
    Serial.print("y: "); Serial.println(y);
    Serial.print("z: "); Serial.println(z);
    lcd.printNumber (80,10, x);
    lcd.printNumber (80,110, y);
    lcd.printNumber (80,170, z);

Am I best doing a nested if statement and sending the value name first? i.e.


I could parse the serial buffer and say if the next character is x then x = Serial.parseFloat(), if y then y = Serial.parseFloat().

Does that make sense logically or is there a better way of handling multiple values send over serial?