Arduino UNO Programming question

Hi All,

I am very new to Arduino UNO board and its programming.
what i need to is :slight_smile:

  1. If one is received on serial port then make Pin13 high and then low.

Below is the code for the same:

void setup() {
  // put your setup code here, to run once:
    Serial.begin(19200);
    pinMode(LED_BUILTIN, OUTPUT);
    Serial.flush();
}

void loop() {
   /*  check if data has been sent from the computer: */
  if (Serial.available() > 0) {
    /* read the most recent byte */
    byte  byteRead [1] = Serial.read();
    /*Listen for a comma which equals byte code # 44 */
    switch (byteRead[0])
    {
     case 0x01:
     // Serial.println("Command 1 is received");
       digitalWrite(LED_BUILTIN, HIGH);
       delay(20);
       digitalWrite(LED_BUILTIN, LOW);
      break;
    }
  }
}

I need to connect digital pin 13 to the button pads of IR remote. When i power up the board it sends high signal to my IR remote button pads irrespective of the 0x01 received on the serial port.
Can you please help me to figure out what’s is wrong with this piece of code?

Also sometimes it misses to send the signal to IR remote even after receiving 0x01 on serial port.

Also on start up it shows extra 3 or 4 bytes with values 255.From were this data is coming to Rx buffer of board?

Thanks a lot in advance

Just to clarify, this is not an Arduino forum.
This is dedicated to Particle products that use a similar programming “language”, but it’s not Arduino.

But when you want to check for the digit 1 you’d check for 0x31 not 0x01.

BTW, what’s the point in using a one element array byteRead[1]?
You are not using the byte for anything but the switch(), so why not just go for

void loop() {
  switch(Serial.read())
  {
    case '1':
       digitalWrite(LED_BUILTIN, HIGH);
       delay(20);
       digitalWrite(LED_BUILTIN, LOW);
       break;
    default:
      break;
  }
}
1 Like