Bluetooth 2 way

Hi I am new to arduino. I am using 2x Hc-05 as a master and a slave. I am using one computer and have two arduinos attached. I change the port before I code to them. I am able press a button on one arduino and light up the LED on the other and vice versa. However, I am unable to send int or anything besides Serial.write('1') or '0'. When I do I get a 0 or some crazy symbol.

Any tips would be appreciated. And also am I able to view both serial monitors on the same computer? if I change the port and reopen serial monitor? Or will this be problematic

-James

Code uploaded to slave and master.

#define ledPin 9
#define button 8
int state = 0;
int buttonState = 0;
void setup() {
  pinMode(button, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  Serial.begin(9600); // Default communication rate of the Bluetooth module
}
void loop() {
  if (Serial.available() > 0) { // Checks whether data is comming from the serial port
    state = Serial.read(); // Reads the data from the serial port
    Serial.println(state);
  }
  delay(10);
  // Controlling the LED
  if (state == '1') {
    digitalWrite(ledPin, HIGH); // LED ON
    state = 0;
  }
  else if (state == '0') {
    digitalWrite(ledPin, LOW); // LED ON
    state = 0;
  }
  // Reading the button
  buttonState = digitalRead(button);
  Serial.print(buttonState);
  if (buttonState == HIGH) {
    Serial.write('1'); // Sends '1' to the master to turn on LED
  }
  else {
    Serial.write('0');
  }
}

lightro:
Hi I am new to arduino. I am using 2x Hc-05 as a master and a slave. I am using one computer and have two arduinos attached. I change the port before I code to them. I am able press a button on one arduino and light up the LED on the other and vice versa. However, I am unable to send int or anything besides Serial.write('1') or '0'. When I do I get a 0 or some crazy symbol.

Can you post your code in tags?

lightro:
Any tips would be appreciated. And also am I able to view both serial monitors on the same computer? if I change the port and reopen serial monitor? Or will this be problematic

Yes, you can. I do it all the time. You just need to open two sketches that are connected to different COM ports. Then open the serial monitor for each sketch.

lightro:
I am able press a button on one arduino and light up the LED on the other and vice versa. However, I am unable to send int or anything besides Serial.write('1') or '0'. When I do I get a 0 or some crazy symbol.

You apparently have done the hard part, and it may be just serial procedure, and you are seeing ASCII. Try here

http://forum.arduino.cc/index.php?topic=396450.0

You might find Arduino to Arduino by Bluetooth helpful.

Power_Broker:
Can you post your code in tags?

Yes, you can. I do it all the time. You just need to open two sketches that are connected to different COM ports. Then open the serial monitor for each sketch.

Added code sorry!

Nick_Pyner:
You apparently have done the hard part, and it may be just serial procedure, and you are seeing ASCII. Try here

Serial Input Basics - updated - Introductory Tutorials - Arduino Forum

Thanks, reading.

MartynC:
You might find Arduino to Arduino by Bluetooth helpful.

Thanks checking out.

I'm confused as to the physical setup of the project. You said that there are two Arduinos connected via Bluetooth and a computer. How is the computer connected and to what (is it usb to one or both of the Arduinos?)?

Shot in the dark: I think you are trying to use one serial port for both interfacing with the computer and the Bluetooth module (BIG NO NO - doesn't work that way). Look into using softserial.h. Many UNO users tying to use XBees have to use softserial.h.

Also, your code doesn't support any serial inputs other than '1' or '0'.

Power_Broker:
I'm confused as to the physical setup of the project. You said that there are two Arduinos connected via Bluetooth and a computer. How is the computer connected and to what (is it usb to one or both of the Arduinos?)?

Shot in the dark: I think you are trying to use one serial port for both interfacing with the computer and the Bluetooth module (BIG NO NO - doesn't work that way). Look into using softserial.h. Many UNO users tying to use XBees have to use softserial.h.

Also, your code doesn't support any serial inputs other than '1' or '0'.

I am using one computer with a usb cable from each arduino to one computer. All it can do now is light the others LED. I changed the image so that it has a button input and led on each arduino circuit. I cant send anything but a '1' or '0'. I changed the serial.write to Serial.write(value); //value = 5

Then I attempted to view it in the monitor on the other arduino but get 0 or crazy symbols.

Do I need two serial monitors for 2 way? What if I just want to collect data from one arduino send to the other and view it there?

Thanks!

  1. DON'T USE PINS D1 and D2!! They get hijacked by the usb port. As I mentioned in my earlier post, you can't use the same serial port for both interfacing via USB AND sensors. Use Serial2 for the Bluetooth modules and Serial for USB comms.

  2. Try using the print method instead of the write method. (more on this later)

  3. You have a lot of other sensors/actuators in your picture that aren't supported in you original code posting. Post the complete code for BOTH Arduinos. We might be able to offer more help with the final version of both codes.

I think he really means don't use D0, D1. They are Serial0 (just plain Serial) hardware. Not a problem, there are three more hardware serial ports available on a Mega and clearly marked on pins 14>19. You just change the

Serial.print.......; to Serial1.print.......; etc.

And stay away from SoftwareSerial.

Do I need two serial monitors for 2 way?

I'm sure that's possible. I believe there is recent thread to that effect. I imagine it is just a matter of ensuring the Arduinos use different COM ports, which is the usual scene anyway.

What if I just want to collect data from one arduino send to the other and view it there?

That makes a lot more sense - even more so when you actually do something with the received data.

Nick_Pyner:
I think he really means don't use D0, D1.

Oops, my mistake. Yes, I meant D0, and D1.

Nick_Pyner:
I believe there is recent thread to that effect. I imagine it is just a matter of ensuring the Arduinos use different COM ports, which is the usual scene anyway.That makes a lot more sense - even more so when you actually do something with the received data.

As I mentioned in an earlier post on this thread that it is possible (I've done it myself quite a bit).