# Xbee Delay

**URL:** <https://forum.arduino.cc/t/xbee-delay/219108>\
**Category:** Networking, Protocols, and Devices\
**Created:** [March 12, 2014, 6:43am UTC](https://forum.arduino.cc/t/xbee-delay/219108 "2014-03-12T06:43:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 12, 2014, 6:43am UTC](https://forum.arduino.cc/t/xbee-delay/219108/1 "2014-03-12T06:43:56Z")

</div>

Hello, I am trying to send a variable resistor's input from one Arduino to another (wirelessly using Xbee modules). The second Arduino will vary the brightness of an LED depending on the value of the variable resistor.

Everything is working but there is about a 1 second delay before the LED responds to the change of the variable resistor.  
Here is my code:

Sender:

```cpp
// SENDER

int analogValue5, val5;

void setup()
{Serial.begin(9600);}

void loop()
{
analogValue5 = analogRead(5);
val5 = map(analogValue5, 0, 1023, 255, 0);

Serial.write(val5);

delay(300);
}

```

Receiver:

```cpp
// RECIEVER

int incomingByte;

void setup() {

Serial.begin(9600);

pinMode (11, OUTPUT);

}

void loop() {
if (Serial.available()) {   

 incomingByte = Serial.read();
 delay(300);

}
analogWrite (11, incomingByte);
delay(10);

}

```

Anyone knows how I can reduce or eliminate this delay?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 12, 2014, 10:22am UTC](https://forum.arduino.cc/t/xbee-delay/219108/2 "2014-03-12T10:22:07Z")

</div>

> Anyone knows how I can reduce or eliminate this delay?

I think you mean delay(), not delay. It really should be obvious how to reduce the delay().

---

<div class="post-metadata">

**Author:** ![waski](https://avatars.discourse-cdn.com/v4/letter/w/c4cdca/32.png) [@waski](https://forum.arduino.cc/u/waski)\
**Post date:** [March 12, 2014, 10:36am UTC](https://forum.arduino.cc/t/xbee-delay/219108/3 "2014-03-12T10:36:03Z")

</div>

Remove all delay() functions from your code. If you need something to happen after some pause, look at Blink without delay example in arduino IDE.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 12, 2014, 10:59am UTC](https://forum.arduino.cc/t/xbee-delay/219108/4 "2014-03-12T10:59:26Z")

</div>

Thanks, I thought you need to have some delay() for the Xbees to communicate.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 12, 2014, 11:08am UTC](https://forum.arduino.cc/t/xbee-delay/219108/5 "2014-03-12T11:08:51Z")

</div>

Mate, could you put here such a stupid question? Uff

If you need fastest communication, set baud rate to 115200 and set RO register to 0 (packetization timeout).

Put analogWrite (11, incomingByte); into if.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 10:47am UTC](https://forum.arduino.cc/t/xbee-delay/219108/6 "2021-05-06T10:47:26Z")

</div>


