Arduino -Remote Controlled LED using HC-05 Bluetooth

Components required:

  • Arduino Uno
  • RED LED
  • Jumper wires
  • HC-05 Bluetooth

CAUTION:

  1. Connect VCC with 3.3V of Arduino, please do not connect it with 5V as that can cook the module
  2. Connect GND with any GND of Arduino
  3. Connect Rx pin with Tx of Arduino
  4. Connect Tx pin with Rx of Arduino

Caution: Disconnect the HC-05 bluetooth module Rx and Tx pins from Arduino Uno as this particular board has only one hardware serial and connecting something to it while uploading a sketch will create conflict or your can using Arduino SoftwareSerial to avoid conflicts.

Code source:

/*
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()
{
if(Serial.available()){
while(Serial.available())
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
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 = „”;
}
}

 

Important: There is no extra step or coding required for HC-05 to work, it’s a simple serial port module, which means if you pair it and then connect to it using any serial port terminal, it will work just like Arduino Serial Monitor.

Follow these mini-steps:

  1. Connect the Rx and Tx pins of HC-05 back to Arduino (if you haven’t did this already).
  2. Pair the device with your mobile phone (in my case I am using Android OS and my phone is Samsung SII).
  3. Download „Bluetooth Terminal” app from Google Play Store.
  4. Open Bluetooth Terminal app.
  5. From the menu, tap on „Connect a device – Insecure”.
  6. You will see a pop-up of „Paired Devices”, tap on „HC-05”, after a second you will get a toast notifying „Connected to HC-05”.
  7. Now type „a” and send, the LED will turn on, similarly, send „b” to turn the LED off.

Bibliography:

https://www.instructables.com/id/Remotely-Control-LED-using-HC-05-Bluetooth-Arduino