ElectroPeak
Published © GPL3+

Getting Started with HC-05 Bluetooth Module & Arduino

Learn how to communicate and send data over Bluetooth using an HC-05 module and an Arduino board.

BeginnerProtip1 hour48,818
Getting Started with HC-05 Bluetooth Module & Arduino

Things used in this project

Hardware components

ElectroPeak HC-05 Bluetooth Serial Wireless Module
×1
Arduino UNO R3
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

code 1

Arduino
/*   
HC05 - Bluetooth AT-Command mode  
modified on 10 Feb 2019 
by Saeed Hosseini 
https://electropeak.com/learn/ 
*/ 
#include <SoftwareSerial.h> 
SoftwareSerial MyBlue(2, 3); // RX | TX 
int flag = 0; 
int LED = 8; 
void setup() 
{   
  Serial.begin(9600); 
  MyBlue.begin(9600); 
  pinMode(LED, OUTPUT); 
  Serial.println("Ready to connect\nDefualt password is 1234 or 000"); 
} 
void loop() 
{ 
  if (MyBlue.available()) 
    flag = MyBlue.read(); 
  if (flag == 1) 
  { 
    digitalWrite(LED, HIGH); 
    Serial.println("LED On"); 
  } 
  else if (flag == 0) 
  { 
    digitalWrite(LED, HIGH); 
    Serial.println("LED Off"); 
  } 
} 

code 2

Arduino
void loop() 

{ 

  if (MyBlue.available()) 

    flag = MyBlue.read(); 

  if (flag == 1) 

  { 

    digitalWrite(LED, HIGH); 

    Serial.println("LED On"); 

  } 

  else if (flag == 0) 

  { 

    digitalWrite(LED, HIGH); 

    Serial.println("LED Off"); 

  } 

 

} 

code 3

Arduino
/* 
HC05 - Bluetooth AT-Command mode 
modified on 10 Feb 2019 
by Saeed Hosseini 
https://electropeak.com/learn/guides
*/ 
#include "SoftwareSerial.h"
SoftwareSerial MyBlue(2, 3); // RX | TX 
void setup() 
{ 
  Serial.begin(9600); 
  MyBlue.begin(38400);  //Baud Rate for AT-command Mode.  
  Serial.println("***AT commands mode***"); 
} 
void loop() 
{ 
  //from bluetooth to Terminal. 
  if (MyBlue.available()) 
    Serial.write(MyBlue.read()); 
  //from termial to bluetooth 
  if (Serial.available()) 
    MyBlue.write(Serial.read());
}

Credits

ElectroPeak

ElectroPeak

55 projects • 444 followers
At ElectroPeak we want to teach you to enjoy electronics more. We offer Top-notch guides and worry-free shopping experience.

Comments