HCSR04 really slow in App Inventor

i cant post it haha, network problem, sorry
hcsr04 (1).aia (243.7 KB)

can u help me? pls

hcsr04 (1).aia (274.0 KB)


I also had to fix
Delimiter Byte

I tried to test the application as it is and it tells me that it does not respond, it does not load, do you know why?

i fix the problem of the doesnt respond but the app still doesn't work, maybe it's my arduino code.
Now the app simply doesn't do anything, it doesn't change the image, it doesn't play sound and nothing

void loop()
{

long distancia = ultrasonic.read();
long distancia2 = ultrasonic2.read();
if (distancia < lejos)
{
  alertas(distancia);
}
else if (distancia > lejos)
{
  digitalWrite (led, LOW);
  bt.println("d");
  delay(400);
}
   if (distancia2 < lejos)
{
  cuidado(distancia2);
}
else if (distancia2 > lejos)
{
  digitalWrite (led, LOW);
  delay(400);
  bt.println("h");
} 

}
void alertas(float distancia) {
if (distancia < lejos && distancia >= medio) {
bt.println("a");
delay(400);
parpadeo(1000);
}
else if (distancia < medio && distancia > cerca) {
bt.println("b");
delay(400);
parpadeo(500);
}
else if (distancia <= cerca) {
bt.println("c");
delay(400);
parpadeo(250);
}
}

void parpadeo(int tiempo) {
digitalWrite(led, HIGH); // enciende el LED.
delay(tiempo); // retardo en milisegundos
digitalWrite(led, LOW); // apaga el LED.
delay(tiempo);
}
void cuidado(float distancia2) {
if (distancia2 < lejos && distancia2 >= medio) {
bt.println("e");
delay(400);
parpadeo2(1000);
}
else if (distancia2 < medio && distancia > cerca) {
bt.println("f");
delay(400);
parpadeo2(500);
}
else if (distancia2 <= cerca) {
bt.println("g");
delay(400);
parpadeo2(250);
}
}

void parpadeo2(int tiempo2) {
digitalWrite(led, HIGH); // enciende el LED.
delay(tiempo2); // retardo en milisegundos
digitalWrite(led, LOW); // apaga el LED.
delay(tiempo2);
}

Add a final ELSE to the AI2 if/then/else to display anything that the preceding branches missed in a Label.

Also, is Switch1 On?

I notice you lack branches to handle disconnection.

See FAQ Section: BlueTooth Starter Guides

I dont get it :frowning:

yeah switch 1 is on

its a hc05 bt module

Try changing that -1 in the ReceiveText block to +1, to force read single characters.

2 Likes

now works, thanks a loooot

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.