5.- App requests temperature and humidity to the Arduino. The Arduino sends values.
p9A0i_bluetooth_temperatura.aia (3.3 KB)
-
When Click in tempe_humidity Button, App sends the character “D”.
Arduino concatenates the temperature and humidity Strings separated by a comma:
37,80 -
App ReceiveText 37,80 converts it to a list and separates the values.
-
Note: the DelimiterByte must have the value 10. [10 is ASCII New Line, LF. Arduino \n]
-
In this Arduino code I do not use the sensor or the I2C LCD to simplify its content.
Here you can see the code with the sensor and the I2C LCD
// Juan A. Villalpando
// http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm
char caracter;
int temperature = 0;
int humidity = 0;
String tempera_humidity;
void setup() {
Serial.begin(9600);
}
void loop() {
temperature = random(20,40);
humidity = random(50,95);
delay(500);
if(Serial.available()) {
caracter = Serial.read();
if(caracter == 'T'){Serial.println(temperature);}
if(caracter == 'H'){Serial.println(humidity);}
if(caracter == 'D'){
tempera_humidity = (String) temperature + "," + (String) humidity;
Serial.println(tempera_humidity);
}
}
}