Problem with if statmenet

Hey, I am totally new to this thing and I am trying to make my first steps into both coding and arduino.
I am trying to create simple code that prints text if led is active and can not understand why it does not work.

void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(13, HIGH);
if (13 == HIGH) {
Serial.print("Hello);
}
}

In your if statement, you compare 13 which is a number to HIGH which is a boolean value. But what you want to compare is not 13 but the digital value of the pin 13.

Try to find an instruction which provides this value.

Welcome to the forum! Please read the sticky posts at the beginning to help make better posts. Specifically, use code tags for your code.

The problem is that the constant HIGH is the value 1 and you are comparing it to the value 13. I'm pretty sure 1 is not equal to 13 so your if() statement is false.

I'm guessing you want to do a digitalRead() of pin 13 which returns the value LOW (0) or HIGH (1) and compare that to HIGH...

void setup()
{
  pinMode(13, OUTPUT);
  Serial.begin(9600); 
}
void loop()
{    
  digitalWrite(13, HIGH);
   if (digitalRead(13) == HIGH) {
   Serial.print("Hello);
 }
}

Here's the definition of HIGH:

#define HIGH 0x1

So your code:

  if (13 == HIGH) {

is equivalent to:

  if (13 == 1) {

Now do you see why it never prints "Hello"?

You could set a variable with the pin state:

byte LEDstate = HIGH;

and then use that variable to set the pin via pinMode() and also use that variable in your if statement.

blh64:
I'm guessing you want to do a digitalRead() of pin 13 which returns the value LOW (0) or HIGH (1) and compare that to HIGH...

Doing digitalRead() on an output pin will probably work, but it's not guaranteed to work on every architecture. It's also not very efficient.

Thank you guys, fixed! This was very helpful!