0

I have been trying to use the HC-05 Module with my Arduino Uno to control a LED, which can be turned on and off by my phone. Everything is fine when i input the values from the serial monitor. The problem only occurs when I use my phone. I am using a bluetooth terminal for HC-05 and it shows it connected. The bluetooth module is conected as its blinking slows down when I use the app.

Here's the code:

#define ledPin 8
int state = 0;

void setup() {
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, LOW);
 Serial.begin(38400); /
}

void loop() {
 if(Serial.available() > 0){ // Checks whether data is comming from the serial port
 state = Serial.read(); 
 }                                       
 if (state == '0') {
 digitalWrite(ledPin, LOW); 
 Serial.println("LED: OFF");
 state = 0;
 }
 else if (state == '1') {
 digitalWrite(ledPin, HIGH);
 Serial.println("LED: ON");;
 state = 0;
 } 
}

Here's the serial monitor output;

enter image description here Appreciate the Help!

0

Few Points that you might want to Look into.

  1. Where exactly are you connecting Bluetooth Module with Uno. Make sure you are connecting it with Rx and Tx Pin Only.
  2. First make Simple Program to send some data on Serial Say "Hello World" at every 1second and make sure your Bluetooth is connected to Hardware Serial Pins only. If you receive data on phone then you are good to receive as well If not then Try below points.
  3. Make sure your HC-05 Baudrate is correct. If you are not sure then try some others as well like 9600, 115200 etc.
  4. Make sure Rx and Tx pins are connect with correct pins of HC-05. If you know your Baudrate then try swapping Rx Tx and it should response to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.