I was trying to communicate with my arduino uno over the serial connection from the USB. Connecting to it is usually not a problem, but what buggs me is the first transaction of the data... No matter with what I do it, java code or the serial monitor which comes with the IDE, I always have the problem that usually only one Byte is being transfered or received from the Arduino. What could be the problem? Is it just a bug and I have to live with it or can this somehow be fixed?

My Arduino Code:

#include "RGBdriver.h"
#define CLK 10
#define DIN 11

RGBdriver driver(CLK, DIN);
byte red = 0;
byte green = 0;
byte blue = 0;

byte newRed = 0;
byte newGreen = 0;
byte newBlue = 255;

void setup() {

void loop() {
  if (Serial.available() >= 3) {
    newRed = Serial.read();
    newGreen = Serial.read();
    newBlue = Serial.read();

  if ((red != newRed) || (green != newGreen) || (blue != newBlue)) {
    red = newRed;
    green = newGreen;
    blue = newBlue;

    driver.SetColor(red, green, blue);
  • Are you waiting for the Arduino to finish the bootloader timeout after opening the serial port from the PC?
    – Majenko
    Jan 30, 2017 at 21:24
  • Yes, I do! The Arduino is being used for controlling the lights on my LED strip. I know it booted because they turn on and after 10-15 sec, just to be safe, I try to send the data and on the first try it turns off and on in a short time and on the second try it really changes the color.
    – CryoDrakon
    Jan 30, 2017 at 21:35
  • 1
    Now I have actually looked at your code your problem is immediately obvious to me. I cover it in detail here: hackingmajenkoblog.wordpress.com/2016/02/01/…
    – Majenko
    Jan 30, 2017 at 21:37
  • Ok what I could have changed in my code is putting Seria.available() >=3, bcs I need 3 Bytes of data for updating. But it still doesnt update the color on the first try. This also happens in the serial monitor...
    – CryoDrakon
    Jan 30, 2017 at 21:57
  • I updated my code. Now it works with the serial monitor, but my java program is still not working, meaning the first attempt of sending the data doesnt work... Only after trying the data one time it will work from there on.
    – CryoDrakon
    Jan 30, 2017 at 22:05

1 Answer 1


Consider giving sufficient delay to initiate the time to receive the data. The loop would otherwise terminate since the data received is less than 3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.