bakhshiyev
bakhshiyev

Reputation: 11

How to send data from Arduino via HC-05?

I need to send 1 if a button is pressed or 0 if not. So I used this Arduino (Nano) code. When i use it with Serial.println and cheking it on COM port it works:

#include <SoftwareSerial.h>
int txPin = 1;
int rxPin =0;
bool y = 1;
bool n = 0;
SoftwareSerial bt(txPin, rxPin);
int btnpin=13;

void setup() {
  pinMode(13, INPUT);
  bt.begin(9600);
  Serial.begin(9600);
}

void loop() {
  if(bt.available()) {
    if(digitalRead(btnpin) == HIGH)
      bt.write(y);
    else bt.write(n);
  }
  delay(100);
}

I'm trying to check it with Bluetooth Terminal. However I always see this

enter image description here

enter image description here

Upvotes: 0

Views: 4442

Answers (2)

bakhshiyev
bakhshiyev

Reputation: 11

Actually, with delay(100); mobile's bluetooth buffer was overfilled, u need to increase delay value to approximately 2000.

Upvotes: 1

jikuja
jikuja

Reputation: 463

Try other baudrates. Some modules have baudrate 38400 as default but some other 9600. Also consider using Serial instead of SoftwareSerial if you have extra UART available.

Upvotes: 2

Related Questions