Hi everyone,
I have an issue while trying to recive information send from my phone to my bluetooth hc-05 module, I think that every thing is conected properly to the arduino uno board, and I can find no problems on my code, if any of you can spot the problem, it would help me a lot.
It also does not print the recieved information on the console.
This are the conections to the board:
RX -> 9
TX -> 10
LED -> 6
The HC-05 module is powered with 3.3 volts.
And this is the code I use for this project.
#include <SoftwareSerial.h>
SoftwareSerial ModuloBT (9, 10); // (TXD,RXD);
const int Led = 12;
String infoInicio;
int info = 0;
void setup() {
pinMode(Led, OUTPUT);
Serial.begin(9600);
ModuloBT.begin (9600);
Serial.println ("Preparing");
ModuloBT.print("AT");
delay(1000);
ModuloBT.print("AT+NAME");
ModuloBT.print("LED_CONTROL");
delay (1000);
ModuloBT.print("AT+BAUD");
ModuloBT.print("4");
delay (1000);
ModuloBT.print("AT+PSWD");
ModuloBT.print("1234");
delay (1000);
Serial.println("End setting up everything");
}
void loop() {
if (ModuloBT.available()){
infoInicio = ModuloBT.read();
info = infoInicio.toInt();
Serial.println(infoInicio);
if (info == 1){
digitalWrite(Led, HIGH);
}else if (info == 0){
digitalWrite(Led, LOW);
}
}
}
If there ia someone out there that can help me with this problem I will thank him a lot.
Ok, I have symplified the code and now I can recieve information, but I am suposed to receive imformation as numbers from -250 to 165 and It is only printed on the console numbers between 56 and 45, does someone know where is the problem.
This is the new code:
Thanks every one for your help but now I have another doubt how can I check if the bluetooth is conected. I ask this is because I want to make a blue led blink while the bluetooth is not conected.
It may be possible to use the state pin of the module to monitor the connected status. Not all modules support the use of this pin and there is a good discussion here