Sending variable thru blue tooth to android app.


Thanks for the Info I read your guide and it was informational. I wish I had read it a month ago before I started my Blue tooth journey.


So I am using Serial.write (VAL) Shouldn't this send bytes not chars or am I not understanding how that works. by doing this AI2 should be talking apples for apples.

I am interested in how you converted ASCII values to numeric values.

weldsmith: I am interested in how you converted ASCII values to numeric values.

I can't comment on that, I just get numbers out of sensors or on-board calculations in the normal manner, and send them to the phone. You can see this in the practical application at the end of the notes and I'm not sure that your goals are very different from that example. As far as I know A12 is just a road from London to Great Yarmouth, and I'm far from sure that there is anything to be gained from travelling on it. I'm only speculating, but it could even be your main source of grief right now.

Right at the back of the notes is a link to Robin2's serial input basics. It might be what you need.

I am interested in how you converted ASCII values to numeric values.

I think my method of doing this is incredibly awkward but I don’t know of a better way to do it.

The program receives each character as a byte but then finds the ASCII character from a list.


The byte is converted back to a character and added to the global string “tempText”. If a byte is a numeric character, then the global numeric variable “tempInputNumber” is increased appropriately.


When a carriage return is received (13) the function “FinalizeInput” is called which displays both the incoming text and processes the numeric value appropriately. It’s possible to use these numbers in calculations or graph them.

I don’t recommend receiving numeric values this way. The ability to send data to a smartphone was a feature added to a project I’m working on. There was a big advantage if the data could be sent in the same format as it was being sent to a LabView program. The LabView program could process the ASCII characters just fine and I didn’t want to use a separate protocol for the Bluetooth app.

Edit: I noticed the inserted images aren’t as detailed as the images attached. To see more detail download the images.

Alright, I still remain that my problem is in the arduino sketch. If the print statement reads like below, it completely ignores the (scr) The serial Monitor reads (GeoA) ascii char for (71,101,111, Hex 10) it is ignoring my raw data. The serial Port is having an issue with a value as a byte.

        Serial.write(71);         // control station Battery level.
        Serial.write(101);        //targ. Battery level
        Serial.print(10, HEX);

As I mentioned earlier,

DuaneDegn: weldsmith would need to use a terminal which displays non-ASCII characters.

If you're not using some special terminal which will display raw data, then you'll get gibberish as you have seen. I'm not aware of a serial terminal which will display data the way you want (though I wouldn't be surprised if such a program exists).

Being able to display data both in a normal terminal window and send it to an app was a big reason I went through the trouble I did to get the AI2 app to accept ASCII data as input.


Now, I get what you mean. I thought you were referring to a terminal on the phone.

So a Recap.

1)The terminal is behaving as it should. If I send a byte I will see nothing on the screen.
2)I will have to break down a raw value of 120 down to an ASCII string <1,2,0> on the arduino side.
3)I will have to reconstruct, if you will, 120 from the ASCII string <1,2,0> on the AI2 side.

am I understanding this Correctly?

There are a lot of people out there having this same issue and there has not been a good explanation. I will keep up this thread until I get it I hope it helps people in the future.

I have learned a lot on this post and I appreciate yours and everyone’s comments and help. I am a little thick headed at times, but I am starting to see what I am up against.

weldsmith: am I understanding this Correctly?


weldsmith: I appreciate yours and everyone's comments and help.

You're very welcome.

I can't believe the way I'm receiving ASCII characters is a good way to approach this problem. I just haven't found a (better) way to convert ASCII numeric characters to numeric variables AI2 can process.

If you just want to display the numbers as text then you don't have to jump through all these hoops.

As I promised I am posting my AI2 blocks and the arduino sketch for others to look at. I am sending a float and two integers. All data is sent by a comma separated list and it is recieved and Then parsed from a CSV list (comma seperated Value list). You do not have to parse the integers on the arduino side the serial port does this for you. The numbers can not be calculated on the AI2 side but can be converted from text to numeric and then you can use them as numbers.

the Bluetooth is connected through serial (HCO5)!simple-newping-sketch
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

#include <Encoder.h>
Encoder myEnc(18,19);  // 18=Purple Channel B 19=Green channel A
int actualPosition =0;

int buttonState ;
byte lastState = HIGH;
const int buttonPin = 17;     // the number of the pushbutton pin
const int ledPin =  13;       // the number of the LED pin  
int buttonPushCounter = 0;    // Store counts in here.

unsigned long Print_Interval = 50;
unsigned long previousMillis = 0;
char val; // variable to receive data from the serial port

#include <NewPing.h>
#define PING_PIN  10  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(PING_PIN, PING_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
float Dist_in_CM = 0;
unsigned long Dist =0;

void setup() {
lcd.begin(16, 2); 
  // initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);  


void loop() 

if (Serial.available() > 0) // if data is available to read
    val =; // read it and store it in 'val'

//**************Not needed***************************

if ( val == 'B' | 'C' | 'D' | 'E' | 'F')// can use this to select a function or a switch case statement.
     //PING_1  (); 

//**************Not needed***************************

if ( val == 'A' ) // if 'A' was received send all sensor Data.
  if (Serial)
        int actualPosition = ((;    
        Serial.print(actualPosition);      // encoder counts - or positive
        Serial.print (",");                // "," for the CSV a comma seperated value in AI2
        Serial.print(buttonPushCounter);   // button counts
        Serial.print(",");                 // "," for the CSV a comma seperated value in AI2
        Serial.println(Dist_in_CM);        // last print is println for deliminator block 
                                           // to show when to stop recieving.
        digitalWrite(ledPin, HIGH);        // an indicator for a send reciept.
  count ();
  Print ();
 //int Dist = sonar.ping_result / US_ROUNDTRIP_CM ;
void Print ()
   int Dist = sonar.ping_in() ; 
   int actualPosition = ((;
 if ((unsigned long)(millis() - previousMillis) >= Print_Interval)
    previousMillis = millis();  
    lcd.setCursor(0, 0);
    lcd.setCursor(0, 1);
    lcd.setCursor(4, 0);
    lcd.setCursor(4, 1);
    lcd.setCursor(7, 0);
    lcd.setCursor(10, 0);
    lcd.print(Dist_in_CM); //Dist_in_CM

int count ()
buttonState = digitalRead(buttonPin);
  if(buttonState && buttonState != lastState)  //
      digitalWrite(ledPin, HIGH);    
      buttonPushCounter ++;       
        digitalWrite(ledPin, LOW);
    lastState = buttonState;
    delay (50);

float PING_1 ()
    delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
    unsigned int uS =;// Send ping, get ping time in microseconds (uS).
    Dist_in_CM = uS / US_ROUNDTRIP_CM;
    return Dist_in_CM;//

Here’s the image attached to weldsmith’s reply. It’s much easier to read if you download the image.


Thanks letting us know how you got this to work.

I see there’s a “delimiter” field. Do you know if you can have more than one delimiter so you can break a file into fields and rows?


I do not know if you can have more than one delimiter byte. I used a delimiter byte of an ascii 10 (for line ending) to let AI2 know that the arduino was done sending data. The last print statement should be a Println to make this happen. AI2 does have a (list from csv table text) block that resembles a 3d array with rows and columns where you can call on a field and index to access the element. I think this is what you are looking for.