Hello everyone. I was wondering how I could receive more than one value from my arduino sensors to my phone. Basically, how can my phone recognize different variables? How can I set it up on both arduino and mit?
Arduino Sketch Example
ClassicBt_Arduino_ToAppMultiVal.txt (2.1 KB) (rename to .ino file)
You can send a string, like this:
//ArduinoToAppMultiVal.ino Chris Ward 13/04/2021 23:05:14
DHT_Unified dht(DHTPIN, DHTTYPE);
//vars
unsigned long lgUpdateTime;
unsigned int igID = 1;
float fgTemperature;
float fgHumidity;
void setup()
{
// Initialize device.
dht.begin();
Serial.begin(9600);
lgUpdateTime = millis();
}
void loop()
{
if(millis() - lgUpdateTime > 5000) //Loop approx every 5 seconds
{
lgUpdateTime = millis();
//Collect sensor data
//Temperature
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature))
{
fgTemperature = 99999.0;
}
else
{
fgTemperature = event.temperature;
}
//Humidity
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity))
{
fgHumidity = 99999.0;
}
else
{
fgHumidity = event.relative_humidity;
}
if (Serial.connected())
{
//To App via Bluetooth
if ((fgTemperature != 99999.0) && (!fgHumidity != 99999.0))
{
Serial.print(fgTemperature,2);
Serial.print("|");
Serial.print(fgHumidity,2);
Serial.print("|");
Serial.print(igID); //process ID
Serial.println(); //This tells App "End of Data"
//= Ascii LineFeed Char Num 10
}
}
}
}
Note that I have used a pipe "|" char as the value separator for App Inventor to split the string into a list.
Hello. I'm having an issue with receiving multiple values. I will send you the code and the block, I circled the part where I've had the issue (everything else works just fine)
momo.txt (1.2 KB)
Yes. I had put it in the block only but now also from the designer. However, those values still don't appear. Or better, take a look
This technique only works when you do BlueTooth ReceiveText.
It does not work for ReceiveUnsignedBytes.
Thank you so much! It works now. One question: why do we put that -1 at number of bytes? What's it for?
Thank you!
Right-click the "ReceiveText" block and select "Help" from the menu. There is a description for the negative value.




