Problem with BT module HC-05

I have a circuit where two pumps (currently just LED's) are activated by pressing two different buttons.
After its success, I updated the code to use a bluetooth module HC-05 and control it with an MIT App Inventor app.
Unfortunately, it doesn't work, and I don't know whether the problem lies in the Arduino or the app

The code goes as following:

//Constants pump 1 y 2

const int pin_pumpA = 2;
const int pin_pumpB = 3;



// BT state variable
int bt_state = 0;

void setup()
{

Serial.begin(9600);
pinMode (pin_pumpA, OUTPUT);
pinMode (pin_pumpB, OUTPUT);

}
void loop()
{
//lectura del estado del texto BT
if (Serial.available() > 0)
{
bt_state = Serial.read();
}

if (bt_state == 1)

{


digitalWrite(pin_pumpA,HIGH);
delay(5000);
digitalWrite(pin_pumpA,LOW);
delay(1000);


}

if (bt_state == 2)

{
digitalWrite(pin_pumpB,HIGH);
delay(5000);
digitalWrite(pin_pumpB,LOW);
delay(1000);

}

I could use some help trying to find the problem, thanks!

If you use a different app than the MIT ap inventor to send a 1 or 2 does it work?

I have the "Serial Bluetooth Terminal" app I use for testing things like this. After you are connected you can simple commands and read simple feedback. Then you'll know if the problem is the app or the code.

1 Like

Thank you, by using "Seria Bluetooth Terminal" I found out it was better to use a char variable instead of int.
Have a nice day

1 Like

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