very simple code won't run on arduino uno

First of all, I'm terribly sorry for being a total noob and giving up on troubleshooting this issue so quick.

So I bought a new arduino uno (not genuine) and wanted to test it, so
I wrote a very simple code that would enable me to make the onboard LED light up,
whenever I push a button on pin 8 (no real reason for choosing pin8).
I've chosen the internal pullup function, since I need it for my actual project.

My simple testcode doesn't seem to work. What am I doing wrong?
(Let's assume the led aswell as the button itself work fine)

Here's the code:

int buttonstate = 0;

void setup()
{
  pinMode(8, INPUT_PULLUP);
  pinMode(13, OUTPUT);
}

void loop()
{
  buttonstate = digitalRead(8);
  if (buttonstate == LOW) {
    digitalWrite(13, HIGH);
  } else {
    digitalWrite(13, LOW);
  }
  
}

(Sorry for any grammar mistakes you might find, I'm from the land of the Lederhosen and Bratwürste)

Your code said pin 2 for input :wink:

Yup, you're right lol. I'm sorry.
That was a copy paste mistake.

It should've said pin8.
I tried both though. Didn't make a difference.
Other than that: Did you see any other mistakes?

Which way are you wired? S1 S2 or S3

.

should be s3.

pin8 (or pin2, copy paste mistake) is connected to the bottom right pin of the button.
The bottom left pin of the button is directly connected to Ground so whenever I push it,
it should go LOW and if I don't push it, it should stay HIGH.

the onboard LED is pin13 and is not connected otherwise.

Thanks for your quick replies btw, didn't expect to be noticed this fast.

If the switch is one of those 6mm tactile switches with 4 pins, the pins on each end are shorted internally. If you connect diagonal pins you can avoid the short.

@groundFungus
Thanks, I tried it diagonally as you said, but sadly that didn't solve the issue.

In fact, I also tried connecting pin8 directly to ground (temporarily, as if it was a switch being pressed)
but nothing happened.

And you changed the code to read pin 8?

Whenever you make any changes to your posted code, please post the new version so that we can keep up.

How about a photo of your setup? Often we can see something that you may have missed.

You're right. Thanks for the headsup. Updated the code.

I attached a pic of the setup.
Please ignore the big black block in the picture. That's part of the actual project. Just a bunch of leds with resistors, not connected to anything at the moment.

(Upload failed multiple times, I'll supply a pic tomorrow. I'm very sorry.)

(another upload attempt)

Comment on pointless image...
Are you sure the vcc and gnd busses are carried across the long sides of the breadboard?

Add jumpers across the power rails.

That is exactly why I asked for a photo. Those split power rails have been the bane of many new users.

Please do not edit your original post with new code. Put the new version in a new post. That will maintain continuity of the thread.

Let’s see what the annoying_orange has to say...!
We could all be wrong (!)

annoying_orange

So lucky to have him interested in Arduino.

I didn’t see ‘that’ coming :slight_smile:

@larryd ayee lol

Yyyyyyup you were right. Wow man, guess I can join the common-noob-problem-22 group now. :confused:

Really makes me wonder how I didn't think of this. I thought I checked for this. :o Operational Blindness I guess.

by the way sorry for the late reply. Different Timezone.

Thank you very much.