Hackster is hosting Hackster Holidays, Ep. 3: Livestream & Giveaway Drawing. Start streaming on Monday!Stream Hackster Holidays, Ep. 3 on Monday!
Bharath Rao M
Published

Bluetooth Chat

Enable a chatting interface between two serial monitors.

IntermediateFull instructions provided5 hours9,210
Bluetooth Chat

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
Bluetooth module HC-0
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

HC-05 connections

HC05

HC-06 connections

HC06

Code

HC-05 Arduino code

Arduino
#include <SoftwareSerial.h>
SoftwareSerial BTserial(4,2); // RX, TX
 
char c=' ';
 
void setup() 
{
    // start the serial communication with the computer
    Serial.begin(9600);
    Serial.println("Arduino with HC-05 is ready");
 
    // start communication with the HC-05 using 9600
    BTserial.begin(9600);  
    Serial.println("Bluetooth serial started at 9600");
}
 
void loop()
{
 
     // Read from HC-05 and send to Arduino Serial Monitor
    if (BTserial.available())
    {  
        c = BTserial.read();
        Serial.write(c);
    }
 
    // Read from Arduino Serial Monitor and send to HC-05
    if (Serial.available())
    {
        c =  Serial.read();
        BTserial.write(c);  
    }
 
}

HC-06 Arduino Code

Arduino
#include <SoftwareSerial.h>
SoftwareSerial BTserial(4,2); // RX , TX

char m=' ';
 
void setup() 
{
    Serial.begin(9600);
    Serial.println("Arduino with HC-06 is ready");
 
    // HC-06 default baud rate is 9600
    BTserial.begin(9600);  
    Serial.println("Bluetooth Serial started at 9600");
}
 
void loop()
{
 
  // Read from HC-06 and send to Arduino Serial Monitor
  if (BTserial.available())
  {
    m = BTserial.read();
    Serial.write(m);
  }
 
  // Read from Arduino Serial Monitor and send to HC-06
  if (Serial.available())
  {
    m=Serial.read();
    BTserial.write(m);
  }
  
}

Credits

Bharath Rao M

Bharath Rao M

3 projects • 24 followers
An electronics hobbyist.

Comments