Hc05 Bluetooth communication got 2 second delay

Hi All

I havent touch arduino for ages but im back at it again, giving me problems :rofl:, i got two arduinos, got 64 inputs on one arduino so my data to send will be from 1 to 64 bytes?, and then 64 outputs on the other arduino, anyway im just on breadboard now testing the hc 05 module when i serial write a 1 the other arduino takes about 2 seconds to respond, ive never really work with serial or bluetooth so not sure what the right way is to code it?

Please any help?

Thanks

int state = 0;
const int ledPin = 6;
const int buttonPin = 13;
int buttonState = 1;

void setup() 
{
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH);
}

void loop()
{

 buttonState = digitalRead(buttonPin);
 
 if (buttonState == LOW)
 {
  Serial.write('1');
  digitalWrite(ledPin, HIGH);
 }
 else
 {
  Serial.write('0');
  digitalWrite(ledPin, LOW);
 }
delay(10); 
}
``


int incomingByte = 0; // for incoming serial data
const int led = 4;

void setup() {
Serial.begin(115200); // opens serial port, sets data rate to 9600 bps
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
}

void loop() {
// reply only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
}
//Serial.print(incomingByte);
if (incomingByte == '1')
{
digitalWrite(led, HIGH); // LED ON
}
else if (incomingByte == '0')
{
digitalWrite(led, LOW); // LED ON
}
delay(10);
}

You're sending furiously.
(And you should use Software Serial.)

Compose your loop() to send a '1', delay(1000), send a '0', delay(1000)
or delay(500),
See how that goes (no pushbutton stuff for now).

Try INPUT_PULLUP instead and wire the button between buttonPin and GND. A pressed button give a low in reading it.

Hey, how about reading the instructions then? :thinking:

No, 64 bits or 8 bytes.

Bluetooth has some latency (delay) in transmission. You just have to live with it.

Clearly not true.
Have you actually configured Bluetooth to operate at 115200?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.