user15851: Here is my circuit:

and here is my code:
int LED = 13;
int BTN = 7;

void setup() {
pinMode(LED,OUTPUT);
pinMode(BTN,INPUT);
}
void loop() {
if(digitalRead(BTN) == HIGH) {
digitalWrite(LED,LOW);
}
else{
digitalWrite(LED,HIGH);
}
}

When I press the button, the LED is supposed to go low, but it doesn't. What is wrong with this circuit/code?

user4143: Paul is correct. Your button is wired wrong. The GPIO pin should be connected to the same side as the resistor. Also the button needs rotating through 90 degrees.
Also check how your LED is wired up. At the moment it looks like it's set up so that the GPIO sinks the current (LOW turns the LED on) yet the LED looks like it's connected the wrong way around for that.
In fact, I can't actually find anything right about that circuit...

user29796: Your code and schematic both seem to be wrong.
Try out this schematic:

And then code:
const int kPinLed = 6; // LED - Pin 6
const int kPinBtn = 7; // Push Button - Pin 7

void setup()
{
  pinMode(kPinLed, OUTPUT);       // LED as OUTPUT
  pinMode(kPinBtn, INPUT_PULLUP); // Push Button as INPUT wiith pullup
}

void loop()
{
  if(digitalRead(kPinBtn) == LOW)  // When Push Button is pressed
  {
    digitalWrite(kPinLed, HIGH);   // LED ON
  }
  else digitalWrite(kPinLed, LOW); // LED OFF
}


15851: <p>Here is my circuit:
<a href="https://i.stack.imgur.com/kMqM1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kMqM1.png" alt="enter image description here"></a></p>

<p>and here is my code:</p>

<pre><code>int LED = 13;
int BTN = 7;

void setup() {
pinMode(LED,OUTPUT);
pinMode(BTN,INPUT);
}
void loop() {
if(digitalRead(BTN) == HIGH) {
digitalWrite(LED,LOW);
}
else{
digitalWrite(LED,HIGH);
}
}
</code></pre>

<p>When I press the button, the LED is supposed to go low, but it doesn't. What is wrong with this circuit/code?</p>
 4143: <p>Paul is correct. Your button is wired wrong. The GPIO pin should be connected to the same side as the resistor. Also the button needs rotating through 90 degrees.</p>

<p>Also check how your LED is wired up. At the moment it looks like it's set up so that the GPIO sinks the current (LOW turns the LED on) yet the LED looks like it's connected the wrong way around for that.</p>

<p>In fact, I can't actually find anything <em>right</em> about that circuit...</p>
 29796: <p>Your code and schematic both seem to be wrong.</p>

<p>Try out this schematic:</p>

<p><a href="https://i.stack.imgur.com/XiEvq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XiEvq.png" alt="schematic"></a></p>

<p>And then code:</p>

<pre><code>const int kPinLed = 6; // LED - Pin 6
const int kPinBtn = 7; // Push Button - Pin 7

void setup()
{
  pinMode(kPinLed, OUTPUT);       // LED as OUTPUT
  pinMode(kPinBtn, INPUT_PULLUP); // Push Button as INPUT wiith pullup
}

void loop()
{
  if(digitalRead(kPinBtn) == LOW)  // When Push Button is pressed
  {
    digitalWrite(kPinLed, HIGH);   // LED ON
  }
  else digitalWrite(kPinLed, LOW); // LED OFF
}
</code></pre>
