Arduino Uno - 2 way bluetooth communication guidance.

Arduino Uno - 2 way bluetooth communication

We successfully got two Arduino Uno’s to communicate with eachother using the RX/TX pins and wires.
We used the serial monitor to trace two way communication using this code:

int incomingByte = 0;   // for incoming serial data
int i = 0;

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
        // Try to change this for quicker speed.
}

void loop() {
       

        Serial.print(i);
       Serial.println(" * ");
        i++;
        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
}

Now we would like to use the HC-05 Bluetooth modules (6 pin) to have two communication.
We have searched for a good guild and have found bits a pieces here and there to help with this project.

Could someone please throw me a bone on a good guide to achieve this objective.

This is the code we are using to test two way. We are not able to trace two way communication.

#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>
SoftwareSerial mySerial(8, 9); //RX,TX

const int ledPin = 13; // the pin that the LED is attached to

byte iB;      // a variable to read incoming serial data into
int count = 0;

void setup() 
{
  // initialize serial communication:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  mySerial.begin(9600);

  Serial.print("set up complete...");
  // make sure that the default chip select pin is set to
  }

void loop() 
{
  count++;
  
  mySerial.listen();
 mySerial.println(" * * * ");
 Serial.print(" * * * ");
    if (mySerial.available() > 0) {
    // read the oldest byte in the serial buffer:
    iB = mySerial.read();
    Serial.println(iB);
    Serial.print("+");
    if (count % 16)Serial.println();
    analogWrite(ledPin, iB);
    delay (100);
    }
}

Start with your first program and modify it a little so it uses SoftwareSerial to communicate between the two Arduinos using wired connections.

When that works replace the wired connections with the Bluetooth devices.

Don't bring in other complications such as SPI and an SD card until you have the Bluetooth working.

...R

I have not yet used it myself, but here is the best explanation I know of

http://phillipecantin.blogspot.ca/2014/01/hc-05-bluetooth-link-of-2-arduino.html

If you have no experience with bluetooth, you might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

We got things working.

Started with a Serial.* code then configured the Bluetooth HC-05's Master and Slave. Plugged HC-05 rx to Arduino tx and tx to Arduino rx We found out our dedug Serial.print(" text"); was echoing back to the second Arduino.

This is how we set the HC-05 https://sites.google.com/site/craigwcoleman/arduino-bt from http://phillipecantin.blogspot.ca/

I need to document the AT command a bit more.

Thanks for the posts.

Molto Epico Arduino!

Nick_Pyner: I have not yet used it myself, but here is the best explanation I know of

http://phillipecantin.blogspot.ca/2014/01/hc-05-bluetooth-link-of-2-arduino.html

If you have no experience with bluetooth, you might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

grazie!

Robin2: Start with your first program and modify it a little so it uses SoftwareSerial to communicate between the two Arduinos using wired connections.

When that works replace the wired connections with the Bluetooth devices.

Don't bring in other complications such as SPI and an SD card until you have the Bluetooth working.

...R

grazie!

I’m trying to work on communicating two bluetooth modules using two arduino uno but it is not working. Please help me to find the mistakes with the codes of master and slave. My project includes transferring data of received sensors reading connected to master to the slave.

master_1.ino (2.86 KB)

slave_1.ino (349 Bytes)

gandhipalak: I'm trying to work on communicating two bluetooth modules using two arduino uno but it is not working. Please help me to find the mistakes with the codes of master and slave. My project includes transferring data of received sensors reading connected to master to the slave.

You have resurrected a 2-years-dead Thread,

Have you read the advice in it? Have you tried the advice in it - specifically to try a wired connection first?

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

...R

It would be helpful if you posted your code in the proper manner, using the </> tags, also details of the wiring.