Hi there. I have a problem with my bluetooth module HC-05.
I could configure it and paired it to my cellphone (android) correctly using the SoftwareSerial.h library.
I'm able to change the name, password, and other parameters with the example code, and it works correctly:
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(10, 11); // RX, TX
void setup() {
Serial.begin(9600);
bluetooth.begin(38400);
while (!Serial) {
}
Serial.println("Configuración");
}
void loop() { // run over and over
if (bluetooth.available()) {
Serial.write(bluetooth.read());
}
if (Serial.available()) {
bluetooth.write(Serial.read());
}
}
And as this works correctly, I don't believe there's a problem with the circuit (just the bluetooth module connected my arduino UNO vcc-5v, GND-GND, TXD-10, RXD-11).
Just for testing, I want to print to the serial monitor any value recieved via bluetooth, and turning on a led if it is '1'. I'm using the Serial Bluetooth Terminal app, that was recomended to me by a friend.
Here's the code I'm using:
#include<SoftwareSerial.h>
SoftwareSerial BT(10, 11); //RX TX
int ledPin = 13;
char state = '0';
void setup() {
BT.begin(9600);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
}
void loop() {
if(BT.available()){
Serial.print("Data recieved: ");
state = BT.read();
Serial.println(state);
if (state == "0"){
digitalWrite(ledPin, LOW);
} else {
if(state == "1"){
digitalWrite(ledPin, HIGH);
}
}
}
delay(10);
}
So, I can connect from the app to the bluetooth module (It says Connected in the app), but when I send any message, it doesn't do anything. Neither the led turns on if I send a '1', nor it shows anything in the Serial Monitor.
I have already tried with 3 different HC-05, each of them bought in a different place, and with 3 different Arduinos. I have changed the bauds, the name, and other configurations, I have tried with 4 different programs, I've simplified the code to only show a message with the if(BT.available());, I've changed the pins, the voltage, and nothing.
I've never had this much problem with any other arduino module, I've read forums and watched videos for days, but no matter what I try, it doesn't work.
Do you have any idea what the problem might be? I would appreciate a lot your help
I hope I was clear with my problem, and if you have any further question, don't doubdt to ask it.