Serial_byte help

I need help with this code.
I need to find out if the serial_byte at position 1 is returning false or true.

I tried to see it on the console but as I am using the port to communicate I cannot monitor it.
or else how to read the door even with it in use?

Can someone help me?

type or paste code here
  // Enabled flags
  serial_byte =;

  if ((serial_byte,1) == true)
    digitalWrite(LuzTeste, 1);

Sorry, your question and code make no sense at all. You test for serial byte(1), which is the second byte in the buffer, before you even know if you have read TWO bytes.
Also, "false" means the numeric value is ZERO, all other values will return TRUE!
What are you REALLY trying to do?

Snippets of code often leave out important information. That is why we request that you post the whole code. That if statement will not compile. See the if structure reference for the syntax.

So you have an external device that is sending serial data to the mystery Arduino? What is the device? What is it sending (ASCII, binary)? Provide a sample of the serial data.

I need to collect the information that is in position 1 of serial_byte and then perform an if.
how do I collect information from just that position?

The code is not all here or you can put it. It was only this excerpt to try to understand

What do you mean by "position 1 of serial_byte"? Do you mean the first bit of that byte? Or do you mean bit number 1, which is the second bit because bits are numbered from 0. Or do you mean something else?

Yes, this.
the value of the bit in position 1 (the second bit).

I need to make a comparison using that bit.
if this bit is true (> 0) it does one thing. if it is false (<0) make another one.
Everyone else doesn't care.

The bitRead() function can be used to read the state of a bit.

False is 0. Any other value (positive or negative) is true.


I am new to this world so I apologize for these issues.
this function has 2 inputs. (x, n)
to read bit 1 as I put it?

An example:

byte ourByte = 0b00000010;

void setup()
   // read the second from the right bit (bit 1) of the byte ourByte   
   Serial.print("bit 1 of ourByte = ");
   Serial.println(bitRead(ourByte, 1)); 

void loop()


bit 1 of ourByte = 1

1 Like

thanks problem solved :slight_smile:

You can turn the board Led on/off to indicate what is happening.

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