I have an Andriod APP which connects to Arduino UNO over bluetooth( HC-05), and receives sensor readings using Serial.print() command in Arduino sketch. The App is made using APP inventor and uses Bluetooth blocks in that program.

Here's a snapAPPINVENTOR Block

It works fine until I use a Dust sensor, which needs Android to sample on pin D8.

int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 1000;//sampe 30s ;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
unsigned long timeElapsed=2000;
unsigned long sTime;

void setup() {
starttime = millis();

void loop() {

duration = pulseIn(pin, LOW);
lowpulseoccupancy = lowpulseoccupancy+duration;

if ((millis()-starttime) > sampletime_ms)//if the sample time == 1s
ratio = lowpulseoccupancy/(sampletime_ms*10.0);  // Integer percentage 0=>100
concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet    curve


Adding the variable "concentration" above to the Serial.print() leads to the error in which the APP receives no information block on one clock timer, then receives two consecutive in the next clock timer. The APP is designed to check bluetooth every 1000 ms, and I am sending the sensor data after 1000ms. When it receives no data, it shows error="Cannot acces item/list is empty. What to do? It works fine if I leave "concentration". Serial rate is 9600bps.


1 Answer 1


In the arduino a long is 32 bits, I think a float for concentration is not enought, so, the aruino go in overflow maybe resetting it self before writing enything to the serial.

  • \$\begingroup\$ Values of concentration vary anywhere between 100 and 50,000 and thus are comfortably within float's range. It should not be a problem. \$\endgroup\$
    – user20507
    May 21, 2014 at 16:50
  • \$\begingroup\$ Did you checked if you can see any data with the serial port, without the bluetooth? \$\endgroup\$
    – user43186
    May 22, 2014 at 9:01
  • \$\begingroup\$ Yes, in fact the data is coming out fine on the serial monitor. \$\endgroup\$
    – user20507
    May 22, 2014 at 9:11
  • \$\begingroup\$ ok, it's a sync problem between android and arduino, thy this way: send a command from the android to the arduino for the data, in this way you don't even need to wait. \$\endgroup\$
    – user43186
    May 22, 2014 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.