user21318: Sorry if my code isn't well written or anything because I'm new to Arduino and coding in C, but what is wrong with my code?
int sidepin = 2;
int LED = 5;
int val;
void setup() {
  pinMode(sidepin, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  val = digitalRead(sidepin);
  if(val = 0)
  {
    pinMode(LED, HIGH);
  }
  else(val > 0) 
  {
    pinMode(LED, LOW);
  }
}


user16417: Your IF statement, you're using: (val = 0), and I believe you meant (val == 0).
Also, you're using else(val > 0) and else doesn't need any argument. So the fixed code should look like:
int sidepin = 2;
int LED = 5;
int val;
void setup() {
  pinMode(sidepin, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  val = digitalRead(sidepin);
  if(val == LOW)
  {
    pinMode(LED, HIGH);
  }
  else
  {
    pinMode(LED, LOW);
  }
}


21318: <p>Sorry if my code isn't well written or anything because I'm new to Arduino and coding in C, but what is wrong with my code?</p>

<pre><code>int sidepin = 2;
int LED = 5;
int val;
void setup() {
  pinMode(sidepin, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  val = digitalRead(sidepin);
  if(val = 0)
  {
    pinMode(LED, HIGH);
  }
  else(val &gt; 0) 
  {
    pinMode(LED, LOW);
  }
}
</code></pre>
 16417: <p>Your IF statement, you're using: <code>(val = 0)</code>, and I believe you meant <code>(val == 0)</code>.</p>

<p>Also, you're using <code>else(val &gt; 0)</code> and <code>else</code> doesn't need any argument. So the fixed code should look like:</p>

<pre><code>int sidepin = 2;
int LED = 5;
int val;
void setup() {
  pinMode(sidepin, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  val = digitalRead(sidepin);
  if(val == LOW)
  {
    pinMode(LED, HIGH);
  }
  else
  {
    pinMode(LED, LOW);
  }
}
</code></pre>
