I followed this tutorial: Remote Controlled LED using HC-05

I've assembled everything, uploaded the code and connected it with my phone. The code:

Arduino Turn LED On/Off using Serial Commands
Created April 22, 2015
Hammad Tariq, Incubator (Pakistan)

It's a simple sketch which waits for a character on serial
and in case of a desirable character, it turns an LED on/off.

Possible string values:
a (to turn the LED on)
b (tor turn the LED off)

char junk;
String inputString="";

void setup()                    // run once, when the sketch starts
 Serial.begin(9600);            // set the baud rate to 9600, same should be of your Serial Monitor
 pinMode(13, OUTPUT);

void loop()
      char inChar = (char)Serial.read(); //read the input
      inputString += inChar;        //make a string of the characters coming on serial
    while (Serial.available() > 0)  
    { junk = Serial.read() ; }      // clear the serial buffer
    if(inputString == "a"){         //in case of 'a' turn the LED on
      digitalWrite(13, HIGH);  
    }else if(inputString == "b"){   //incase of 'b' turn the LED off
      digitalWrite(13, LOW);
    inputString = "";

I connected it with my android phone and downloaded the suggested app: Bluetooth Terminal, however when I type "a" or "b" I get weird characters that change every time:

Weird Symbols

When the weird symbols just happen to contain a, the LED does turn on and when the symbols contain b, the LED does turn off so it works in that sense but it's just very unreliable. Please help me if anyone knows.

The setup: Circuit diagram

  • 1
    You set the baud rate to 9600 in your sketch. As far as I know HC05 uses a default baud rate of 38400. – Peter Paul Kiefer Oct 18 '19 at 16:34

Your Answer

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

Browse other questions tagged or ask your own question.