Two flux of bluetooth problem

Hi everyone,

I'm here because I'm in trouble... I use MIT app Inventor 2 to make an application and the HC05 bluetooth module to cummunicate between the application and the arduino but I have a problem with it, can someone help me?

I have an app that read the temperature that the arduino receive and that works well. The problem is that I have to transmit an information (basicly 1 and 0) to my arduino to control one other thing but the arduino can't read it, maybe because there's too much information on the Serial port (I send temperature every 5 seconds)... Is that true? Can I fix that?

Thank you

Hi. Your description of the problem is hopelessly lacking in detail for anyone to guess what the problem could be. I could give you a list of all the things we would need to know to help you, but fortunately they are already written down for you in the "please read" post at the to of every forum section.

Ok so:
I use an arduino Uno, a HC05 bluetooth module and MIT app inventor 2. I send every 5 seconds the temperature on the application like that:

int a=1;                  //Bluetooth
                  
#include <Servo.h>      //Servo
Servo myservo;
int val;

#include <dht.h>        //Temp
#define dht_apin A5
dht DHT;

unsigned long actual_time;  //millis
unsigned long last_time_task1;
unsigned long last_time_task2;

void setup(){

 Serial.begin(9600); 

 myservo.attach(7);     //Servo

}
void loop(){

//Bluetooth
  while(Serial.available()){   
    a=Serial.read();
    Serial.println(a);}
    if(a=='1'){
      myservo.write(0);
      delay(5000);
      myservo.write(179);
      delay(500);
}
    if(a=='0'){
      myservo.write(0);
    }
  while(1>0){
    DHT.read11(dht_apin); //Temp
    Serial.println(DHT.temperature);
  delay(5000);
}
}

Then on the application I read this temperature and I display it on the screen (this part works fine).

My problem here is that I would like to send a code (the a==1 and a==0 on the arduino) that could run the loop. But it doesn't work as I want, the arduino doesn't seem to receive that byte... I will let you a screenshot of the code I use for the application on MIT.
Thank you

Thankyou for using code tags.

Your code is still difficult to read. Could you please click Tools-->Auto format and then post it again?

I did spot this:

while(1>0){

that will cause the code to become stuck in that loop forever. Is that what you intended?

Wow... I'll stick with "normal" code thanks!

I don't see the Tools option... Yes the While loop is useless here you're right but it's still what I intended. I know it's not the usual code but it's easy to understand isn't it? I forgot to say that if I don't use the temperature part of my code, the bytes that I send from the application do it's job fine so I don't know how to fix that...

  while(1>0){
    DHT.read11(dht_apin); //Temp
    Serial.println(DHT.temperature);
  delay(5000);
}

When do you expect this loop to stop/exit?

I don't want it to stop, it's just that I programmed in python recently and I forgot that there's a loop function in the arduino ::slight_smile:

Then you need to get rid of the delay as well. You should be using the BlinkWithoutDelay method of checking if time passed or you will only check the serial ports every 5 seconds as well.

Distra12:
I don't see the Tools option... Yes the While loop is useless here you're right but it's still what I intended. I know it's not the usual code but it's easy to understand isn't it? I forgot to say that if I don't use the temperature part of my code, the bytes that I send from the application do it's job fine so I don't know how to fix that...

Look harder for the Auto Format option.

So, if you remove the temperature loop, the code works how you want. If you put the temperature loop option in, the rest of the code does not work. But you say this is how you intended the temperature loop to work, to loop forever. That isn't really how you intended it to work is it?

I try to use the millis function and it soluced my problem :slight_smile: Thank you very much