Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample code for Bluetooth communication. #4

Closed
Ido-Sobol opened this issue Dec 26, 2021 · 0 comments
Closed

Sample code for Bluetooth communication. #4

Ido-Sobol opened this issue Dec 26, 2021 · 0 comments

Comments

@Ido-Sobol
Copy link
Owner

Ido-Sobol commented Dec 26, 2021

HC05 Configuration:

 

#include <SoftwareSerial.h>

#define tx 2

#define rx 3

SoftwareSerial configBt(rx, tx); // RX, TX

void setup() 

{

  Serial.begin(38400);

  configBt.begin(38400);

  pinMode(tx, OUTPUT);

  pinMode(rx, INPUT);

}

void loop() 

{

  if(configBt.available()) //if the bluetooth module is sending something...

  {

    Serial.print(configBt.readString()); //print whatever the bluetooth module is sending 

  }

   

  if(Serial.available()) //if we have typed anything into the serial monitor input text box...

  {

    configBt.write(Serial.read()); //write whatever we typed into the serial monitor input text box to the bluetooth module

  }

}

 

 

Receiver:

 

#include <SoftwareSerial.h>

#define tx 2

#define rx 3

SoftwareSerial bt(rx, tx); //RX, TX

void setup()

{

  Serial.begin(9600);

  bt.begin(9600);

  pinMode(tx, OUTPUT);

  pinMode(rx, INPUT);

}

void loop()

{

  if(bt.available()>0)

  {

    Serial.println(bt.read());

  }

}

 

 

Sender:

 

#include <SoftwareSerial.h>

#define tx 2

#define rx 3

SoftwareSerial bt(rx,tx); //RX, TX

void setup() 

{

  Serial.begin(9600);

  bt.begin(9600);

  pinMode(tx, OUTPUT);

  pinMode(rx, INPUT);

}

void loop() 

{

  bt.write(123);


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant